intermediate cjeckin - nfs woes!
[vamsas.git] / src / org / vamsas / objects / utils / AppDataReference.java
index 29c044b..50dc96b 100644 (file)
@@ -6,6 +6,8 @@ import java.util.Vector;
 
 import org.vamsas.client.ClientHandle;
 import org.vamsas.client.UserHandle;
+import org.vamsas.client.simpleclient.VamsasArchive;
+import org.vamsas.client.simpleclient.VamsasArchiveReader;
 import org.vamsas.objects.core.*;
 /**
  * Form, accessors and validation for ApplicationData references in
@@ -137,4 +139,21 @@ public class AppDataReference {
     
     return searchAppDatas(doc, match, true); // only return AppDatas belonging to appdata app.
   }
+  /**
+   * safely creates a new appData reference
+   * @param dest destination document Vobject
+   * @param entry base application reference to make unique 
+   */
+  public static String uniqueAppDataReference(VamsasDocument dest,String base) {
+    String urn = new String(base);    
+    for (int i=0, j=dest.getApplicationDataCount(); i<j; i++) {
+      ApplicationData o = dest.getApplicationData()[i];
+      // ensure new urn is really unique
+      int v = 1;
+      while (o.getUrn().equals(urn)) {
+        urn = base+"/"+v++;      
+      } 
+    }
+    return urn;
+  }
 }