From: jprocter Date: Tue, 12 Sep 2006 10:07:11 +0000 (+0000) Subject: bugfixed org.vamsas.test.simpleclient.ArchiveClient and made VorbaId mechanism more... X-Git-Tag: Release_0.2~281 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=705044b23ff07576f5827f68a4677eef007635fd;p=vamsas.git bugfixed org.vamsas.test.simpleclient.ArchiveClient and made VorbaId mechanism more rigorous. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@239 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/org/vamsas/client/Vobject.java b/src/org/vamsas/client/Vobject.java index e27ee86..1c7388f 100644 --- a/src/org/vamsas/client/Vobject.java +++ b/src/org/vamsas/client/Vobject.java @@ -77,25 +77,35 @@ public abstract class Vobject { * the reflected class instance. */ private void testInstanceForIdField() { - // look for the id field (should be an NCName string) // TODO: decide if 'id' is an appropriate reserved attribute name for the VorbaId - try { - java.lang.reflect.Field fd = this.getClass().getDeclaredField("_id"); - if (String.class.isAssignableFrom(fd.getType())) { - this.setRegisterable(true); + // 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())) { + 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(); } - } catch (SecurityException e) { - e.printStackTrace(); - } catch (NoSuchFieldException e) { - this.setRegisterable(false); } } - + // 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 { @@ -176,6 +186,10 @@ public abstract class Vobject { * properly instantiated VorbaIdFactory. */ public VorbaId getVorbaId() { + /*if (!registerable && !__testedInstance) { + testInstanceForIdField(); + __testedInstance=true; + }*/ if (registerable && vorbaId == null) { // Try to use the associated factory. if (__vorba != null) diff --git a/src/org/vamsas/client/VorbaId.java b/src/org/vamsas/client/VorbaId.java index c7616fb..fb87ca8 100644 --- a/src/org/vamsas/client/VorbaId.java +++ b/src/org/vamsas/client/VorbaId.java @@ -34,7 +34,8 @@ public class VorbaId { protected static VorbaId newId(IVorbaIdFactory vorbaObject, Vobject vobject) { // Make unique id from appSpace info in vorbaObject synchronized (vorbaObject) { - return vorbaObject.makeVorbaId(vobject); + vobject.vorbaId=vorbaObject.makeVorbaId(vobject); + return vobject.vorbaId; } } protected static VorbaId newId(String id) { @@ -46,4 +47,27 @@ public class VorbaId { public String getId() { return id; } + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + if (obj instanceof String) + return id.equals(obj); + else if (obj instanceof VorbaId) + return id.equals(((VorbaId)obj).id); + return false; + } + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return id.hashCode(); + } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + return id; + } + } diff --git a/src/org/vamsas/client/VorbaXmlBinder.java b/src/org/vamsas/client/VorbaXmlBinder.java index 7272c1f..0f4feb1 100644 --- a/src/org/vamsas/client/VorbaXmlBinder.java +++ b/src/org/vamsas/client/VorbaXmlBinder.java @@ -60,7 +60,7 @@ public class VorbaXmlBinder implements UnmarshalListener { public void fieldAdded(String fieldName, Object parent, Object child) { if (parent instanceof Vobject && child instanceof Vobject) { if (((Vobject) child).V_parent==null) { - System.err.println("Setting parent of "+fieldName); + // System.err.println("Setting parent of "+fieldName); ((Vobject) child).setV_parent((Vobject) parent); } } diff --git a/src/org/vamsas/client/simpleclient/SimpleDocBinding.java b/src/org/vamsas/client/simpleclient/SimpleDocBinding.java index 408e651..c0c8084 100644 --- a/src/org/vamsas/client/simpleclient/SimpleDocBinding.java +++ b/src/org/vamsas/client/simpleclient/SimpleDocBinding.java @@ -120,6 +120,8 @@ public class SimpleDocBinding { catch (Exception e) { log.warn("Failed to get document from "+oReader.jfile.getName()); }; } Vector docrefs = AppDataReference.getAppDataReferences(doc); + if (docrefs==null) + return null; Vector entries = oReader.getExtraEntries(); if (entries!=null && docrefs.size()>0) { int i=0, j=entries.size(); diff --git a/src/org/vamsas/test/simpleclient/ArchiveClient.java b/src/org/vamsas/test/simpleclient/ArchiveClient.java index da555af..f0b2e16 100644 --- a/src/org/vamsas/test/simpleclient/ArchiveClient.java +++ b/src/org/vamsas/test/simpleclient/ArchiveClient.java @@ -83,6 +83,10 @@ public class ArchiveClient extends IdFactory { if (vsess==null) throw new Error("ArchiveClient instance is invalid!."); } + /** + * set this to false if watch loop should end immediately + */ + protected boolean watchForChange=true; public static int WATCH_SLEEP=300; /** * watch the document file for updates. @@ -93,15 +97,16 @@ public class ArchiveClient extends IdFactory { valid(); vsess.unLock(); // doh. FileWatcher watcher = new FileWatcher(vsess.getVamsasFile()); + // watcher.setState(); + watchForChange=true; long endtime=System.currentTimeMillis()+time; try { org.vamsas.client.simpleclient.Lock doclock; - //watcher.setState(); do { doclock=watcher.getChangedState(); if (doclock==null) Thread.sleep(WATCH_SLEEP); - } while (doclock==null && (time==0 || endtime>System.currentTimeMillis())); // tuning. + } while (watchForChange && doclock==null && (time==0 || endtime>System.currentTimeMillis())); // tuning. if (doclock==null) return null; else { diff --git a/src/org/vamsas/test/simpleclient/ClientDoc.java b/src/org/vamsas/test/simpleclient/ClientDoc.java index cc56e8c..da05e00 100644 --- a/src/org/vamsas/test/simpleclient/ClientDoc.java +++ b/src/org/vamsas/test/simpleclient/ClientDoc.java @@ -5,6 +5,7 @@ import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.vamsas.client.IClientAppdata; import org.vamsas.client.Vobject; import org.vamsas.client.VorbaId; import org.vamsas.client.simpleclient.ClientDocument; @@ -16,7 +17,13 @@ import org.vamsas.objects.core.VamsasDocument; import org.vamsas.objects.utils.ProvenanceStuff; // simple holder to pass to client. -public class ClientDoc { +public class ClientDoc extends org.vamsas.client.ClientDocument { + /* (non-Javadoc) + * @see org.vamsas.client.IClientDocument#getClientAppdata() + */ + public IClientAppdata getClientAppdata() { + throw new Error("Appdata access is not implemented in the test.simpleclient.ClientDoc instance."); // TODO Auto-generated method stub + } protected boolean isModified=false; private Log log = LogFactory.getLog(ClientDoc.class); protected VamsasDocument doc; @@ -34,7 +41,7 @@ public class ClientDoc { * @param user */ public ClientDoc(VamsasDocument doc, VamsasArchive iohandler, VamsasArchiveReader reader, String app, String user, Hashtable objrefs) { - super(); + super(objrefs, (iohandler!=null) ? iohandler.getVorba() : null); this.doc = doc; this.iohandler = iohandler; this.reader = reader; @@ -279,14 +286,13 @@ public class ClientDoc { } if (unregistered!=null) { - VorbaId id = iohandler.getVorba().makeVorbaId(unregistered); + VorbaId id = this._registerObject(unregistered); log.debug("Registered object - total of "+objrefs.size()+" ids."); return id; } log.warn("Null Vobject passed to registerObject."); return null; } - /* * (non-Javadoc) * @@ -297,8 +303,8 @@ public class ClientDoc { log.debug("getObject called on null objrefs list."); return null; } - if (objrefs.containsKey(id)) - return (Vobject) objrefs.get(id); + if (objrefs.containsKey(id.getId())) + return (Vobject) objrefs.get(id.getId()); log.debug("Returning null Vobject reference for id "+id.getId()); return null; }