/** * */ package uk.ac.vamsas.objects.utils; import java.util.Vector; import uk.ac.vamsas.client.ClientHandle; import uk.ac.vamsas.client.UserHandle; import uk.ac.vamsas.client.simpleclient.VamsasArchive; import uk.ac.vamsas.client.simpleclient.VamsasArchiveReader; import uk.ac.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: 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 Vobject 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(); ApplicationData[] appdatas = doc.getApplicationData(); for (int q=0; q0) 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 uk.ac.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(uk.ac.vamsas.objects.core.User, uk.ac.vamsas.client.UserHandle) * @param app * @see AppDataReference.equals(uk.ac.vamsas.objects.core.ApplicationData, uk.ac.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. } /** * 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 = base.replace('/','_').replace('\\','_').replace(':', '_').replace('.', '_'); int v = 1; for (int i=0, j=dest.getApplicationDataCount(); i