added and tested simple document handling and update with test.ArchiveWriter.
[vamsas.git] / src / org / vamsas / objects / utils / AppDataReference.java
index 2f1bc78..ecf9a43 100644 (file)
@@ -2,12 +2,36 @@
  * 
  */
 package org.vamsas.objects.utils;
+import java.util.Vector;
 
+import org.vamsas.objects.core.*;
 /**
- * Form and validation for ApplicationData references in
+ * Form, accessors and validation for ApplicationData references in
  * vamsas document.
- * TODO: extend XML Schema to properly validate against the same forms required by this class
+ * TODO: LATER:extend XML Schema to properly validate against the same forms required by this class
+ * TODO: implement methods for searching appData structure for particular combinations of client and user data
+ * TODO: VAMSAS: URNS for appDatas are supposed to be unique, aren't they ?
  */
 public class AppDataReference {
-
+  static public Vector getAppDataReferences(VamsasDocument doc) {
+    if ((doc!=null) && (doc.getApplicationDataCount()>0)) {
+      Vector apdrefs = new Vector();
+      ApplicationData[] appdatas = doc.getApplicationData();
+      for (int q=0; q<appdatas.length; q++) {
+        String refstring=appdatas[q].getDataReference();
+        if (refstring!=null) 
+          apdrefs.add(refstring);
+        User users[] = appdatas[q].getUser();
+        
+        if (users!=null)
+          for (int u=0; u<users.length; u++)
+            refstring=users[u].getDataReference();
+            if (refstring!=null)
+              apdrefs.add(new String(refstring)); // avoid referencing.
+      }
+      if (apdrefs.size()>0)
+        return apdrefs;
+    }
+    return null;
+  }
 }