From: jprocter Date: Tue, 24 Jan 2006 19:31:24 +0000 (+0000) Subject: fixed a slight bug in AppData entry searching, and introduced generic AppData entry... X-Git-Tag: Release_0.2~347 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=349c4a3b6842fd54d791e0a92728dba294b30488;p=vamsas.git fixed a slight bug in AppData entry searching, and introduced generic AppData entry searching methods. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@173 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/org/vamsas/objects/utils/AppDataReference.java b/src/org/vamsas/objects/utils/AppDataReference.java index ecf9a43..0900239 100644 --- a/src/org/vamsas/objects/utils/AppDataReference.java +++ b/src/org/vamsas/objects/utils/AppDataReference.java @@ -4,15 +4,34 @@ package org.vamsas.objects.utils; import java.util.Vector; +import org.vamsas.client.ClientHandle; +import org.vamsas.client.UserHandle; import org.vamsas.objects.core.*; /** * Form, accessors and validation for ApplicationData references in * vamsas document. * 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 { + /** + * search interface for collecting particular types of AppDatas in a vamsas document + * @author jimp + * + */ + interface IAppDSearch { + /** + * process the appData object d + * @param d + * @return true if appData should be collected + */ + public boolean process(AppData d); + } + /** + * collect all appData reference strings in a vamsas document + * @param doc + * @return vector of String objects + */ static public Vector getAppDataReferences(VamsasDocument doc) { if ((doc!=null) && (doc.getApplicationDataCount()>0)) { Vector apdrefs = new Vector(); @@ -24,14 +43,98 @@ public class AppDataReference { User users[] = appdatas[q].getUser(); if (users!=null) - for (int u=0; u0) + return apdrefs; + } + return null; + } + /** + * General search through the set of AppData objects for a particular profile of Client and User handle. + * @param doc + * @param test interface implemented by the filter selecting particular AppDatas. + * @param cascade if true only User objects for ApplicationData objects that test.process returned true will be tested. + * @return set of org.vamsas.objects.core.AppData objects for which test.process returned true + */ + static public Vector searchAppDatas(VamsasDocument doc, IAppDSearch test, boolean cascade) { + if ((doc!=null) && (doc.getApplicationDataCount()>0)) { + Vector apdrefs = new Vector(); + ApplicationData[] appdatas = doc.getApplicationData(); + for (int q=0; q0) return apdrefs; } return null; } + static public boolean equals(User p, UserHandle u) { + if (p.getFullname().equals(u.getFullName()) + && p.getOrganization().equals(u.getOrganization())) + return true; + return false; + } + /** + * 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) + * @param p + * @param c + * @return match of p on template c. + */ + static public boolean equals(ApplicationData p, ClientHandle c) { + if ( + ((c.getClientUrn()==null) || p.getUrn().equals(c.getClientUrn())) + && + (p.getName().equals(c.getClientName())) + && + ((c.getVersion()==null) || (p.getVersion().equals(c.getVersion()))) + ) + return true; + return false; + } + /** + * Searches document appData structure for particular combinations of client and user data + * @param doc the data + * @param user template user data to match against + * @see AppDataReference.equals(org.vamsas.objects.core.User, org.vamsas.client.UserHandle) + * @param app + * @see AppDataReference.equals(org.vamsas.objects.core.ApplicationData, org.vamsas.client.ClientHandle) + * @return set of matching client app datas for this client and user combination + */ + static public Vector getUserandApplicationsData(VamsasDocument doc, UserHandle user, ClientHandle app) { + if (doc==null) { + return null; + } + final UserHandle u = user; + final ClientHandle c = app; + + IAppDSearch match = new IAppDSearch() { + public boolean process(AppData p) { + if (p instanceof User) { + if (AppDataReference.equals((User) p, u)) + return true; + } else + if (p instanceof ApplicationData) { + if (AppDataReference.equals((ApplicationData) p, c)) + return true; + } + return false; + } + }; + + return searchAppDatas(doc, match, true); // only return AppDatas belonging to appdata app. + } }