update author list in license for (JAL-826)
[jalview.git] / src / jalview / io / vamsas / LocalDocSyncObject.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.io.vamsas;
19
20 import uk.ac.vamsas.client.Vobject;
21
22 /**
23  * Implement the basic logic for synchronising changes to or from the Vamsas
24  * Document. This is a more generic and normalised framework than the one
25  * implemented in DatastoreItem, but probably more tedious to implement. ..
26  * abandoned. Nov 2008
27  * 
28  * @author JimP
29  */
30 public abstract class LocalDocSyncObject extends DatastoreItem
31 {
32   /**
33    * 
34    * @return null or the local object that is being worked on.
35    */
36   public abstract Object getLObject();
37
38   /**
39    * 
40    * @return null or the document object that is being worked on
41    */
42   public abstract Vobject getVObject();
43
44   /**
45    * endpoint for synchronize when all opreations are finished.
46    */
47   public abstract void nextObject();
48
49   /**
50    * called if the local object can be safely updated from the bound document
51    * object. public abstract void updateToDoc();
52    */
53
54   /**
55    * called if the associated document object can be safely updated with the
56    * local changes public abstract void updateToDoc();
57    */
58
59   /**
60    * @return true if the local object is modified
61    */
62   public abstract boolean locallyModified();
63
64   /**
65    * 
66    * @return true if the bound document object is modified
67    */
68   public abstract boolean documentModified();
69
70   /**
71    * 
72    * @return true if the document object is locked w.r.t. this object's update.
73    */
74   public abstract boolean documentObjectLocked();
75
76   /**
77    * 
78    * @return a new datastore item instance which binds the local object to a new
79    *         document object
80    */
81   public abstract LocalDocSyncObject newDocumentObject(); // could make this
82
83   // constructor(Lobject)
84
85   /**
86    * 
87    * @return a new datastore item instance which binds the document object to a
88    *         new local object.
89    */
90   public abstract LocalDocSyncObject newLocalObject(); // make this
91
92   // constructor(Vobject)
93
94   /**
95    * apply the update/commit logic as defined in the vamsas paper
96    * 
97    * @param documentIsUpdated
98    *          true if a document update event is being handled
99    */
100   public void synchronize(boolean documentIsUpdated)
101   {
102     Object Lobject = getLObject();
103     Vobject Vobject = getVObject();
104     if (Lobject == null)
105     {
106       // no local binding for document object
107       newLocalObject().synchronize(documentIsUpdated);
108       return;
109     }
110     if (Vobject == null)
111     {
112       // no document binding for local object
113       newDocumentObject().synchronize(documentIsUpdated);
114     }
115     // Check binding is valid
116     if (getjv2vObj(Lobject) != Vobject)
117     {
118       // no local binding for document object
119       newLocalObject().synchronize(documentIsUpdated);
120       // no document binding for local object
121       newDocumentObject().synchronize(documentIsUpdated);
122     }
123   }
124 }