try {
Method fd = this.getClass().getMethod("getId", (Class[]) null);
Object idstring = fd.invoke((Object) this, (Object[]) null);
- log.debug(this.getClass().getName()+" called setInstanceVorbaIdField!");
+ log.debug(this.getClass().getName()+" called getInstanceIdField!");
if (idstring!=null && idstring instanceof String) {
if (((String) idstring).length()>0)
return (String) idstring;
* properly instantiated VorbaIdFactory.
*/
public VorbaId getVorbaId() {
- /*if (!registerable && !__testedInstance) {
- testInstanceForIdField();
- __testedInstance=true;
- }*/
if (registerable && vorbaId == null) {
+ if (this.__stored_in_document) {
+ if (__vorba!=null)
+ vorbaId=org.vamsas.client.VorbaId.newId(this.__getInstanceIdField());
+ }
// Try to use the associated factory.
if (__vorba != null)
if ((vorbaId = __vorba.makeVorbaId(this)) == null)
if (newobj instanceof Vobject) {
Vobject nobj = (Vobject) newobj;
nobj.set__stored_in_document(true);
- Field fd = null;
try {
if (nobj.isRegisterable() && nobj.___id_field!=null) {
// look for the id field (should be an NCName string)
nobj.__vorba = vorbafactory;
- 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);
- nobj.setVorbaId(VorbaId.newId(idstring));
- } else {
+ nobj.setVorbaId(VorbaId.newId(idstring));
+ if (objrefs.containsKey(nobj.getVorbaId()) && !objrefs.get(nobj.getVorbaId()).equals(nobj)) {
System.err.println("Serious problem : duplicate id '"+idstring+"' found! expect badness.");
// TODO: HANDLE duplicate XML ids correctly
}
+ objrefs.put(nobj.getVorbaId(), nobj);
} else {
// add to list of objects without a valid vorbaId
obj.add(nobj);
// forces registration and id field update.
VorbaId id = o.getVorbaId();
if (!objrefs.containsKey(id)) {
- objrefs.put(id.id, o);
+ objrefs.put(id, o);
} else {
- throw new Error("Serious! Duplicate reference made by vorbaIdFactory!");
+ if (!objrefs.get(id).equals(o))
+ throw new Error("Serious! Duplicate reference made by vorbaIdFactory!");
}
}
}
* @return null or {(Object) VamsasDocument Vobject, (Object) Hashtable of Vobject references, (Object) Boolean(sync) }
*/
public static Object[] getVamsasObjects(Reader instream,
- IVorbaIdFactory factory, Vobject root) {
+ VorbaIdFactory factory, Vobject root) {
Unmarshaller unmarshaller = new Unmarshaller(root);
unmarshaller.setIDResolver(new IDResolver() {
public Object resolve(String id) {
Hashtable refbase = new Hashtable();
Vector unrefed = new Vector();
final Hashtable objrefs = refbase;
- final IVorbaIdFactory vorbafactory = factory;
+ final VorbaIdFactory vorbafactory = factory;
final Vector unrefedObj = unrefed;
unmarshaller.setUnmarshalListener(new VorbaXmlBinder(vorbafactory, unrefedObj, objrefs));
// Call the unmarshaller.
boolean sync=ensure_references(unrefed, objrefs);
if (!(obj instanceof Vobject))
return null;
+ vorbafactory.setNewIdHash(objrefs); // update the Document IO Handler's set of vorbaId<>Object bindings.
return new Object[] { obj, objrefs, new Boolean(sync)};
}
} catch (MarshalException e) {
public VorbaId makeVorbaId(Vobject vobject) {
if (session==null)
throw new Error("makeVorbaId called on improperly initialised IdFactory Vobject!");
+ if (!vobject.isRegisterable())
+ throw new Error("makeVorbaId called on unregisterable object.");
+ if (vobject.isRegistered())
+ throw new Error("makeVorbaId called on already registered object.");
String newidstring;
do {
if (sequence>0) {
newidstring=idstring+Integer.toString(sequence);
} while (extantids.containsKey(newidstring));
extantids.put(newidstring, vobject); // hash the Vobject by its new Id
- VorbaId id = newId(newidstring);
+ VorbaId id = newId(newidstring); // VorbaId.hash()==newidstring.hash() so we can still recover vobject
return id;
}
*/
File originalBackup = null;
- boolean donotdeletebackup=true;
+ boolean donotdeletebackup=false;
private final int _TRANSFER_BUFFER=4096*4;
protected SimpleDocument vorba = null;
/**
if (doclock==null)
return null;
else {
- doclock = vsess.getLock(doclock);
- VamsasArchiveReader varc = new VamsasArchiveReader(vsess.getVamsasFile());
- return _getReadonly(varc);
+ return getUpdateable(vsess.getLock(doclock));
+ /*VamsasArchiveReader varc = new VamsasArchiveReader(vsess.getVamsasFile());
+ return _getReadonly(varc);*/
}
} catch (Exception e) {
log.error("Whilst watching file "+vsess.getVamsasFile(), e);
}
public ClientDoc getUpdateable() {
+ return getUpdateable(null);
+ }
+ public ClientDoc getUpdateable(org.vamsas.client.simpleclient.Lock lock) {
+ getVorbaIdHash().clear();
valid();
try {
// patiently wait for a lock on the document.
long tries=5000;
- org.vamsas.client.simpleclient.Lock lock;
- while (((lock=vsess.getLock())==null || !lock.isLocked()) && --tries>0) {
+ while (lock==null && ((lock=vsess.getLock())==null || !lock.isLocked()) && --tries>0) {
// Thread.sleep(1);
log.debug("Trying to get a document lock for the "+tries+"'th time.");
}
cdoc.updateDocumentRoots();
cdoc.iohandler.putVamsasDocument(cdoc.doc);
cdoc.iohandler.closeArchive();
+ this.extantids.clear();// we forget our ids after we close the document.
cdoc.iohandler=null;
cdoc = null;
vsess.unLock();
int u=5;
while (--u>0) {
System.out.println("Watch for more... ("+u+" left)");
- ClientDoc ucdoc = client.watch(50000);
+ ClientDoc ucdoc = client.watch(0000);
if (ucdoc!=null) {
System.out.println("****\nUpdate detected at "+new Date());
ArchiveReports.reportDocument(ucdoc.doc, ucdoc.getReader(), true, System.out);