--- /dev/null
+package jalview.io.vamsas;\r
+\r
+import uk.ac.vamsas.client.Vobject;\r
+\r
+/**\r
+ * Implement the basic logic for synchronising changes to or from the Vamsas Document\r
+ * @author JimP\r
+ */\r
+public abstract class LocalDocSyncObject extends DatastoreItem\r
+{\r
+ /**\r
+ * \r
+ * @return null or the local object that is being worked on. \r
+ */\r
+ public abstract Object getLObject();\r
+ /**\r
+ * \r
+ * @return null or the document object that is being worked on\r
+ */\r
+ public abstract Vobject getVObject();\r
+ \r
+ /**\r
+ * endpoint for synchronize when all opreations are finished.\r
+ */\r
+ public abstract void nextObject();\r
+ /**\r
+ * called if the local object can be safely updated from the bound document object.\r
+ */\r
+ public abstract void updateFromDoc();\r
+ /**\r
+ * called if the associated document object can be safely updated with the local changes\r
+ */\r
+ public abstract void updateToDoc();\r
+ /**\r
+ * @return true if the local object is modified\r
+ */\r
+ public abstract boolean locallyModified();\r
+ /**\r
+ * \r
+ * @return true if the bound document object is modified\r
+ */\r
+ public abstract boolean documentModified();\r
+ /**\r
+ * \r
+ * @return true if the document object is locked w.r.t. this object's update.\r
+ */\r
+ public abstract boolean documentObjectLocked();\r
+ /**\r
+ * \r
+ * @return a new datastore item instance which binds the local object to a new document object \r
+ */\r
+ public abstract LocalDocSyncObject newDocumentObject(); // could make this constructor(Lobject)\r
+ /**\r
+ * \r
+ * @return a new datastore item instance which binds the document object to a new local object. \r
+ */\r
+ public abstract LocalDocSyncObject newLocalObject(); // make this constructor(Vobject)\r
+ /**\r
+ * apply the update/commit logic as defined in the vamsas paper\r
+ * @param documentIsUpdated true if a document update event is being handled \r
+ */\r
+ public void synchronize(boolean documentIsUpdated) {\r
+ Object Lobject = getLObject();\r
+ Vobject Vobject = getVObject();\r
+ if (Lobject==null)\r
+ {\r
+ // no local binding for document object\r
+ newLocalObject().synchronize(documentIsUpdated);\r
+ return;\r
+ }\r
+ if (Vobject==null)\r
+ {\r
+ // no document binding for local object\r
+ newDocumentObject().synchronize(documentIsUpdated);\r
+ }\r
+ // Check binding is valid\r
+ if (getjv2vObj(Lobject)!=Vobject)\r
+ {\r
+ // no local binding for document object\r
+ newLocalObject().synchronize(documentIsUpdated);\r
+ // no document binding for local object\r
+ newDocumentObject().synchronize(documentIsUpdated);\r
+ }\r
+ }\r
+}\r