+++ /dev/null
-/*
- * Created on 15-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 java.beans.EventHandler;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-import java.lang.reflect.Field;
-import java.util.Hashtable;
-import java.util.Vector;
-
-import org.exolab.castor.xml.IDResolver;
-import org.exolab.castor.xml.MarshalException;
-import org.exolab.castor.xml.Marshaller;
-import org.exolab.castor.xml.UnmarshalListener;
-import org.exolab.castor.xml.Unmarshaller;
-import org.exolab.castor.xml.ValidationException;
-import org.vamsas.objects.core.VamsasDocument;
-
-/**
- * @author jimp
- */
-public class SimpleClient implements IClient {
-
- UserHandle user = null;
-
- SessionHandle session = null;
-
- ClientHandle client = null;
-
- /*
- * (non-Javadoc)
- * TODO: check that build substitution variables are correct
- * @see org.vamsas.client.IClient#getAbout()
- */
- public String getAbout() {
- return new String("VORBA SimpleClient version $version$ build $build$");
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.vamsas.client.IClient#getSessionUrn()
- */
- public String getSessionUrn() {
- return session.getSessionUrn();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.vamsas.client.IClient#getSessionHandle()
- */
- public SessionHandle getSessionHandle() {
- return session;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.vamsas.client.IClient#getClientHandle()
- */
- public ClientHandle getClientHandle() {
- return client;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.vamsas.client.IClient#getUserHandle()
- */
- public UserHandle getUserHandle() {
- return user;
- }
-
- private Hashtable handlers = initHandlers();
-
- private Vector listeners = new Vector();
-
- /**
- * make all the PropertyChangeSupport objects for the
- * events described in org.vamsas.client.Event
- * @return
- */
- private static Hashtable initHandlers() {
- Hashtable events = new Hashtable();
- java.util.Iterator evt = Events.EventList.iterator();
- while (evt.hasNext()) {
- Object ths = evt.next();
- events.put(ths, (Object) new PropertyChangeSupport(ths));
- }
- return events;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.vamsas.client.IClient#addDocumentUpdateHandler(java.util.EventListener)
- */
- public void addDocumentUpdateHandler(PropertyChangeListener evt) {
- if (handlers.containsKey(Events.DOCUMENT_UPDATE)) {
- Object handler;
- ((PropertyChangeSupport) (handler = handlers.get(Events.DOCUMENT_UPDATE)))
- .addPropertyChangeListener(evt);
- listeners.add(handler);
- listeners.add((Object) evt);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.vamsas.client.IClient#finalizeClient()
- */
- public void finalizeClient() {
- // TODO: determine if this is last client in session
- // TODO: raise events like : ((lst_client && document.request.to.close), (client_finalization), (
-
- // if (handlers.containsKey(Events.))
- // if (handlers.containsKey(Events.CLIENT_FINALIZATION))
- // deregister listeners.
- // mark this instance as finalized
- }
-
- /**
- * writes the VamsasDocument to the given stream.
- * TODO: ensure that (at least) default provenance entries are written for objects.
- * @param outstream
- * @param doc
- * @throws IOException
- * @throws MarshalException
- * @throws ValidationException
- */
- private static void setVamsasDocument(Writer outstream, VamsasDocument doc)
- throws IOException, MarshalException, ValidationException {
- Marshaller marshaller = new Marshaller(outstream);
- marshaller.marshal(doc);
- }
-
- /**
- * Unmarshals a vamsasDocument object from a stream, registers
- * unregistered objects, records existing VorbaIds, and completes
- * the org.vamsas.client.object housekeeping fields.
- * For a valid unmarshalling, the array of returned objects also includes
- * a <return>sync</return> 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
- * @param instream - the XML input stream
- * @param factory - the SimpleClient's properly configured VorbaId factory to make new references.
- * @return null or {(Object) VamsasDocument object, (Object) Hashtable of object references, (Object) Boolean(sync) }
- */
-private static Object[] getVamsasDocument(Reader instream,
- IVorbaIdFactory factory) {
- Unmarshaller unmarshaller = new Unmarshaller(instream);
- unmarshaller.setIDResolver(new IDResolver() {
- public Object resolve(String id) {
- System.err.println("Warning - id " + id
- + " is not found in the VamsasDocument!");
- return null;
- }
- });
- Hashtable refbase = new Hashtable();
- Vector unrefed = new Vector();
- final Hashtable objrefs = refbase;
- final IVorbaIdFactory vorbafactory = factory;
- final Vector unrefedObj = unrefed;
- unmarshaller.setUnmarshalListener(new UnmarshalListener() {
-
- /*
- * (non-Javadoc)
- *
- * @see org.exolab.castor.xml.UnmarshalListener#attributesProcessed(java.lang.Object)
- */
- public void attributesProcessed(Object object) {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.exolab.castor.xml.UnmarshalListener#fieldAdded(java.lang.String,
- * java.lang.Object, java.lang.Object)
- */
- public void fieldAdded(String fieldName, Object parent, Object child) {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.exolab.castor.xml.UnmarshalListener#initialized(java.lang.Object)
- */
- public void initialized(Object object) {
- }
-
- /*
- * Check if the object has an 'id' field - if it does, copy the value into
- * the VorbaId field of object, and add the object to the VorbaId hash.
- *
- * @see org.exolab.castor.xml.UnmarshalListener#unmarshalled(java.lang.Object)
- */
- public void unmarshalled(Object newobj) {
- if (newobj instanceof object) {
- object nobj = (object) newobj;
- nobj.set__stored_in_document(true);
- Field fd = null;
- try {
- if (nobj.isRegisterable()) {
- // look for the id field (should be an NCName string)
- nobj.__vorba = vorbafactory;
- fd = nobj.getClass().getField("id");
- String idstring;
- if (fd.get(nobj) != null) {
- idstring = (String) fd.get(nobj);
- if (idstring.length() > 0) {
- if (!objrefs.containsKey(idstring)) {
- objrefs.put(idstring, nobj);
- nobj.setVorbaId(VorbaId.newId(idstring));
- } else {
- System.err.println("Serious problem : duplicate id '"+idstring+"' found! expect badness.");
- // TODO: HANDLE duplicate XML ids correctly
- }
- } else {
- // add to list of objects without a valid vorbaId
- unrefedObj.add(nobj);
- }
- } else {
- // add to list of objects without a valid vorbaId
- unrefedObj.add(nobj);
- }
-
- nobj.doHash();
- }
- } catch (Exception e) {
- return;
- };
-
- }
- }
-
- });
- // Call the unmarshaller.
- try {
- while (instream.ready()) {
- Object obj = unmarshaller.unmarshal(instream);
- boolean sync=true;
- if (obj instanceof VamsasDocument) {
- if (unrefed.size()>0) {
- sync=false; // document is out of sync - ids have been created.
- java.util.Iterator newobj = unrefed.listIterator();
- while (newobj.hasNext()) {
- object o = (object) newobj.next();
- // forces registration and id field update.
- VorbaId id = o.getVorbaId();
- if (!objrefs.containsKey(id)) {
- objrefs.put(id.id, o);
- } else {
- throw new Error("Serious! Duplicate reference made by vorbaIdFactory!");
- }
- }
- }
- return new Object[] { obj, objrefs, new Boolean(sync)};
- }
- }
- } 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;
- }
- /**
- * extract data appropriate for client, session and user
- * from vamsas document.
- * @return application's byte array
- */
- private byte[] getApplicationData() {
- // TODO: extract correct byte object from Jar and return it to application.
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.vamsas.client.IClient#getClientDocument()
- */
- public IClientDocument getClientDocument() {
- Object[] vdoc;// TODO: = getVamsasDocument(new Reader());
- // ClientDocument cdoc = new ClientDocument(getApplicationData(),
- // ((VamsasDocument) vdoc[0]).getVAMSAS(), (Hashtable) vdoc[1], this);
- //
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.vamsas.client.IClient#updateDocument(org.vamsas.client.IClientDocument)
- */
- public void updateDocument(IClientDocument newdoc) {
- // TODO Auto-generated method stub
- //
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.vamsas.client.IClient#storeDocument(java.io.File)
- */
- public void storeDocument(File location) {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.vamsas.client.IClient#addVorbaEventHandler(java.lang.String,
- * java.beans.PropertyChangeListener)
- */
- public void addVorbaEventHandler(String EventChain, PropertyChangeListener evt) {
- if (handlers.containsKey(EventChain)) {
- Object handler;
- ((PropertyChangeSupport) (handler = handlers.get(EventChain)))
- .addPropertyChangeListener(evt);
- listeners.add(handler);
- listeners.add((Object) evt);
- }
- }
-
- /* (non-Javadoc)
- * @see org.vamsas.client.IClient#pollUpdate()
- */
- public void pollUpdate() {
- // TODO wake up UpdateWatcher thread to check for updates.
-
- }
-
- public static void main(String[] args) {
- }
-
- /* (non-Javadoc)
- * @see org.vamsas.client.IClient#joinSession()
- */
- public void joinSession() throws Exception {
- // TODO Auto-generated method stub
-
- }
-}
--- /dev/null
+/**
+ *
+ */
+package org.vamsas.client;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.lang.reflect.Field;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.exolab.castor.xml.IDResolver;
+import org.exolab.castor.xml.MarshalException;
+import org.exolab.castor.xml.Marshaller;
+import org.exolab.castor.xml.UnmarshalListener;
+import org.exolab.castor.xml.Unmarshaller;
+import org.exolab.castor.xml.ValidationException;
+import org.vamsas.objects.core.VamsasDocument;
+/**
+ * Implements the Vamsas object ID machinery for translating
+ * between non-volatile XML IDs and object references. Use the
+ * marshalling and unmarshalling methods in this class in order
+ * to avoid validation exceptions when marshalling new objects
+ * into the vamsas document.
+ */
+public class VorbaXmlBinder implements UnmarshalListener {
+ private final IVorbaIdFactory vorbafactory;
+
+ private final Vector obj;
+
+ private final Hashtable objrefs;
+
+ public VorbaXmlBinder(IVorbaIdFactory vorbafactory, Vector obj, Hashtable objrefs) {
+ this.vorbafactory = vorbafactory;
+ this.obj = obj;
+ this.objrefs = objrefs;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.exolab.castor.xml.UnmarshalListener#attributesProcessed(java.lang.Object)
+ */
+ public void attributesProcessed(Object object) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.exolab.castor.xml.UnmarshalListener#fieldAdded(java.lang.String,
+ * java.lang.Object, java.lang.Object)
+ */
+ public void fieldAdded(String fieldName, Object parent, Object child) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.exolab.castor.xml.UnmarshalListener#initialized(java.lang.Object)
+ */
+ public void initialized(Object object) {
+ }
+
+ /*
+ * Check if the object has an 'id' field - if it does, copy the value into
+ * the VorbaId field of object, and add the object to the VorbaId hash.
+ *
+ * @see org.exolab.castor.xml.UnmarshalListener#unmarshalled(java.lang.Object)
+ */
+ public void unmarshalled(Object newobj) {
+ if (newobj instanceof object) {
+ object nobj = (object) newobj;
+ nobj.set__stored_in_document(true);
+ Field fd = null;
+ try {
+ if (nobj.isRegisterable()) {
+ // look for the id field (should be an NCName string)
+ nobj.__vorba = vorbafactory;
+ fd = nobj.getClass().getField("id");
+ String idstring;
+ if (fd.get(nobj) != null) {
+ idstring = (String) fd.get(nobj);
+ if (idstring.length() > 0) {
+ if (!objrefs.containsKey(idstring)) {
+ objrefs.put(idstring, nobj);
+ nobj.setVorbaId(VorbaId.newId(idstring));
+ } else {
+ System.err.println("Serious problem : duplicate id '"+idstring+"' found! expect badness.");
+ // TODO: HANDLE duplicate XML ids correctly
+ }
+ } else {
+ // add to list of objects without a valid vorbaId
+ obj.add(nobj);
+ }
+ } else {
+ // add to list of objects without a valid vorbaId
+ obj.add(nobj);
+ }
+
+ nobj.doHash();
+ }
+ } 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 doc
+ * @throws IOException
+ * @throws MarshalException
+ * @throws ValidationException
+ */
+ private static void setVamsasDocument(Writer outstream, VamsasDocument doc)
+ throws IOException, MarshalException, ValidationException {
+ Marshaller marshaller = new Marshaller(outstream);
+ marshaller.marshal(doc);
+ }
+
+ /**
+ * Unmarshals a vamsasDocument object from a stream, registers
+ * unregistered objects, records existing VorbaIds, and completes
+ * the org.vamsas.client.object housekeeping fields.
+ * For a valid unmarshalling, the array of returned objects also includes
+ * a <return>sync</return> 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
+ * @param instream - the XML input stream
+ * @param factory - the SimpleClient's properly configured VorbaId factory to make new references.
+ * @return null or {(Object) VamsasDocument object, (Object) Hashtable of object references, (Object) Boolean(sync) }
+ */
+ public static Object[] getVamsasDocument(Reader instream,
+ IVorbaIdFactory factory) {
+ Unmarshaller unmarshaller = new Unmarshaller(instream);
+ unmarshaller.setIDResolver(new IDResolver() {
+ public Object resolve(String id) {
+ System.err.println("Warning - id " + id
+ + " is not found in the VamsasDocument!");
+ return null;
+ }
+ });
+ Hashtable refbase = new Hashtable();
+ Vector unrefed = new Vector();
+ final Hashtable objrefs = refbase;
+ final IVorbaIdFactory vorbafactory = factory;
+ final Vector unrefedObj = unrefed;
+ unmarshaller.setUnmarshalListener(new VorbaXmlBinder(vorbafactory, unrefedObj, objrefs));
+ // Call the unmarshaller.
+ try {
+ while (instream.ready()) {
+ Object obj = unmarshaller.unmarshal(instream);
+ boolean sync=true;
+ if (obj instanceof VamsasDocument) {
+ if (unrefed.size()>0) {
+ sync=false; // document is out of sync - ids have been created.
+ java.util.Iterator newobj = unrefed.listIterator();
+ while (newobj.hasNext()) {
+ object o = (object) newobj.next();
+ // forces registration and id field update.
+ VorbaId id = o.getVorbaId();
+ if (!objrefs.containsKey(id)) {
+ objrefs.put(id.id, o);
+ } else {
+ throw new Error("Serious! Duplicate reference made by vorbaIdFactory!");
+ }
+ }
+ }
+ return new Object[] { obj, objrefs, new Boolean(sync)};
+ }
+ }
+ } 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
import java.io.File;
-import org.vamsas.client.SimpleClient;
/**
* @author jim Watches a particular file for its creation, deletion, or
--- /dev/null
+/*
+ * Created on 15-Sep-2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.vamsas.client.simpleclient;
+
+import java.beans.EventHandler;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.BufferedReader;
+import java.io.File;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.vamsas.client.ClientHandle;
+import org.vamsas.client.Events;
+import org.vamsas.client.IClient;
+import org.vamsas.client.IClientDocument;
+import org.vamsas.client.SessionHandle;
+import org.vamsas.client.UserHandle;
+
+/**
+ * @author jimp
+ */
+public class SimpleClient implements IClient {
+
+ UserHandle user = null;
+
+ SessionHandle session = null;
+
+ ClientHandle client = null;
+
+ /*
+ * (non-Javadoc)
+ * TODO: check that build substitution variables are correct
+ * @see org.vamsas.client.IClient#getAbout()
+ */
+ public String getAbout() {
+ return new String("VORBA SimpleClient version $version$ build $build$");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.vamsas.client.IClient#getSessionUrn()
+ */
+ public String getSessionUrn() {
+ return session.getSessionUrn();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.vamsas.client.IClient#getSessionHandle()
+ */
+ public SessionHandle getSessionHandle() {
+ return session;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.vamsas.client.IClient#getClientHandle()
+ */
+ public ClientHandle getClientHandle() {
+ return client;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.vamsas.client.IClient#getUserHandle()
+ */
+ public UserHandle getUserHandle() {
+ return user;
+ }
+
+ private Hashtable handlers = initHandlers();
+
+ private Vector listeners = new Vector();
+
+ /**
+ * make all the PropertyChangeSupport objects for the
+ * events described in org.vamsas.client.Event
+ * @return
+ */
+ private static Hashtable initHandlers() {
+ Hashtable events = new Hashtable();
+ java.util.Iterator evt = Events.EventList.iterator();
+ while (evt.hasNext()) {
+ Object ths = evt.next();
+ events.put(ths, (Object) new PropertyChangeSupport(ths));
+ }
+ return events;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.vamsas.client.IClient#addDocumentUpdateHandler(java.util.EventListener)
+ */
+ public void addDocumentUpdateHandler(PropertyChangeListener evt) {
+ if (handlers.containsKey(Events.DOCUMENT_UPDATE)) {
+ Object handler;
+ ((PropertyChangeSupport) (handler = handlers.get(Events.DOCUMENT_UPDATE)))
+ .addPropertyChangeListener(evt);
+ listeners.add(handler);
+ listeners.add((Object) evt);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.vamsas.client.IClient#finalizeClient()
+ */
+ public void finalizeClient() {
+ // TODO: determine if this is last client in session
+ // TODO: raise events like : ((lst_client && document.request.to.close), (client_finalization), (
+
+ // if (handlers.containsKey(Events.))
+ // if (handlers.containsKey(Events.CLIENT_FINALIZATION))
+ // deregister listeners.
+ // mark this instance as finalized
+ }
+
+ /**
+ * extract data appropriate for client, session and user
+ * from vamsas document.
+ * @return application's byte array
+ */
+ private byte[] getApplicationData() {
+ // TODO: extract correct byte object from Jar and return it to application.
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.vamsas.client.IClient#getClientDocument()
+ */
+ public IClientDocument getClientDocument() {
+ Object[] vdoc;// TODO: = getVamsasDocument(new Reader());
+ // ClientDocument cdoc = new ClientDocument(getApplicationData(),
+ // ((VamsasDocument) vdoc[0]).getVAMSAS(), (Hashtable) vdoc[1], this);
+ //
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.vamsas.client.IClient#updateDocument(org.vamsas.client.IClientDocument)
+ */
+ public void updateDocument(IClientDocument newdoc) {
+ // TODO Auto-generated method stub
+ //
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.vamsas.client.IClient#storeDocument(java.io.File)
+ */
+ public void storeDocument(File location) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.vamsas.client.IClient#addVorbaEventHandler(java.lang.String,
+ * java.beans.PropertyChangeListener)
+ */
+ public void addVorbaEventHandler(String EventChain, PropertyChangeListener evt) {
+ if (handlers.containsKey(EventChain)) {
+ Object handler;
+ ((PropertyChangeSupport) (handler = handlers.get(EventChain)))
+ .addPropertyChangeListener(evt);
+ listeners.add(handler);
+ listeners.add((Object) evt);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.vamsas.client.IClient#pollUpdate()
+ */
+ public void pollUpdate() {
+ // TODO wake up UpdateWatcher thread to check for updates.
+
+ }
+
+ public static void main(String[] args) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.vamsas.client.IClient#joinSession()
+ */
+ public void joinSession() throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+}
-package org.vamsas.client;
+package org.vamsas.client.simpleclient;
import java.io.File;
import java.io.IOException;
+import org.vamsas.client.ClientHandle;
+import org.vamsas.client.IClient;
+import org.vamsas.client.IClientFactory;
+import org.vamsas.client.UserHandle;
+
/**
* TODO document type SimpleClientFactory
* @author jimp
// get IClientFactory
try {
- clientfactory = new org.vamsas.client.SimpleClientFactory(args[0]);
+ clientfactory = new org.vamsas.client.simpleclient.SimpleClientFactory(args[0]);
} catch (IOException e) {
System.err.println(e+"\n"+Usage);
System.exit(1);
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.vamsas.client.SimpleClient;
import org.vamsas.client.simpleclient.*;
import org.vamsas.objects.core.AppDataChoice;
import org.vamsas.objects.core.ApplicationData;