* the reflected class instance.
*/
private void testInstanceForIdField() {
- // look for the id field (should be an NCName string)
// TODO: decide if 'id' is an appropriate reserved attribute name for the VorbaId
- try {
- java.lang.reflect.Field fd = this.getClass().getDeclaredField("_id");
- if (String.class.isAssignableFrom(fd.getType())) {
- this.setRegisterable(true);
+ // look for the id field in all castor classes (should be an NCName string)
+
+ Class thisclass=this.getClass();
+ setRegisterable(false);
+ while (!thisclass.equals(Vobject.class)) {
+ try {
+ java.lang.reflect.Field fd = thisclass.getDeclaredField("_id");
+ if (String.class.isAssignableFrom(fd.getType())) {
+ this.setRegisterable(true);
+ break;
+ }
+ } catch (SecurityException e) {
+ log.error("Unexpected Security Exception whilst finding id fields to set!",e);
+ } catch (NoSuchFieldException e) {
+ thisclass=thisclass.getSuperclass();
}
- } catch (SecurityException e) {
- e.printStackTrace();
- } catch (NoSuchFieldException e) {
- this.setRegisterable(false);
}
}
-
+ // boolean __testedInstance=false;
/**
* update the Vobject instance's _id field, based on the contents of the
* VorbaId. Only call this if you mean to do it!
*/
protected void setInstanceIdField() {
+ /*if (!registerable && !__testedInstance) {
+ testInstanceForIdField();
+ __testedInstance=true;
+ }*/
if (registerable) {
if (__vorba != null)
try {
* properly instantiated VorbaIdFactory.
*/
public VorbaId getVorbaId() {
+ /*if (!registerable && !__testedInstance) {
+ testInstanceForIdField();
+ __testedInstance=true;
+ }*/
if (registerable && vorbaId == null) {
// Try to use the associated factory.
if (__vorba != null)
protected static VorbaId newId(IVorbaIdFactory vorbaObject, Vobject vobject) {
// Make unique id from appSpace info in vorbaObject
synchronized (vorbaObject) {
- return vorbaObject.makeVorbaId(vobject);
+ vobject.vorbaId=vorbaObject.makeVorbaId(vobject);
+ return vobject.vorbaId;
}
}
protected static VorbaId newId(String id) {
public String getId() {
return id;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if (obj instanceof String)
+ return id.equals(obj);
+ else if (obj instanceof VorbaId)
+ return id.equals(((VorbaId)obj).id);
+ return false;
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ return id.hashCode();
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return id;
+ }
+
}
public void fieldAdded(String fieldName, Object parent, Object child) {
if (parent instanceof Vobject && child instanceof Vobject) {
if (((Vobject) child).V_parent==null) {
- System.err.println("Setting parent of "+fieldName);
+ // System.err.println("Setting parent of "+fieldName);
((Vobject) child).setV_parent((Vobject) parent);
}
}
catch (Exception e) { log.warn("Failed to get document from "+oReader.jfile.getName()); };
}
Vector docrefs = AppDataReference.getAppDataReferences(doc);
+ if (docrefs==null)
+ return null;
Vector entries = oReader.getExtraEntries();
if (entries!=null && docrefs.size()>0) {
int i=0, j=entries.size();
if (vsess==null)
throw new Error("ArchiveClient instance is invalid!.");
}
+ /**
+ * set this to false if watch loop should end immediately
+ */
+ protected boolean watchForChange=true;
public static int WATCH_SLEEP=300;
/**
* watch the document file for updates.
valid();
vsess.unLock(); // doh.
FileWatcher watcher = new FileWatcher(vsess.getVamsasFile());
+ // watcher.setState();
+ watchForChange=true;
long endtime=System.currentTimeMillis()+time;
try {
org.vamsas.client.simpleclient.Lock doclock;
- //watcher.setState();
do {
doclock=watcher.getChangedState();
if (doclock==null)
Thread.sleep(WATCH_SLEEP);
- } while (doclock==null && (time==0 || endtime>System.currentTimeMillis())); // tuning.
+ } while (watchForChange && doclock==null && (time==0 || endtime>System.currentTimeMillis())); // tuning.
if (doclock==null)
return null;
else {
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.vamsas.client.IClientAppdata;
import org.vamsas.client.Vobject;
import org.vamsas.client.VorbaId;
import org.vamsas.client.simpleclient.ClientDocument;
import org.vamsas.objects.utils.ProvenanceStuff;
// simple holder to pass to client.
-public class ClientDoc {
+public class ClientDoc extends org.vamsas.client.ClientDocument {
+ /* (non-Javadoc)
+ * @see org.vamsas.client.IClientDocument#getClientAppdata()
+ */
+ public IClientAppdata getClientAppdata() {
+ throw new Error("Appdata access is not implemented in the test.simpleclient.ClientDoc instance."); // TODO Auto-generated method stub
+ }
protected boolean isModified=false;
private Log log = LogFactory.getLog(ClientDoc.class);
protected VamsasDocument doc;
* @param user
*/
public ClientDoc(VamsasDocument doc, VamsasArchive iohandler, VamsasArchiveReader reader, String app, String user, Hashtable objrefs) {
- super();
+ super(objrefs, (iohandler!=null) ? iohandler.getVorba() : null);
this.doc = doc;
this.iohandler = iohandler;
this.reader = reader;
}
if (unregistered!=null) {
- VorbaId id = iohandler.getVorba().makeVorbaId(unregistered);
+ VorbaId id = this._registerObject(unregistered);
log.debug("Registered object - total of "+objrefs.size()+" ids.");
return id;
}
log.warn("Null Vobject passed to registerObject.");
return null;
}
-
/*
* (non-Javadoc)
*
log.debug("getObject called on null objrefs list.");
return null;
}
- if (objrefs.containsKey(id))
- return (Vobject) objrefs.get(id);
+ if (objrefs.containsKey(id.getId()))
+ return (Vobject) objrefs.get(id.getId());
log.debug("Returning null Vobject reference for id "+id.getId());
return null;
}