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.
try {
java.lang.reflect.Field fd = thisclass.getDeclaredField("_id");
if (String.class.isAssignableFrom(fd.getType())) {
+ ___id_field=fd;
this.setRegisterable(true);
break;
}
+ 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
nobj.set__stored_in_document(true);
Field fd = null;
try {
- if (nobj.isRegisterable()) {
+ if (nobj.isRegisterable() && nobj.___id_field!=null) {
// look for the id field (should be an NCName string)
nobj.__vorba = vorbafactory;
- fd = nobj.getClass().getDeclaredField("_id");
- String idstring;
- if (fd.get(nobj) != null) {
- idstring = (String) fd.get(nobj);
+ fd = nobj.___id_field;
+ // use the Vobject accessor method to avoid unpleasant security exceptions.
+ String idstring = nobj.__getInstanceIdField();
+ if (idstring!=null) {
if (idstring.length() > 0) {
if (!objrefs.containsKey(idstring)) {
objrefs.put(idstring, nobj);
obj.add(nobj);
}
} else {
- // add to list of objects without a valid vorbaId
+ // TODO: add to list of objects without a valid vorbaId
obj.add(nobj);
}