* @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());
* @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]))
* @see org.vamsas.client.IClientDocument#getVamsasRoots()
*/
public VAMSAS[] getVamsasRoots() {
+ if (doc==null) {
+ log.debug("Null document for getVamsasRoots(), returning null");
+ return null;
+ }
+ if (archive==null) {
+ // LATER: decide on read-only status of ClientDocument object
+ log.warn("getVamsasRoots() called on possibly read-only document.");
+ }
if (_VamsasRoots!=null)
return _VamsasRoots;
VAMSAS[] roots = doc.getVAMSAS();
if (roots == null) {
- // Make a new one to return to client : TODO: Decide if this is correct
+ // Make a new one to return to client to get filled.
_VamsasRoots = new VAMSAS[] { new VAMSAS() };
+ // Do provenance now. just in case.
+ doc.getProvenance().addEntry(sclient.getProvenanceEntry("Created new document root [id="+_VamsasRoots[0].getId()+"]"));
+ doc.addVAMSAS(_VamsasRoots[0]);
} else {
_VamsasRoots = new VAMSAS[roots.length];
for (int r=0;r<roots.length; r++)
* @see org.vamsas.IClientDocument.setVamsasRoots
*/
public void setVamsasRoots(VAMSAS[] newroots) {
+ if (doc==null) {
+ log.debug("setVamsasRoots called on null document.");
+ return;
+ }
VAMSAS[] newr;
if (newroots==null) {
log.debug("setVamsasRoots(null) - do nothing.");
* @see org.vamsas.client.IClientDocument#addVamsasRoot(org.vamsas.objects.core.VAMSAS)
*/
public void addVamsasRoot(VAMSAS newroot) {
+ if (doc==null) {
+ log.debug("addVamsasRoots called on null document.");
+ return;
+ }
VAMSAS[] newroots = _combineRoots(new VAMSAS[] {newroot}, _VamsasRoots, this);
_VamsasRoots = newroots;
}
* @see org.vamsas.client.IClientDocument#registerObjects(org.vamsas.client.Vobject[])
*/
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++)
* @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 (unregistered!=null) {
VorbaId id = _registerObject(unregistered);
log.debug("Registered object - total of "+objrefs.size()+" ids.");
* @see org.vamsas.client.IClientDocument#getClientAppdata()
*/
public IClientAppdata getClientAppdata() {
+ if (doc==null) {
+ log.warn("getClientAppdata called on null document.");
+ return null;
+ }
if (scappd==null) {
log.debug("Creating new SimpleClientAppdata instance for "+sclient.getSessionHandle());
scappd = new SimpleClientAppdata(this);
}
protected boolean updateSessionDocument() throws java.io.IOException {
boolean docupdate = true; // 'non-serious' problems below set this false
+ if (doc==null) {
+ log.warn("updateSessionDocument called on null document.");
+ throw new java.io.IOException("Document is closed.");
+ }
+ if (archive==null) {
+ log.warn("updateSessionDocument called document archive handler.");
+ throw new java.io.IOException("Document is closed.");
+ }
+
if (!isModified() && !scappd.isModified()) {
log.debug("Document update not necessary. returning false.");
return false;
log.debug("No remaining appdatas were transferred. (Correct?)");
archive.closeArchive();
log.debug("...successully finished and closed.");
-
return docupdate; // no errors ?
}
/* (non-Javadoc)
scappd.finalize();
scappd = null;
}
- // TODO local garbage collection
+ if (doc!=null) {
+ doc = null;
+ }
+ // disengage from client
+ if (sclient!=null)
+ sclient.cdocument = null;
+ sclient=null;
super.finalize();
}
fileLock.release();
fileLock = null;
if (sessionFile != null) {
- if (sessionFile.exists()) {
- // TODO: see if we need to loop-wait for locks or they just block until
- // lock is made...
- do {
- if (fileLock!=null)
- fileLock.release();
- fileLock = new Lock(sessionFile); // TODO: wait around if we can't get the lock.
- } while (!fileLock.isLocked());
- // fileLock = new Lock(sessionFile);
- return fileLock.isLocked();
+ if (!sessionFile.exists()) {
+ // create new file
+ try {
+ if (!sessionFile.createNewFile()) {
+ log.error("Failed to create file prior to locking: "+sessionFile);
+ return false;
+ }
+ } catch (IOException e) {
+ log.error("Exception when trying to create file "+sessionFile, e);
+ return false;
+ }
}
+ // TODO: see if we need to loop-wait for locks or they just block until
+ // lock is made...
+ do {
+ if (fileLock!=null)
+ fileLock.release();
+ fileLock = new Lock(sessionFile); // TODO: wait around if we can't get the lock.
+ } while (!fileLock.isLocked());
+ // fileLock = new Lock(sessionFile);
+ return fileLock.isLocked();
} else
log.error("lockFile called for non-initialised SessionFile!");