4 package org.vamsas.objects.utils;
5 import java.util.Vector;
7 import org.vamsas.client.ClientHandle;
8 import org.vamsas.client.UserHandle;
9 import org.vamsas.objects.core.*;
11 * Form, accessors and validation for ApplicationData references in
13 * TODO: LATER:extend XML Schema to properly validate against the same forms required by this class
14 * TODO: VAMSAS: URNS for appDatas are supposed to be unique, aren't they ?
16 public class AppDataReference {
18 * search interface for collecting particular types of AppDatas in a vamsas document
22 interface IAppDSearch {
24 * process the appData object d
26 * @return true if appData should be collected
28 public boolean process(AppData d);
31 * collect all appData reference strings in a vamsas document
33 * @return vector of String objects
35 static public Vector getAppDataReferences(VamsasDocument doc) {
36 if ((doc!=null) && (doc.getApplicationDataCount()>0)) {
37 Vector apdrefs = new Vector();
38 ApplicationData[] appdatas = doc.getApplicationData();
39 for (int q=0; q<appdatas.length; q++) {
40 String refstring=appdatas[q].getDataReference();
42 apdrefs.add(refstring);
43 User users[] = appdatas[q].getUser();
46 for (int u=0; u<users.length; u++) {
47 refstring=users[u].getDataReference();
49 apdrefs.add(new String(refstring)); // avoid referencing.
58 * General search through the set of AppData objects for a particular profile of Client and User handle.
60 * @param test interface implemented by the filter selecting particular AppDatas.
61 * @param cascade if true only User objects for ApplicationData objects that test.process returned true will be tested.
62 * @return set of org.vamsas.objects.core.AppData objects for which test.process returned true
64 static public Vector searchAppDatas(VamsasDocument doc, IAppDSearch test, boolean cascade) {
65 if ((doc!=null) && (doc.getApplicationDataCount()>0)) {
66 Vector apdrefs = new Vector();
67 ApplicationData[] appdatas = doc.getApplicationData();
68 for (int q=0; q<appdatas.length; q++) {
70 if (t=test.process(appdatas[q]))
71 apdrefs.add(appdatas[q]);
73 User users[] = appdatas[q].getUser();
75 for (int u=0; u<users.length; u++)
76 if (test.process(users[u]))
77 apdrefs.add(users[u]);
85 static public boolean equals(User p, UserHandle u) {
86 if (p.getFullname().equals(u.getFullName())
87 && p.getOrganization().equals(u.getOrganization()))
92 * returns true if Name matches in c and p, and Urn's match (or c.getUrn()==null) and Version's match (or c.getVersion()==null)
95 * @return match of p on template c.
97 static public boolean equals(ApplicationData p, ClientHandle c) {
99 ((c.getClientUrn()==null) || p.getUrn().equals(c.getClientUrn()))
101 (p.getName().equals(c.getClientName()))
103 ((c.getVersion()==null) || (p.getVersion().equals(c.getVersion())))
109 * Searches document appData structure for particular combinations of client and user data
110 * @param doc the data
111 * @param user template user data to match against
112 * @see AppDataReference.equals(org.vamsas.objects.core.User, org.vamsas.client.UserHandle)
114 * @see AppDataReference.equals(org.vamsas.objects.core.ApplicationData, org.vamsas.client.ClientHandle)
115 * @return set of matching client app datas for this client and user combination
117 static public Vector getUserandApplicationsData(VamsasDocument doc, UserHandle user, ClientHandle app) {
121 final UserHandle u = user;
122 final ClientHandle c = app;
124 IAppDSearch match = new IAppDSearch() {
125 public boolean process(AppData p) {
126 if (p instanceof User) {
127 if (AppDataReference.equals((User) p, u))
130 if (p instanceof ApplicationData) {
131 if (AppDataReference.equals((ApplicationData) p, c))
138 return searchAppDatas(doc, match, true); // only return AppDatas belonging to appdata app.