import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.ValidationException;
+import uk.ac.vamsas.client.utils.ChecksummedReader;
import uk.ac.vamsas.objects.core.VamsasDocument;
/**
* Implements the Vamsas Vobject ID machinery for translating
private final Vector obj;
private final Hashtable oldobjhashes;
private final Hashtable objrefs;
- private final Vector updatedobjs;
-
+ private final Vector updatedobjs; // not yet used elswhere ?
+ private final ChecksummedReader inStream;
public VorbaXmlBinder(IVorbaIdFactory vorbafactory, Vector obj, Hashtable objrefs, Hashtable oldobjhashes, Vector updatedobjs) {
- this.vorbafactory = vorbafactory;
- this.obj = obj;
- this.objrefs = objrefs;
+ this(vorbafactory, obj, objrefs, oldobjhashes, updatedobjs, null);
+
+ }
+
+ public VorbaXmlBinder(IVorbaIdFactory vorbafactory2, Vector unrefedObj, Hashtable objrefs2, Hashtable oldobjhashes, Vector updatedObj, ChecksummedReader ckedInstream) {
+ this.inStream = ckedInstream;
+ this.vorbafactory = vorbafactory2;
+ this.obj = unrefedObj;
+ this.objrefs = objrefs2;
this.oldobjhashes = oldobjhashes;
- this.updatedobjs = updatedobjs;
+ this.updatedobjs = updatedObj;
}
/*
* @see org.exolab.castor.xml.UnmarshalListener#attributesProcessed(java.lang.Object)
*/
public void attributesProcessed(Object object) {
+
}
/*
* @see org.exolab.castor.xml.UnmarshalListener#initialized(java.lang.Object)
*/
public void initialized(Object object) {
+ if (object instanceof Vobject) {
+ Vobject nobj = (Vobject) object;
+ if (nobj.isRegisterable() && nobj.___id_field!=null && inStream!=null)
+ nobj.__setInitHash(inStream.getChecksum()); // record start tag position
+ }
}
/*
nobj.set__stored_in_document(true);
try {
if (nobj.isRegisterable() && nobj.___id_field!=null) {
+ if (inStream!=null)
+ nobj.__setFinalHash(inStream.getChecksum()); // compute LHash as difference between end and start tag positions
VorbaId nobj_id=null;
// look for the id field (should be an NCName string)
nobj.__vorba = vorbafactory;
// TODO: add to list of objects without a valid vorbaId
obj.add(nobj);
}
- nobj.doHash();
+ nobj.doHash(); // TODO: DECIDE IF WE NEED TO DO THIS STILL: THIS DOESNT WORK! updates detected by comparing with last hash when marshalling
+
// check to see if new object was present in old object hash
if (nobj_id!=null) {
if (oldobjhashes.containsKey(nobj_id)) {
// object has no entry in the oldhashvalue list but
// there is a valid vorbaId so
nobj.set__added_since_last_read(true);
-
}
// and record the just-unmarshalled hash value
oldobjhashes.put(nobj_id, new Vobjhash(nobj));
final VorbaIdFactory vorbafactory = factory;
final Vector unrefedObj = new Vector();
final Vector updatedObj = new Vector();
- unmarshaller.setUnmarshalListener(new VorbaXmlBinder(vorbafactory, unrefedObj, objrefs, oobjhashes, updatedObj));
+ ChecksummedReader ckedInstream = new ChecksummedReader(instream);
+ unmarshaller.setUnmarshalListener(new VorbaXmlBinder(vorbafactory, unrefedObj, objrefs, oobjhashes,updatedObj, ckedInstream));
// Call the unmarshaller.
try {
while (instream.ready()) {
// TODO: mark objects in oobjhash prior to unmarshalling, to detect when objects have been lost through an update.
//tohere
- Object obj = unmarshaller.unmarshal(instream);
+ Object obj = unmarshaller.unmarshal(ckedInstream);
boolean sync=ensure_references(unrefedObj, objrefs);
if (!(obj instanceof Vobject))
return null;