bug fix to ensure valid and vorbaIds are generated and stored in vamsas object model
[vamsas.git] / src / org / vamsas / client / Vobject.java
index 1c7388f..d120e6c 100644 (file)
@@ -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 setInstanceVorbaIdField!");
+          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