From 161d6b44b4a8c1483c27e54ca16d106343a099d3 Mon Sep 17 00:00:00 2001 From: jprocter Date: Tue, 25 Sep 2007 09:31:42 +0000 Subject: [PATCH] beginning of vamsas/local object synchronization pattern implementation. --- src/jalview/io/vamsas/LocalDocSyncObject.java | 85 +++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/jalview/io/vamsas/LocalDocSyncObject.java diff --git a/src/jalview/io/vamsas/LocalDocSyncObject.java b/src/jalview/io/vamsas/LocalDocSyncObject.java new file mode 100644 index 0000000..344d40b --- /dev/null +++ b/src/jalview/io/vamsas/LocalDocSyncObject.java @@ -0,0 +1,85 @@ +package jalview.io.vamsas; + +import uk.ac.vamsas.client.Vobject; + +/** + * Implement the basic logic for synchronising changes to or from the Vamsas Document + * @author JimP + */ +public abstract class LocalDocSyncObject extends DatastoreItem +{ + /** + * + * @return null or the local object that is being worked on. + */ + public abstract Object getLObject(); + /** + * + * @return null or the document object that is being worked on + */ + public abstract Vobject getVObject(); + + /** + * endpoint for synchronize when all opreations are finished. + */ + public abstract void nextObject(); + /** + * called if the local object can be safely updated from the bound document object. + */ + public abstract void updateFromDoc(); + /** + * called if the associated document object can be safely updated with the local changes + */ + public abstract void updateToDoc(); + /** + * @return true if the local object is modified + */ + public abstract boolean locallyModified(); + /** + * + * @return true if the bound document object is modified + */ + public abstract boolean documentModified(); + /** + * + * @return true if the document object is locked w.r.t. this object's update. + */ + public abstract boolean documentObjectLocked(); + /** + * + * @return a new datastore item instance which binds the local object to a new document object + */ + public abstract LocalDocSyncObject newDocumentObject(); // could make this constructor(Lobject) + /** + * + * @return a new datastore item instance which binds the document object to a new local object. + */ + public abstract LocalDocSyncObject newLocalObject(); // make this constructor(Vobject) + /** + * apply the update/commit logic as defined in the vamsas paper + * @param documentIsUpdated true if a document update event is being handled + */ + public void synchronize(boolean documentIsUpdated) { + Object Lobject = getLObject(); + Vobject Vobject = getVObject(); + if (Lobject==null) + { + // no local binding for document object + newLocalObject().synchronize(documentIsUpdated); + return; + } + if (Vobject==null) + { + // no document binding for local object + newDocumentObject().synchronize(documentIsUpdated); + } + // Check binding is valid + if (getjv2vObj(Lobject)!=Vobject) + { + // no local binding for document object + newLocalObject().synchronize(documentIsUpdated); + // no document binding for local object + newDocumentObject().synchronize(documentIsUpdated); + } + } +} -- 1.7.10.2