import java.io.File;
import java.io.IOException;
import java.util.Date;
+import java.util.Hashtable;
import java.util.Vector;
import org.apache.commons.logging.Log;
import org.vamsas.client.IVorbaIdFactory;
import org.vamsas.client.SessionHandle;
import org.vamsas.client.UserHandle;
+import org.vamsas.client.Vobject;
+import org.vamsas.client.VorbaId;
import org.vamsas.client.simpleclient.AppDataOutputStream;
import org.vamsas.client.simpleclient.FileWatcher;
import org.vamsas.client.simpleclient.IdFactory;
d = docb.getVamsasDocument(vreader);
if (d!=null) {
- ClientDoc creader = new ClientDoc(d, null, vreader, getProvenanceUser());
+ ClientDoc creader = new ClientDoc(d, null, vreader, getProvenanceUser(), getVorbaIdHash());
return creader;
}
}
varc.cancelArchive();
return null;
}
- ClientDoc cdoc = new ClientDoc(d, varc, varc.getOriginalArchiveReader(), getProvenanceUser());
+ ClientDoc cdoc = new ClientDoc(d, varc, varc.getOriginalArchiveReader(), getProvenanceUser(), getVorbaIdHash());
return cdoc;
// do appHandle?
} catch (Exception e) {
}
System.out.println("Finished at "+new Date());
}
-
+ public org.vamsas.client.Vobject getObject(VorbaId id) {
+ Hashtable idhash = this.getVorbaIdHash();
+ if (idhash!=null && idhash.containsKey(id))
+ return (Vobject) idhash.get(id);
+ return null;
+ }
}
package org.vamsas.test.simpleclient;
+import java.util.Hashtable;
import java.util.Vector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.vamsas.client.Vobject;
import org.vamsas.client.VorbaId;
import org.vamsas.client.simpleclient.ClientDocument;
import org.vamsas.client.simpleclient.VamsasArchive;
* @param reader
* @param user
*/
- public ClientDoc(VamsasDocument doc, VamsasArchive iohandler, VamsasArchiveReader reader, String user) {
+ public ClientDoc(VamsasDocument doc, VamsasArchive iohandler, VamsasArchiveReader reader, String user, Hashtable objrefs) {
super();
this.doc = doc;
this.iohandler = iohandler;
this.reader = reader;
this.user = user;
+ this.objrefs = objrefs;
_VamsasRoots = doc.getVAMSAS();
}
// AppDataOutputStream appd;
// iohandler.cancelArchive(); // otherwise the original may be overwritten.
// }
}
+ private java.util.Hashtable objrefs=null;
+
+ public VorbaId[] registerObjects(Vobject[] unregistered) {
+ if (doc==null) {
+ log.warn("registerObjects[] called on null document.");
+ return null;
+ }
+ if (objrefs==null) {
+ log.warn("registerObjects[] called for null objrefs hasharray.");
+ return null;
+ }
+ if (unregistered!=null) {
+ VorbaId ids[] = new VorbaId[unregistered.length];
+ for (int i=0,k=unregistered.length; i<k; i++)
+ if (unregistered[i]!=null) {
+ log.warn("Null Vobject passed to registerObject[] at position "+i);
+ return null;
+ } else {
+ ids[i]=registerObject(unregistered[i]);
+ }
+ log.debug("Registered "+unregistered.length+" objects - total of "+objrefs.size()+" ids.");
+ return ids;
+ }
+ return null;
+ }
+ /* (non-Javadoc)
+ * @see org.vamsas.client.IClientDocument#registerObject(org.vamsas.client.Vobject)
+ */
+ public VorbaId registerObject(Vobject unregistered) {
+ if (doc==null) {
+ log.warn("registerObjects called on null document.");
+ return null;
+ }
+ if (objrefs==null) {
+ log.warn("registerObjects called for null objrefs hasharray.");
+ return null;
+ }
+ if (iohandler==null) {
+ log.warn("registerObjects called for read only document.");
+ return null;
+ }
+
+ if (unregistered!=null) {
+ VorbaId id = iohandler.getVorba().makeVorbaId(unregistered);
+ log.debug("Registered object - total of "+objrefs.size()+" ids.");
+ return id;
+ }
+ log.warn("Null Vobject passed to registerObject.");
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.vamsas.client.IClientDocument#getObject(org.vamsas.client.VorbaId)
+ */
+ public Vobject getObject(VorbaId id) {
+ if (objrefs==null) {
+ log.debug("getObject called on null objrefs list.");
+ return null;
+ }
+ if (objrefs.containsKey(id))
+ return (Vobject) objrefs.get(id);
+ log.debug("Returning null Vobject reference for id "+id.getId());
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.vamsas.client.IClientDocument#getObjects(org.vamsas.client.VorbaId[])
+ */
+ public Vobject[] getObjects(VorbaId[] ids) {
+ if (objrefs==null) {
+ log.debug("getObject[] called on null objrefs list.");
+ return null;
+ }
+ Vobject[] vo = new Vobject[ids.length];
+ for (int i=0,j=ids.length; i<j;i++)
+ if (objrefs.containsKey(ids[i]))
+ vo[i] = (Vobject) objrefs.get(ids[i]);
+ else
+ log.debug("Returning null Vobject reference for id "+ids[i].getId());
+ return vo;
+ }
}
\ No newline at end of file