X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Forg%2Fvamsas%2Fclient%2FVobject.java;h=1c7388f2c0179eea9f9bef31883a4135497148b7;hb=705044b23ff07576f5827f68a4677eef007635fd;hp=a393b9e2991bf812c9ab54b70fe33f812d1c6363;hpb=916aba7790b0a8bf8bc10308ca366198ed44b34e;p=vamsas.git diff --git a/src/org/vamsas/client/Vobject.java b/src/org/vamsas/client/Vobject.java index a393b9e..1c7388f 100644 --- a/src/org/vamsas/client/Vobject.java +++ b/src/org/vamsas/client/Vobject.java @@ -39,7 +39,10 @@ public abstract class Vobject { */ protected boolean registerable = 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 @@ -50,6 +53,16 @@ public abstract class Vobject { * 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(); + } /** * @@ -64,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 { @@ -119,6 +142,8 @@ public abstract class Vobject { 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; @@ -128,6 +153,7 @@ public abstract class Vobject { vorbaId = thisid; __vorba = factory; __stored_in_document = stored; + V_parent=_V_parent; return (__old_hash==0) || (__old_hash == __last_hash); } @@ -160,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) @@ -270,6 +300,8 @@ public abstract class Vobject { for (int k=0, l=vals.length; k