From 2ea5b422dcbf74955d0f2360748cd2be5d9b543c Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 14 Dec 2006 18:05:40 +0000 Subject: [PATCH] refactored org to uk git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@272 be28352e-c001-0410-b1a7-c7978e42abec --- src/org/vamsas/client/ClientDocument.java | 52 --- src/org/vamsas/client/ClientHandle.java | 97 ---- src/org/vamsas/client/Events.java | 92 ---- src/org/vamsas/client/IClient.java | 142 ------ src/org/vamsas/client/IClientAppdata.java | 61 --- src/org/vamsas/client/IClientDocument.java | 99 ----- src/org/vamsas/client/IClientFactory.java | 56 --- src/org/vamsas/client/IObjectUpdate.java | 26 -- src/org/vamsas/client/IVorbaIdFactory.java | 37 -- src/org/vamsas/client/Iapp.java | 12 - .../vamsas/client/InvalidSessionUrnException.java | 38 -- .../vamsas/client/NoDefaultSessionException.java | 46 -- src/org/vamsas/client/SessionHandle.java | 38 -- src/org/vamsas/client/SessionUrn.java | 40 -- src/org/vamsas/client/UserHandle.java | 50 --- src/org/vamsas/client/Vobject.java | 464 -------------------- src/org/vamsas/client/Vobjhash.java | 25 -- src/org/vamsas/client/VorbaId.java | 73 --- src/org/vamsas/client/VorbaIdFactory.java | 84 ---- src/org/vamsas/client/VorbaXmlBinder.java | 241 ---------- 20 files changed, 1773 deletions(-) delete mode 100644 src/org/vamsas/client/ClientDocument.java delete mode 100644 src/org/vamsas/client/ClientHandle.java delete mode 100644 src/org/vamsas/client/Events.java delete mode 100644 src/org/vamsas/client/IClient.java delete mode 100644 src/org/vamsas/client/IClientAppdata.java delete mode 100644 src/org/vamsas/client/IClientDocument.java delete mode 100644 src/org/vamsas/client/IClientFactory.java delete mode 100644 src/org/vamsas/client/IObjectUpdate.java delete mode 100644 src/org/vamsas/client/IVorbaIdFactory.java delete mode 100644 src/org/vamsas/client/Iapp.java delete mode 100644 src/org/vamsas/client/InvalidSessionUrnException.java delete mode 100644 src/org/vamsas/client/NoDefaultSessionException.java delete mode 100644 src/org/vamsas/client/SessionHandle.java delete mode 100644 src/org/vamsas/client/SessionUrn.java delete mode 100644 src/org/vamsas/client/UserHandle.java delete mode 100644 src/org/vamsas/client/Vobject.java delete mode 100644 src/org/vamsas/client/Vobjhash.java delete mode 100644 src/org/vamsas/client/VorbaId.java delete mode 100644 src/org/vamsas/client/VorbaIdFactory.java delete mode 100644 src/org/vamsas/client/VorbaXmlBinder.java diff --git a/src/org/vamsas/client/ClientDocument.java b/src/org/vamsas/client/ClientDocument.java deleted file mode 100644 index 3866a90..0000000 --- a/src/org/vamsas/client/ClientDocument.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - */ -package org.vamsas.client; - -import java.util.Hashtable; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.vamsas.objects.core.VAMSAS; - -/** - * skeleton abstract class to allow client implementations - * access to vamsas.client.Vobject registry mechanism. - */ -public abstract class ClientDocument implements IClientDocument { - static Log log = LogFactory.getLog(ClientDocument.class); - - /** - * collection of org.vamsas.client.Vobject references - */ - protected Hashtable vamsasObjects; - protected IVorbaIdFactory vorbafactory; - - protected ClientDocument(Hashtable objects, IVorbaIdFactory factory) { - vamsasObjects = objects; - vorbafactory = factory; - } - - /** - * @see IClientHandle.registerObject(Vobject unregistered) - */ - protected VorbaId _registerObject(Vobject unregistered) { - // be ultra safe here because the user may be trying to mix different factories - if (unregistered.__vorba==null) - unregistered.__vorba = vorbafactory; - else - if (unregistered.__vorba!=vorbafactory) { - // LATER: decide if this is allowed - it isn't for the moment. - log.error("Attempt to overwrite info in a registered vorba Vobject (under a different IVorbaIdFactory) ! - Implementation fix needed."); - return null; - } else { - // probably didn't need to call registerObject. - log.debug("Redundant call to registerObject"); - } - // TODO: add default provenance. - // TODO: decide if we need to do call __ensure_instance_ids here - // TODO: check if __ensure_instance_ids works correctly with new 'visit flag' mechanism - unregistered.__ensure_instance_ids(); // call cascade method here : - return unregistered.getVorbaId(); - } -} diff --git a/src/org/vamsas/client/ClientHandle.java b/src/org/vamsas/client/ClientHandle.java deleted file mode 100644 index 76666f9..0000000 --- a/src/org/vamsas/client/ClientHandle.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - */ -package org.vamsas.client; - -import java.io.Serializable; - -/** - * Uniquely describes a vamsas client application. - * @author jimp - */ -public class ClientHandle implements Serializable { - static final long serialVersionUID = 0; - /** - * @param clientName - * @param version - */ - public ClientHandle(String clientName, String version) { - super(); - this.clientName = clientName; - this.version = version; - this.setClientUrn("vamsas://"+clientName+":"+version+"/"); // TODO: decide on application handle ornthing (used to prefix new ids made by a particular application) - } - /** - * (non-unique) human readable vamsas client name - */ - String clientName; - - /** - * the unambiguous client identifier - * This may be rewritten by the Vorba object if - * other clients with the same name, version - * and user are involved in a session. - * - */ - String clientUrn; - - /** - * version modifier to tag application space - */ - String version; - - /** - * @return Returns the clientUrn. - */ - public String getClientUrn() { - return clientUrn; - } - - /** - * May become protected - should only be set by a Vorba object. - * @param clientUrn - * The clientUrn to set. - */ - public void setClientUrn(String clientUrn) { - this.clientUrn = clientUrn; - } - - /** - * @return Returns the version. - */ - public String getVersion() { - return version; - } - - /** - * @param version - * The version to set. - */ - public void setVersion(String version) { - this.version = version; - } - - - /** - * @return Returns the clientName. - */ - public String getClientName() { - return clientName; - } - - /** - * @param clientName - * The clientName to set. - */ - public void setClientName(String clientName) { - this.clientName = clientName; - } - - public boolean equals(Object that) { - if (that instanceof ClientHandle) - return this.equals((ClientHandle) that); - return false; - } - public boolean equals(ClientHandle that) { - return (clientName.equals(that.clientName) && version.equals(that.version) && clientUrn.equals(that.clientUrn)); - } -} diff --git a/src/org/vamsas/client/Events.java b/src/org/vamsas/client/Events.java deleted file mode 100644 index 4a91f5a..0000000 --- a/src/org/vamsas/client/Events.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.vamsas.client; - -/** - * Enumerates the event types generated during the lifecycle of a Vamsas - * session. - * See the excel spreadsheet in VamsasClient/docs/VamsasSessionEventAnalysis.xls for - * some more information about when these are generated and how they should be - * handled. - * - */ - -public class Events { - /** - * Generated when a client has finished updating the document. - * Client which has completed an update should - * not receive the event. - * NewValue: org.vamsas.client.IClient for session. - */ - public static final String DOCUMENT_UPDATE = "org.vamsas.client.events.documentUpdateEvent"; - - /** - * Generated when a new vamsas document is created (perhaps from some existing - * Vamsas data) so an application may do its own data space initialization. - * Raised for a new application connecting to a vamsas document - * NewValue: org.vamsas.client.IClient for session. - * LATER: DOCUMENT_CREATE event may be redundant - */ - public static final String DOCUMENT_CREATE = "org.vamsas.client.events.documentCreateEvent"; - - /** - * Generated when a new vamsas client is attached to a session (Handle is - * passed) Note: the newly created client does not receive the event. - */ - public static final String CLIENT_CREATION = "org.vamsas.client.events.clientCreateEvent"; - - /** - * Generated when a vamsas client leaves a session (Handle is passed to all - * others). - */ - public static final String CLIENT_FINALIZATION = "org.vamsas.client.events.clientFinalizationEvent"; - - /** - * Generated prior to session Shutdown, after the last participating vamsas - * client has finalized. - * Probably only useful to IClientFactory implementations. - * NewValue: - */ - public static final String SESSION_SHUTDOWN = "org.vamsas.client.events.SessionShutdownEvent"; - - /** - * Generated for all clients when any client calls IClient.storeDocument() to - * allow them to store any updates before an offline copy of the session is - * created. - * Any client that handles this should call the - * IClient.getDocument(), update and then IClient.updateDocument in the same - * handler thread (the lock on the document is held until the handler exits). - * EventName: - * NewValue: org.vamsas.client.IClient for session. - */ - public static final String DOCUMENT_FINALIZEAPPDATA = "org.vamsas.client.events.DocumentFinalizeAppData"; - - /** - * Generated by Vorba stub for the sole remaining client instance in a session, - * when it makes a call to finalizeClient(). - * It is only raised if the session has been modified since the - * last call to storeDocument() by any application. - * LATER: copies of a document should be on a per-user basis for multi-user sessions. - * Sequence is as follows : 1. All other vamsas clients have - * called finalizeClient() 2. Final living client monitors closures, and - * realises that it is last. 3. Final client generates event to prompt - * associated application to inquire if the user wishes to save the document - * for future reference. - * * Any call to finalizeClient in a thread other than the registered - * EventListener will block until the RequestToClose handler has exited. - * NewValue: org.vamsas.client.IClient for session. - */ - public static final String DOCUMENT_REQUESTTOCLOSE = "org.vamas.client.DocumentRequestToCloseEvent"; - - public static java.util.Vector EventList = initList(); - - private static java.util.Vector initList() { - java.util.Vector vec = new java.util.Vector(); - vec.add((Object) DOCUMENT_UPDATE); - vec.add((Object) DOCUMENT_CREATE); - vec.add((Object) CLIENT_CREATION); - vec.add((Object) CLIENT_FINALIZATION); - vec.add((Object) SESSION_SHUTDOWN); - vec.add((Object) DOCUMENT_REQUESTTOCLOSE); - vec.add((Object) DOCUMENT_FINALIZEAPPDATA); - return vec; - } -} diff --git a/src/org/vamsas/client/IClient.java b/src/org/vamsas/client/IClient.java deleted file mode 100644 index aaf855f..0000000 --- a/src/org/vamsas/client/IClient.java +++ /dev/null @@ -1,142 +0,0 @@ -/** - * org.vamsas.client.IClient - * - */ -package org.vamsas.client; - -import java.beans.PropertyChangeListener; -import java.io.IOException; - -/** - * Defines the methods availabable to a vamsas - * application for interacting with its Vorba agent - * created by an IClientFactory instance for a particular session, - * user, and application handle. - * (it's VORBA, not CORBA!) - * LATER: add exceptions for timeouts raised when there are problems accessing session data (because another application is hogging it). - * LATER: think about situations when two applications both want a ClientDocument at the same time - can one have read-only access (and be told that another is about to update) - */ - -public interface IClient { - - /** - * Self-documenting/describing info for the application to present - * to the user. - * LATER: formalise this for describing VAMSAS system, a particular - * Vorba client agent, and a particular session. - * @return string like VamsasClient v.1.1.1 (GPL) and whatever - */ - public String getAbout(); - - /** - * convenience method to get the SessionUrn as a string (for passing directly to a text box...). - * @return current SessionUrn - */ - public String getSessionUrn(); - /** - * Returns a valid URN for other applications to connect to - * the vamsas session. - * @return session handle for this session. - */ - public SessionHandle getSessionHandle(); - /** - * Included for applications with several ClientHandle - * identities. - * @return ClientHandle used to interact with - * other Vamsas applications. - */ - public ClientHandle getClientHandle(); - /** - * - * @return UserHandle used when interacting - * with other Vamsas applications. - */ - public UserHandle getUserHandle(); - /** - * Method called by client application on exit. - * Vorba will inform other clients if they exist. - * If this is the last application in the session - * then the session will be closed. - * Note: The application should be ready to handle - * 'RequestToCloseDocument' events from the Vorba - * agent in the latter case and so prompt the user - * to save the session locally. - * LATER: pick a better name ? - */ - public void finalizeClient(); - /** - * register handler for updates for the current session - */ - public void addDocumentUpdateHandler(PropertyChangeListener evt); - /** - * get vamsas document with - * user and app specific data - * IClientDocuments are not thread-safe. - * TODO: New exception for failed document lock. - * @throws IOException if lock is not obtainable for the document in the session - */ - public IClientDocument getClientDocument() throws IOException; - /** - * Queue new Vorba objects for storage and propagation - * to other clients (via Event.DOCUMENT_UPDATE based - * notification of document change) - * New objects without provenance information will be - * given a default entry using the IClient's application, - * user (and session) handles - * Validity of IClientDocument object instances after this call is implementation dependent - * TODO: consider refactoring to remove the redundant IClientDocument parameter for this method - */ - public void updateDocument(IClientDocument newdoc); - /** - * Any application may call storeDocument to - * save a local copy of the current vamsas document - * including all application specific entries. - * - * @param location to write zip file - */ - public void storeDocument(java.io.File location); - /** - * Any application may call importDocument to merge a stored - * vamsasDocument into the current session. - * Note: use a IClientFactory's implementation to make sessions out of vamsas documnts - * LATER: VAMSAS: The IClient implementation will handle all ID 'relocations' - * @param location - */ - public void importDocument(java.io.File location); - /** - * Add a listener to a particular event chain. - * See org.vamsas.client.Events for allowed - * values for EventChain. - * The EventChain value is passed as the - * propertyName in the java.bean.PropertyChangeEvent - * LATER: extend class to form own vamsas Event/Listener model. - * @param EventChain Name of event. Blank/null registers handler for all events. - * @param evt - event handler function. - */ - public void addVorbaEventHandler(String EventChain, PropertyChangeListener evt); - /** - * Sets the update handler that will be called when any updates occur to objects of type rootObject. - * @param rootObject - * @param handler - */ - public void setUpdateHandler(IObjectUpdate handler); - public IObjectUpdate getUpdateHandler(Class rootObject); - public void removeUpdateHandler(Class rootObject); - public IObjectUpdate[] getUpdateHandlers(); - /** - * client application calls this to force the - * Vorba client to check for updates immediately. - * - */ - public void pollUpdate(); - - /** - * Client application calls this after any pre-session initialization - * (registering of Handlers, etc) - * Exceptions are raised for any failures. Any stateful calls to the session prior to - * this will result in an implicit call to joinSession - if that results in an exception - * then the VamsasClient should raise an Error. - * LATER: create VAMSAS exception hierarchy (in a language agnostic manner) - */ - public void joinSession() throws Exception; -} diff --git a/src/org/vamsas/client/IClientAppdata.java b/src/org/vamsas/client/IClientAppdata.java deleted file mode 100644 index 965a783..0000000 --- a/src/org/vamsas/client/IClientAppdata.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * - */ -package org.vamsas.client; - -import java.io.DataInput; -import java.io.DataOutput; - -/** - * Object for accessing Client and User specific data - * in an IClientDocument instance. - * - */ -public interface IClientAppdata { - /** - * @return true if Client's non-user specific application data is non-zero length. - */ - boolean hasClientAppdata(); - /** - * @return true if User's Client Application data is non-zero length - */ - boolean hasUserAppdata(); - /** - * - * @return byte array containing the Client's non-user specific application data - */ - byte[] getClientAppdata(); - /** - * - * @return byte array containing the Client's user specific application data - */ - byte[] getUserAppdata(); - /** - * set the non-User-specific application data - * @param data - the new non-user-specific data - */ - void setClientAppdata(byte[] data); - /** - * set the User-specific application data - * @param data - the new user-specific data - */ - void setUserAppdata(byte[] data); - /** - * @return non-user specific data output stream - */ - DataOutput getClientOutputStream(); - /** - * @return non-user specific data input stream - */ - DataInput getClientInputStream(); - /** - * - * @return user specific data output stream - */ - DataOutput getUserOutputStream(); - /** - * - * @return user specific data input stream - */ - DataInput getUserInputStream(); -} diff --git a/src/org/vamsas/client/IClientDocument.java b/src/org/vamsas/client/IClientDocument.java deleted file mode 100644 index 8db697f..0000000 --- a/src/org/vamsas/client/IClientDocument.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Created on 13-Sep-2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.vamsas.client; - -import org.vamsas.objects.core.VAMSAS; - - -/** - * Defines the API for the Vamsas XML Document - * as accessed by a Vamsas SimpleClient Application. - * An instance of this interface is valid for a - * particular set of user, session and application - * handles. - * - * It initially represents a snapshot of the - * XML document at a particular time - queriable by - * reference or by retrieval of root objects. - * It provides methods to make new Vobject references, - * These are guaranteed to be unique amongst existing - * objects in the document, all other references created - * by this Vobject's instance and all other references - * constructed by any other vamsas agents in the session. - * TODO: LATER: finegrained access control for public/private user access - * Finegrained access control: Since a clientDocument is created for a particular - * UserHandle, there is scope for fine grain data access - * control based on user identity. - * A user may also want to make private notes, not - * available to other people using the same application - * in the same session. - * TODO: LATER: implement a more sophisticated query interface for quickly identifying new data in a vamsas document and manipulating existing objects - * @author jimp - */ -public interface IClientDocument { - - /** - * Get a single Vobject. - * @param id - * @return Vobject referred to by id or null if it doesn't exist. - */ - Vobject getObject(VorbaId id); - /** - * Get a list of objects. - * @param ids - * @return array of objects using a vector of VorbaId ids. - */ - Vobject[] getObjects(VorbaId[] ids); - /** - * Returns all root objects in document. All objects inherit - * from org.vamsas.client.Vobject and have valid VorbaIds and provenance entries. - * @return array of root Vamsas element objects. - */ - VAMSAS[] getVamsasRoots(); - /** - * set the VAMSAS roots in the document - * TODO: decide if objects are verified for provenance and VorbaIds by this call or when document is stored - * TODO: decide if this call should throw InvalidVamsasObject exceptions. - * TODO: decide how this call deals with applications that 'forget' to include all VAMSAS roots (this is where reference counting/garbage collection happens) - * @param roots - */ - void setVamsasRoots(VAMSAS[] roots); - /** - * Adds a new VAMSAS root entry - * TODO: decide on same InvalidVamsasObject exceptions. - * TODO: decide if a 'removeVamsasRoot' method is really needed. - * @param newroot - */ - void addVamsasRoot(VAMSAS newroot); - /** - * Returns an Vobject with a valid VorbaId, and provenance element. - * The VorbaId is so the application may refer to it in - * its own dataspace. - * - * Note: An Vobject with valid VorbaId will not be reregistered. - * Advice: Calling this method for a high-level Vobject - * (such as org.vamsas.objects.core.VAMSAS) will - * register all its component objects too. - * - * @param unregistered unregistered vamsas Vobject - * @return VorbaId registered for vamsas Vobject - */ - VorbaId registerObject(Vobject unregistered); - /** - * Returns an array of objects, each with a valid VorbaId - * (and completed provenance entry). - * Note: An Vobject with valid VorbaId will not be reregistered. - * @param unregistered array of unregistered objects. - * @return array of VorbaIds for the registered objects - */ - VorbaId[] registerObjects(Vobject[] unregistered); - /** - * Get instance of Client and User specific vamsas document data access interface. - * @return Interface to Client and user specific application data - */ - IClientAppdata getClientAppdata(); -} \ No newline at end of file diff --git a/src/org/vamsas/client/IClientFactory.java b/src/org/vamsas/client/IClientFactory.java deleted file mode 100644 index f9a50b4..0000000 --- a/src/org/vamsas/client/IClientFactory.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Created on 13-Sep-2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.vamsas.client; - -/** - * Defines methods for instantiating Vorba client application agents - * @author jimp - * - * (it's VORBA, not CORBA!) - */ - -public interface IClientFactory { - - /** - * Create a new Vorba Session - * @param applicationHandle is the application's VAMSAS handle string - * @throws NoDefaultSessionException if more than one session exists that the client may connect to - */ - IClient getIClient(ClientHandle applicationHandle) throws NoDefaultSessionException; - /** - * returns new Vorba for a given session. - * @param applicationHandle - * @param sessionUrn session to connect to (or null to create a new session) - * @return - */ - IClient getIClient(ClientHandle applicationHandle, String sessionUrn); - /** - * returns new vorba for a given session acting as a particular identity - * @param applicationHandle - * @param userId - * @param sessionUrn session to connect to (or null to create a new session) - * @return - */ - IClient getIClient(ClientHandle applicationHandle, UserHandle userId, String sessionUrn); - /** - * New session for application and specific user - * @param applicationHandle - * @param userId - * @return - * @throws NoDefaultSessionException if more than one session exists that the client may connect to - */ - IClient getIClient(ClientHandle applicationHandle, UserHandle userId) throws NoDefaultSessionException; - - /** - * enumerate the active sessions this IClientFactory instance knows about. - * Can be used by caller to pick a session on catching a NoDefaultSessionException. - * LATER: Define interface for discovering more information about a session (so it can be presented to a user in a meaningful way) - * @return possibly empty array of sessionUrn strings - */ - public String[] getCurrentSessions(); - -} diff --git a/src/org/vamsas/client/IObjectUpdate.java b/src/org/vamsas/client/IObjectUpdate.java deleted file mode 100644 index cda754d..0000000 --- a/src/org/vamsas/client/IObjectUpdate.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.vamsas.client; - -/** - * Methods implemented by a Vamsas Application's Object Update handler - * @author vamsas - * Introduced November 2006 Vamsas Meeting - * TODO: verify this is sufficient for the per-object update event mechanism - */ -public interface IObjectUpdate { - /** - * Called by the library to find out which vamsas document object this update handler is interested in - * @return class that extends org.vamsas.Vobject - */ - Class getRootVobject(); - /** - * Called to test if this handler is to be called for updates to any Vobjects below the Root Vobject in the vamsas document. - * @return false means IObjectUpdate.update(updated, cdoc) will only be called with instances of type getRootVobject(). - */ - boolean handlesSubtreeUpdates(); - /** - * Method called by Vamsas Client Library for all updated objects that the handler is registered for. - * @param updated - * @param cdoc - */ - void update(org.vamsas.client.Vobject updated, org.vamsas.client.IClientDocument cdoc); -} diff --git a/src/org/vamsas/client/IVorbaIdFactory.java b/src/org/vamsas/client/IVorbaIdFactory.java deleted file mode 100644 index ea25e8e..0000000 --- a/src/org/vamsas/client/IVorbaIdFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Created on 14-Sep-2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.vamsas.client; - -/** - * @author jimp - * middleware interface for generating new VorbaId objects - * for a particular vamsas client based on the current - * session, user and client handle. Generally implemented - * by instances of the vamsas library api only. - */ -public interface IVorbaIdFactory { - /** - * construct a new id appropriate for this client in the vamsas session. - * @param vobject TODO - * - * @return valid VorbaId for session, or null if VorbaIdFactory not configured - * correctly. - */ - public abstract VorbaId makeVorbaId(Vobject vobject); - - public abstract SessionHandle getSessionHandle(); - - public abstract ClientHandle getClientHandle(); - - public abstract UserHandle getUserHandle(); - /** - * called when an object is touched by the vamsas library prior to writing - * to record last hash for the object's VorbaId - * @param vobject - */ - public abstract void updateHashValue(Vobject vobject); -} \ No newline at end of file diff --git a/src/org/vamsas/client/Iapp.java b/src/org/vamsas/client/Iapp.java deleted file mode 100644 index 381e22b..0000000 --- a/src/org/vamsas/client/Iapp.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * org.vamsas.client.Iapp - */ -package org.vamsas.client; -public interface Iapp { - /** - * Define core callback functionality that a fully - * fledged vamsas application Vobject must implement - * TODO: define some Application Callbacks and create use cases for them - */ - -}; diff --git a/src/org/vamsas/client/InvalidSessionUrnException.java b/src/org/vamsas/client/InvalidSessionUrnException.java deleted file mode 100644 index d1863a8..0000000 --- a/src/org/vamsas/client/InvalidSessionUrnException.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.vamsas.client; - -public class InvalidSessionUrnException extends Exception { - - /** - * - */ - public InvalidSessionUrnException() { - super("Invalid Vamsas Session URN."); - // TODO Auto-generated constructor stub - } - - /** - * @param message - * @param cause - */ - public InvalidSessionUrnException(String message, Throwable cause) { - super(message, cause); - // TODO Auto-generated constructor stub - } - - /** - * @param message - */ - public InvalidSessionUrnException(String message) { - super("Invalid Vamsas Session URN: "+message); - // TODO Auto-generated constructor stub - } - - /** - * @param cause - */ - public InvalidSessionUrnException(Throwable cause) { - super(cause); - // TODO Auto-generated constructor stub - } - -} diff --git a/src/org/vamsas/client/NoDefaultSessionException.java b/src/org/vamsas/client/NoDefaultSessionException.java deleted file mode 100644 index bfee0e6..0000000 --- a/src/org/vamsas/client/NoDefaultSessionException.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * - */ -package org.vamsas.client; - -/** - * @author jimp - * Raised if an IClient instance is requested without - * specifying a particular vamsas session handle - * when more than one candidate session exists. - */ -public class NoDefaultSessionException extends Exception { - - /** - * - */ - public NoDefaultSessionException() { - super("No Default Session Defined"); - } - - /** - * @param message - */ - public NoDefaultSessionException(String message) { - super(message); - // TODO Auto-generated constructor stub - } - - /** - * @param cause - */ - public NoDefaultSessionException(Throwable cause) { - super(cause); - // TODO Auto-generated constructor stub - } - - /** - * @param message - * @param cause - */ - public NoDefaultSessionException(String message, Throwable cause) { - super(message, cause); - // TODO Auto-generated constructor stub - } - -} diff --git a/src/org/vamsas/client/SessionHandle.java b/src/org/vamsas/client/SessionHandle.java deleted file mode 100644 index 736fee3..0000000 --- a/src/org/vamsas/client/SessionHandle.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Created on 12-Sep-2005 - * - */ -package org.vamsas.client; - -/** - * Uniquely locates a particular VAMSAS session. - * @author jimp - * - */ -public class SessionHandle { - - /** - * @param sessionUrn - */ - public SessionHandle(String sessionUrn) { - super(); - SessionUrn = sessionUrn; - } - /** - * @return Returns the sessionUrn. - */ - public String getSessionUrn() { - return SessionUrn; - } - /** - * @param sessionUrn The sessionUrn to set. - */ - public void setSessionUrn(String sessionUrn) { - SessionUrn = sessionUrn; - } - /** - * The path to the vamsas session file. - */ - String SessionUrn; - -} diff --git a/src/org/vamsas/client/SessionUrn.java b/src/org/vamsas/client/SessionUrn.java deleted file mode 100644 index 4eff113..0000000 --- a/src/org/vamsas/client/SessionUrn.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * - */ -package org.vamsas.client; - -import java.net.URI; -import java.util.Hashtable; -import java.util.Vector; - -/** - * @author jimp - * base class for vamsas session/document types - * uses java.net.URI internally for construction of URN - */ -public abstract class SessionUrn { - protected URI urn; - /** - * The types of URI protocols we understand - */ - protected static final Hashtable TYPES=new Hashtable(); - - /** - * construct urn for a locally stored session file - * @param type - * @param url - */ - protected SessionUrn(String type, java.net.URL url) { - if (!TYPES.containsKey(type.toLowerCase())) - throw new Error("Unknown "+this.getClass().getName()+" type '"+type+"' for URL '"+url+"'"); - try { - urn = URI.create(type+"://"+url.getPath()); - } catch (Exception e) { - // TODO: something better than throwing an error should be done here. - throw new Error(e); - } - } - public String getSessionUrn() { - return urn.toString(); - } -} diff --git a/src/org/vamsas/client/UserHandle.java b/src/org/vamsas/client/UserHandle.java deleted file mode 100644 index 8bfe16c..0000000 --- a/src/org/vamsas/client/UserHandle.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Created on 12-Sep-2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.vamsas.client; - -/** - * Unique user identifier for a vamsas session. - * Used to write user provenance information, and - * track view/access control in multiuser sessions. - * @author jimp - */ -public class UserHandle { - /** - * @param fullName - * @param organization - */ - public UserHandle(String fullName, String organization) { - this.fullName = fullName; - Organization = organization; - } - String fullName; - String Organization; - /** - * @return Returns the fullName. - */ - public String getFullName() { - return fullName; - } - /** - * @param fullName The fullName to set. - */ - public void setFullName(String fullname) { - fullName = fullname; - } - /** - * @return Returns the organization. - */ - public String getOrganization() { - return Organization; - } - /** - * @param organization The organization to set. - */ - public void setOrganization(String organization) { - Organization = organization; - } -} diff --git a/src/org/vamsas/client/Vobject.java b/src/org/vamsas/client/Vobject.java deleted file mode 100644 index d7bd6eb..0000000 --- a/src/org/vamsas/client/Vobject.java +++ /dev/null @@ -1,464 +0,0 @@ -/** - * - */ -package org.vamsas.client; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Iterator; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.exolab.castor.mapping.FieldDescriptor; -import org.exolab.castor.mapping.FieldHandler; -import org.exolab.castor.xml.util.XMLClassDescriptorImpl; -import org.vamsas.test.simpleclient.VamsasArchive; - -/** - * Base class for all Vamsas objects extracted from an IClientDocument. An - * Vobject maybe registered or unregistered. - * - * @author jimp - * - */ -public abstract class Vobject { - static Log log = LogFactory.getLog(Vobject.class); - - /** - * true if Vobject was stored in a vamsas Document or has been retrieved from it - */ - protected boolean __stored_in_document = false; - /** - * true if Vobject was updated since the vamsas library last read a Vobj with the same VorbaId from a document. - */ - protected boolean __updated_since_last_read = false; - /** - * memory of the last doHash() value computed for the Vobject - * @see doHash() - */ - protected int __last_hash = 0; - /** - * set by testInstanceForIdField() if Vobject should have a VorbaId - */ - protected boolean registerable = false; - protected boolean __visited = false; - /** - * reference to containing object for this Vobject. - */ - protected Vobject V_parent=null; - /** - * unique id for all vamsas objects allows unambiguous referencing to any - * Vobject in the vamsas document - */ - protected VorbaId vorbaId = null; - - /** - * the source of unique VorbaIds. - */ - protected IVorbaIdFactory __vorba = null; - - /* (non-Javadoc) - * @see java.lang.Object#finalize() - */ - protected void finalize() throws Throwable { - V_parent=null; - __vorba=null; - vorbaId=null; - super.finalize(); - } - - /** - * - */ - protected Vobject() { - super(); - testInstanceForIdField(); - } - java.lang.reflect.Field ___id_field=null; // set to ease pain of reflection - /** - * set the isRegisterable flag based on the presence of a 'private String _id' field in - * the reflected class instance. - */ - private void testInstanceForIdField() { - // TODO: decide if 'id' is an appropriate reserved attribute name for the VorbaId - // look for the id field in all castor classes (should be an NCName string) - - Class thisclass=this.getClass(); - setRegisterable(false); - while (!thisclass.equals(Vobject.class)) { - try { - java.lang.reflect.Field fd = thisclass.getDeclaredField("_id"); - if (String.class.isAssignableFrom(fd.getType())) { - ___id_field=fd; - this.setRegisterable(true); - break; - } - } catch (SecurityException e) { - log.error("Unexpected Security Exception whilst finding id fields to set!",e); - } catch (NoSuchFieldException e) { - thisclass=thisclass.getSuperclass(); - } - } - } - // boolean __testedInstance=false; - /** - * update the Vobject instance's _id field, based on the contents of the - * VorbaId. Only call this if you mean to do it! - */ - protected void setInstanceIdField() { - /*if (!registerable && !__testedInstance) { - testInstanceForIdField(); - __testedInstance=true; - }*/ - if (registerable) { - if (__vorba != null) - try { - Method fd = this.getClass().getMethod("setId", new Class[] { String.class }); - fd.invoke((Object) this, new Object[] {new String(this.getVorbaId().id)}); - log.debug(this.getClass().getName()+" called setInstanceIdField!"); - } catch (InvocationTargetException e) { - log.error("SourceGeneration of " - + this.getClass().toString() - + "\n has resulted in an inaccessible 'setId' method!\nCannot set ID from the vorbaId Vobject.", e); - } - catch (IllegalAccessException e) { - log.error("SourceGeneration of " - + this.getClass().toString() - + "\n has resulted in an inaccessible 'setId' method!\nCannot set ID from the vorbaId Vobject.", e); - } catch (SecurityException e) { - log.error("Security access violation for "+this.getClass().toString(),e); - } catch (NoSuchMethodException e) { - log.warn(this.getClass().toString()+" was erroneously marked as a Vorba Vobject class (Implementation error?)"); - this.setRegisterable(false); - } - } else { - System.err.println("Client error. Trying to setInstanceIdField on a " - + this.getClass().toString() + " (which cannot be given a vorbaId)"); - } - } - - protected String __getInstanceIdField() { - /*if (!registerable && !__testedInstance) { - testInstanceForIdField(); - __testedInstance=true; - }*/ - if (registerable) { - if (__vorba != null) - try { - Method fd = this.getClass().getMethod("getId", (Class[]) null); - Object idstring = fd.invoke((Object) this, (Object[]) null); - log.debug(this.getClass().getName()+" called getInstanceIdField!"); - if (idstring!=null && idstring instanceof String) { - if (((String) idstring).length()>0) - return (String) idstring; - } - } catch (InvocationTargetException e) { - log.error("SourceGeneration of " - + this.getClass().toString() - + "\n has resulted in an inaccessible 'getId' method!\nCannot set ID from the vorbaId Vobject.", e); - } - catch (IllegalAccessException e) { - log.error("SourceGeneration of " - + this.getClass().toString() - + "\n has resulted in an inaccessible 'getId' method!\nCannot set ID from the vorbaId Vobject.", e); - } catch (SecurityException e) { - log.error("Security access violation for "+this.getClass().toString(),e); - } catch (NoSuchMethodException e) { - log.warn(this.getClass().toString()+" was erroneously marked as a Vorba Vobject class (Implementation error?)"); - this.setRegisterable(false); - } - } else { - System.err.println("Client error. Trying to getInstanceIdField on a " - + this.getClass().toString() + " (which cannot be given a vorbaId)"); - } - return null; - } - - /** - * calculate a hash for the Vobject with all housekeeping fields at standard - * values. (isRegisterable is an immutable attribute property) - * TODO: decide if __stored_in_document should be included in the hash or not. - * @return true if new hash different to last hash - */ - synchronized protected boolean doHash() { - long __old_hash = __last_hash; - __last_hash = 0; - Vobject _V_parent=V_parent; - V_parent=null; - VorbaId thisid = vorbaId; - IVorbaIdFactory factory = __vorba; - boolean stored = __stored_in_document; - boolean updated = __updated_since_last_read; - boolean visited = __visited; - java.lang.reflect.Field idfield = ___id_field; - ___id_field=null; - __updated_since_last_read=false; - vorbaId = null; - __vorba = null; - __visited=false; - // compute hash - __last_hash = this.hashCode(); - // reset houseskeeping variables - ___id_field=idfield; - vorbaId = thisid; - __vorba = factory; - __stored_in_document = stored; - __updated_since_last_read=updated; - V_parent=_V_parent; - __visited=visited; - return (__old_hash==0) || (__old_hash == __last_hash); - } - - /** - * TODO: combine two versions of the same collection Vobject to resolve - * asynchronous updates to the same vamsas Vobject Merges two vamsas objects, - * one of which is a later version of the earlier (ie they have the same - * vorbaId but one is a later version recently read from the vamsasDocument - * collection. - * - * @return - */ - protected boolean merge(Vobject laterCopy) { - log.warn(this.getClass().getName()+".merge() not implemented."); - return true; - } - - /** - * - * @return true if Vobject is registered - */ - public boolean isRegistered() { - return (registerable) ? (vorbaId != null) : false; - } - - /** - * Method to get fixed reference for the Vobject in the vamsas document. - * - * @returns null if Vobject is neither registered or not associated with a - * properly instantiated VorbaIdFactory. - */ - public VorbaId getVorbaId() { - if (registerable && vorbaId == null) { - if (this.__stored_in_document) { - if (__vorba!=null) - vorbaId=org.vamsas.client.VorbaId.newId(this.__getInstanceIdField()); - } - // Try to use the associated factory. - if (__vorba != null) - if ((vorbaId = __vorba.makeVorbaId(this)) == null) - return null; // Factory not valid. - else { - this.setInstanceIdField(); - return vorbaId; - } - } - return vorbaId; - } - - /** - * used by the IClient implementation to generate unique Id based on client - * applications current namespace. - */ - protected void setVorbaId(VorbaId newid) { - vorbaId = newid; - } - - /** - * @return true if Vobject is present in Vamsas Document. - */ - public boolean is__stored_in_document() { - return __stored_in_document; - } - - /** - * @return true if this object has been updated in the currently stored document since the last time a Vobject with the same ID was read from a Vamsas Document - */ - public boolean is__updated_since_last_read() { - return __updated_since_last_read; - } - - /** - * Set internal flag to indicate this object was updated since the last document read - * @param __updated_since_last_read the __updated_since_last_read to set - */ - protected void set__updated_since_last_read(boolean __updated_since_last_read) { - this.__updated_since_last_read = __updated_since_last_read; - } - - /** - * for use by Vorba agent to reflect state of vamsas Vobject to client - * application. - * Setting stored_in_document on a registerable Vobject without a - * vorbaId will mean is will *never* get a vorbaId and - * horrible things will happen. - * @param __stored_in_document true if Vobject has been marshalled into current document. - */ - protected void set__stored_in_document(boolean __stored_in_document) { - this.__stored_in_document = __stored_in_document; - } - - /** - * __last_hash is the hash value computed when the Vobject was last checked - * against a IClientDocument generated by the Vobject's parent IClient - * instance. - * - * @return Returns the __last_hash. - */ - public int get__last_hash() { - return __last_hash; - } - - /** - * @return true if Vobject can have a vorbaId - */ - public boolean isRegisterable() { - return registerable; - } - - /** - * Called by __testInstanceForidField and the post-unmarshalling handler - * to indicate if Vobject will have a vorbaId. - * @param registerable - */ - protected void setRegisterable(boolean registerable) { - this.registerable = registerable; - } - /** - * ensure's internal id field corresponds to vorbaId and - * cascade through all fields referring to an instance of Vobject - * calling the same method on them. - * TODO: LATER: properly apply castors own field mechanisms to get at accessors - * TODO: FIX CYCLIC __ensure+instance_ids - * Implementation note for the todo: - * this works like a depth-first search over all vamsas objects in an vamsasDocument. - * __visited is the visited flag, any Vobj who's flag is of a different parity - * to the visited argument will be recursed on. - * note - the doHash() function used to be used as the 'visited' flag - - * this *is not* a valid heuristic, although it will work "most of the time". - * TODO: LATER? Add another method for setDefaultProvenanceField (in the spirit of setInstanceIdField) using the info from the __vorba.getClient/User/Session methods - */ - protected void __ensure_instance_ids() { - __ensure_instance_ids(!__visited); - } - protected void __ensure_instance_ids(boolean visited) { - if (__vorba==null) - throw new Error("Improperly intialised org.vamsas.client.Vobject - no VorbaFactory given."); - log.debug("doing "+this.getClass()+".__ensure_instance_ids()"); - if (!__stored_in_document && registerable) - setInstanceIdField(); - if (__visited==visited) - return; - __visited=visited; - __vorba.updateHashValue(this); - - Class descriptor = null; - XMLClassDescriptorImpl descimpl = null; - try { - // castor descriptor resolver magic - descriptor = this.getClass().getClassLoader().loadClass(this.getClass().getName()+"Descriptor"); - descimpl = (XMLClassDescriptorImpl) descriptor.getConstructor((Class[])null).newInstance((Object[])null); - } catch (Exception e) { - log.fatal("Source Generation Error!: Couldn't resolve descriptor for " - +this.getClass().getName() - +" was 'generate descriptors' set for castorbuilder.properties?"); - return; - } - FieldDescriptor fields[] = descimpl.getFields(); - for (int i=0,j=fields.length; i 0) { - nobj.setVorbaId(VorbaId.newId(idstring)); - if (objrefs.containsKey(nobj_id=nobj.getVorbaId()) && !objrefs.get(nobj.getVorbaId()).equals(nobj)) { - System.err.println("Serious problem : duplicate id '"+idstring+"' found! expect badness."); - // TODO: HANDLE duplicate XML ids correctly - } - objrefs.put(nobj_id, nobj); - } else { - // add to list of objects without a valid vorbaId - obj.add(nobj); - } - } else { - // TODO: add to list of objects without a valid vorbaId - obj.add(nobj); - } - - nobj.doHash(); - // check to see if new object was present in old object hash - if (oldobjhashes.containsKey(nobj.getVorbaId())) { - Vobjhash oldhash = (Vobjhash) oldobjhashes.get(nobj.getVorbaId()); - if (oldhash.isUpdated(nobj)) { - // mark the object as updated in this document read. - nobj.set__updated_since_last_read(true); - oldobjhashes.put(nobj_id, new Vobjhash(nobj)); - updatedobjs.addElement(nobj); - } - } - } - } catch (Exception e) { - return; - }; - - } - } - - /** - * writes the VamsasDocument to the given stream. - * TODO: ensure that (at least) default provenance entries are written for objects. - * @param outstream - * @param vorba valid VorbaIdFactory to construct any missing IDs - * @param doc - * @throws IOException - * @throws MarshalException - * @throws ValidationException - */ - public static void putVamsasDocument(PrintWriter outstream, VorbaIdFactory vorba, VamsasDocument doc) - throws IOException, MarshalException, ValidationException { - // Ensure references - if (vorba==null) - throw new Error("Null VorbaIdFactory Parameter"); - if (doc.__vorba==null) - doc.__vorba = vorba; - doc.__ensure_instance_ids(); // this may take a while. Do we allow for cyclic references ? - doc.marshal(outstream); - - } - /** - * creates new VorbaId references where necessary for newly unmarshalled objects - * @param unrefed - * @param objrefs - * @return false if any new object references were made - */ - private static boolean ensure_references(Vector unrefed, Hashtable objrefs) { - boolean sync=true; - if (unrefed.size()>0) { - sync=false; // document is out of sync - ids have been created. - java.util.Iterator newobj = unrefed.listIterator(); - while (newobj.hasNext()) { - Vobject o = (Vobject) newobj.next(); - // forces registration and id field update. - VorbaId id = o.getVorbaId(); - if (!objrefs.containsKey(id)) { - objrefs.put(id, o); - } else { - if (!objrefs.get(id).equals(o)) - throw new Error("Serious! Duplicate reference made by vorbaIdFactory!"); - } - } - } - return sync; - } - /** - * Unmarshals a vamsasDocument Vobject from a stream, registers - * unregistered objects, records existing VorbaIds, and completes - * the org.vamsas.client.Vobject housekeeping fields. - * For a valid unmarshalling, the array of returned objects also includes - * a sync parameter which is true if new VorbaIds - * were created. If sync is false, then the caller should ensure that the - * vamsasDocument is written back to disk to propagate the new VorbaIds. - * TODO: ensure that provenance is correct for newly registered objects - * as getVamsasObjects but will detect updated objects based on differing hash values - * obtained from the VorbaIdFactory's VorbaId, Vobject.get__last_Hash() pairs (if any) - * @param instream - the XML input stream - * @param factory - the SimpleClient's properly configured VorbaId factory to make new references. - * @param root the root element's org.vamsas.objects.core Vobject. - * @return null or {(Object) VamsasDocument Vobject, (Object) Hashtable of Vobject references, (Object) Boolean(sync), (Object) Vector of updated objects in document } - */ - public static Object[] getVamsasObjects(Reader instream, - VorbaIdFactory factory, Vobject root) { - Unmarshaller unmarshaller = new Unmarshaller(root); - unmarshaller.setIDResolver(new IDResolver() { - public Object resolve(String id) { - VorbaXmlBinder.log.warn("Warning - id " + id - + " is not found in the Vamsas XML!"); - return null; - } - }); - final Hashtable objrefs = new Hashtable(); - if (factory.extanthashv==null) - factory.extanthashv=new Hashtable(); - final Hashtable oobjhashes=factory.extanthashv; - final VorbaIdFactory vorbafactory = factory; - final Vector unrefedObj = new Vector(); - final Vector updatedObj = new Vector(); - unmarshaller.setUnmarshalListener(new VorbaXmlBinder(vorbafactory, unrefedObj, objrefs, oobjhashes, updatedObj)); - // Call the unmarshaller. - try { - while (instream.ready()) { - // TODO: mark objects in oobjhash prior to unmarshalling, to detect when objects have been lost through an update. - //tohere - Object obj = unmarshaller.unmarshal(instream); - boolean sync=ensure_references(unrefedObj, objrefs); - if (!(obj instanceof Vobject)) - return null; - vorbafactory.setNewIdHash(objrefs); // update the Document IO Handler's set of vorbaId<>Object bindings. - return new Object[] { obj, objrefs, new Boolean(sync),updatedObj}; - } - } catch (MarshalException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ValidationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } -} \ No newline at end of file -- 1.7.10.2