debugged VamsasArchive and rationalised debugging messages.
[vamsas.git] / src / org / vamsas / client / object.java
index b570101..ea51068 100644 (file)
@@ -31,7 +31,7 @@ public abstract class object {
    */
   protected boolean __stored_in_document = false;
 
-  protected long __last_hash = 0;
+  protected long __last_hash = 0; // default is different so doHash always returns true initially.
 
   protected boolean registerable = false;
 
@@ -76,23 +76,20 @@ public abstract class object {
         try {
           Method fd = this.getClass().getMethod("setId", new Class[] { String.class });
           fd.invoke((Object) this, new Object[] {new String(this.getVorbaId().id)});
-          log.info(this.getClass().getName()+" called setInstanceIdField!");
+          log.debug(this.getClass().getName()+" called setInstanceIdField!");
         } catch (InvocationTargetException e) { 
-          System.err
-          .println("SourceGeneration of "
+          log.error("SourceGeneration of "
               + this.getClass().toString()
-              + "\n has resulted in an inaccessible 'setId' method!\nCannot set ID from the vorbaId object.");
-          e.printStackTrace(System.err);
+              + "\n has resulted in an inaccessible 'setId' method!\nCannot set ID from the vorbaId object.", e);
         }
         catch (IllegalAccessException e) {
-          System.err
-              .println("SourceGeneration of "
+          log.error("SourceGeneration of "
                   + this.getClass().toString()
-                  + "\n has resulted in an inaccessible 'setId' method!\nCannot set ID from the vorbaId object.");
-          e.printStackTrace(System.err);
+                  + "\n has resulted in an inaccessible 'setId' method!\nCannot set ID from the vorbaId object.", e);
         } catch (SecurityException e) {
-          e.printStackTrace(System.err);
+          log.error("Security access violation for "+this.getClass().toString(),e);
         } catch (NoSuchMethodException e) {
+          log.warn(this.getClass().toString()+" was erroneously marked as a Vorba object class (Implementation error?)");
           this.setRegisterable(false);
         }
     } else {
@@ -104,8 +101,10 @@ public abstract class object {
   /**
    * calculate a hash for the object with all housekeeping fields at standard
    * values. (isRegisterable is an immutable attribute property)
+   * @return true if new hash different to last hash
    */
-  synchronized protected void doHash() {
+  synchronized protected boolean doHash() {
+    long __old_hash = __last_hash;
     __last_hash = 0;
     VorbaId thisid = vorbaId;
     IVorbaIdFactory factory = __vorba;
@@ -116,6 +115,7 @@ public abstract class object {
     vorbaId = thisid;
     __vorba = factory;
     __stored_in_document = stored;
+    return (__old_hash==0) || (__old_hash == __last_hash);
   }
 
   /**
@@ -128,6 +128,7 @@ public abstract class object {
    * @return
    */
   protected boolean merge(object laterCopy) {
+    log.warn(this.getClass().getName()+".merge() not implemented.");
     return true;
   }
 
@@ -223,9 +224,11 @@ public abstract class object {
   protected void __ensure_instance_ids() {
     if (__vorba==null)
       throw new Error("Improperly intialised org.vamsas.client.object - no VorbaFactory given.");
-    log.info(this.getClass()+".__ensure_instance_ids()");
+    log.debug("doing "+this.getClass()+".__ensure_instance_ids()");
     if (!__stored_in_document && registerable)
       setInstanceIdField();
+    if (!doHash())
+      return; // nothing has changed in this object - probably visited it before.
     Class descriptor = null;
     XMLClassDescriptorImpl descimpl = null;
     try {
@@ -233,7 +236,9 @@ public abstract class object {
       descriptor = this.getClass().getClassLoader().loadClass(this.getClass().getName()+"Descriptor");
       descimpl = (XMLClassDescriptorImpl) descriptor.getConstructor(null).newInstance(null);
     } catch (Exception e) {
-      log.error("Couldn't resolve descriptor for "+this.getClass().getName());
+      log.fatal("Source Generation Error!: Couldn't resolve descriptor for "
+          +this.getClass().getName()
+          +" was 'generate descriptors' set for castorbuilder.properties?");
       return;
     }
     FieldDescriptor fields[] = descimpl.getFields();
@@ -280,7 +285,7 @@ public abstract class object {
                   //}
                 } else {
                   rf = (object) fval;
-                  log.info("Got value for "+fields[i].getFieldName());
+                  log.debug("Got value for "+fields[i].getFieldName());
                 }
               }
             } else {