X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fuk%2Fac%2Fvamsas%2Fclient%2FVobject.java;h=6603f1a8756ef829d5ed867cb2b0b63e7d317a7f;hb=0e95b1e51ee83557e26b520c7b10ea172fbd0a43;hp=8e9fc5199993391f8482cf1aa295d26a7ff0c49e;hpb=4b707f884b9300b927dba2fbfccfe2694eef7894;p=vamsas.git diff --git a/src/uk/ac/vamsas/client/Vobject.java b/src/uk/ac/vamsas/client/Vobject.java index 8e9fc51..6603f1a 100644 --- a/src/uk/ac/vamsas/client/Vobject.java +++ b/src/uk/ac/vamsas/client/Vobject.java @@ -80,6 +80,12 @@ public abstract class Vobject { super(); testInstanceForIdField(); } + /** + * Override Object.hashCode with base value for castor generated object hashcodes. + */ + public int hashCode() { + return 17; + } 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 @@ -179,7 +185,36 @@ public abstract class Vobject { } return null; } - + /** + * calls the castor-generated hashCode() method + * @return + */ + protected int __callHash() { + try { + Method fd = this.getClass().getMethod("hashCode", (Class[]) null); + Object hashvalue = fd.invoke((Object) this, (Object[]) null); + if (log.isDebugEnabled()) + log.debug(this.getClass().getName()+" called hashCode()!"); + if (hashvalue!=null && hashvalue instanceof Integer) { + return ((Integer) hashvalue).intValue(); + } + } catch (InvocationTargetException e) { + log.error("SourceGeneration of " + + this.getClass().toString() + + "\n has resulted in an inaccessible 'hashCode' method!\nHave you set org.exolab.castor.builder.equalsmethod=true in castorbuilder.properties ?.", e); + } + catch (IllegalAccessException e) { + log.error("SourceGeneration of " + + this.getClass().toString() + + "\n has resulted in an inaccessible 'hashCode' method!\nHave you set org.exolab.castor.builder.equalsmethod=true in castorbuilder.properties ?.", e); + } catch (SecurityException e) { + log.error("Security access violation for "+this.getClass().toString(),e); + } catch (NoSuchMethodException e) { + log.warn(this.getClass().toString()+" was erroneously extending from a Vorba Vobject class (Implementation error? no hashCode() method)" + + "\nHave you set org.exolab.castor.builder.equalsmethod=true in castorbuilder.properties ?.", e); + } + return 0; + } /** * calculate a hash for the Vobject with all housekeeping fields at standard * values. (isRegisterable is an immutable attribute property) @@ -187,28 +222,29 @@ public abstract class Vobject { * @return true if new hash different to last hash (or first time its been computed) */ synchronized protected boolean doHash() { + boolean stored = __stored_in_document; + __stored_in_document=false; + boolean updated = __updated_since_last_read; + __updated_since_last_read=false; + boolean added_since=__added_since_last_read; + __added_since_last_read=false; long __old_hash = __last_hash; __last_hash = 0; + // leave registerable - doesn't change + boolean visited = __visited; + __visited=false; Vobject _V_parent=V_parent; V_parent=null; VorbaId thisid = vorbaId; + vorbaId = null; IVorbaIdFactory factory = __vorba; - boolean stored = __stored_in_document; - boolean updated = __updated_since_last_read; - boolean visited = __visited; + __vorba = null; java.lang.reflect.Field idfield = ___id_field; ___id_field=null; - __updated_since_last_read=false; - __stored_in_document=false; - boolean added_since=__added_since_last_read; - __added_since_last_read=false; long l_hash = __l_hash; __l_hash = 0; - vorbaId = null; - __vorba = null; - __visited=false; // compute hash - __last_hash = this.hashCode(); + __last_hash = __callHash(); // reset houseskeeping variables ___id_field=idfield; vorbaId = thisid; @@ -317,6 +353,8 @@ public abstract class Vobject { */ protected void set__stored_in_document(boolean __stored_in_document) { this.__stored_in_document = __stored_in_document; + if(__stored_in_document && log.isDebugEnabled()) + log.debug("Retrieved document object: "+this.getVorbaId()); } /** @@ -324,6 +362,9 @@ public abstract class Vobject { */ protected void set__added_since_last_read(boolean __added_since_last_read) { this.__added_since_last_read = __added_since_last_read; + + if(__added_since_last_read && log.isDebugEnabled()) + log.debug("New object in document: "+this.getVorbaId()); } /** @@ -333,7 +374,7 @@ public abstract class Vobject { * * @return Returns the __last_hash. */ - public int get__last_hash() { + public long get__last_hash() { return __last_hash; } @@ -384,7 +425,10 @@ public abstract class Vobject { XMLClassDescriptorImpl descimpl = null; try { // castor descriptor resolver magic - descriptor = this.getClass().getClassLoader().loadClass(this.getClass().getName()+"Descriptor"); + StringBuffer desname = new StringBuffer(this.getClass().getName()); + desname.insert(desname.lastIndexOf("."), ".descriptors"); + desname.append("Descriptor"); + descriptor = this.getClass().getClassLoader().loadClass(desname.toString()); descimpl = (XMLClassDescriptorImpl) descriptor.getConstructor((Class[])null).newInstance((Object[])null); } catch (Exception e) { log.fatal("Source Generation Error!: Couldn't resolve descriptor for "