X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Forg%2Fvamsas%2Fclient%2FVobject.java;h=589b7ffb6acd6d95b620825ede675a25b4e1742c;hb=39e28eac9d274805d5b0bdc9f28583c16f65d50e;hp=1c7388f2c0179eea9f9bef31883a4135497148b7;hpb=705044b23ff07576f5827f68a4677eef007635fd;p=vamsas.git diff --git a/src/org/vamsas/client/Vobject.java b/src/org/vamsas/client/Vobject.java index 1c7388f..589b7ff 100644 --- a/src/org/vamsas/client/Vobject.java +++ b/src/org/vamsas/client/Vobject.java @@ -71,7 +71,7 @@ public abstract class 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. @@ -86,6 +86,7 @@ public abstract class Vobject { try { java.lang.reflect.Field fd = thisclass.getDeclaredField("_id"); if (String.class.isAssignableFrom(fd.getType())) { + ___id_field=fd; this.setRegisterable(true); break; } @@ -132,6 +133,43 @@ public abstract class Vobject { + 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 @@ -186,11 +224,11 @@ public abstract class Vobject { * properly instantiated VorbaIdFactory. */ public VorbaId getVorbaId() { - /*if (!registerable && !__testedInstance) { - testInstanceForIdField(); - __testedInstance=true; - }*/ 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)