JAL-1432 updated copyright notices
[jalview.git] / src / jalview / io / vamsas / LocalDocSyncObject.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3  * Copyright (C) 2014 The Jalview Authors
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  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.io.vamsas;
20
21 import uk.ac.vamsas.client.Vobject;
22
23 /**
24  * Implement the basic logic for synchronising changes to or from the Vamsas
25  * Document. This is a more generic and normalised framework than the one
26  * implemented in DatastoreItem, but probably more tedious to implement. ..
27  * abandoned. Nov 2008
28  * 
29  * @author JimP
30  */
31 public abstract class LocalDocSyncObject extends DatastoreItem
32 {
33   /**
34    * 
35    * @return null or the local object that is being worked on.
36    */
37   public abstract Object getLObject();
38
39   /**
40    * 
41    * @return null or the document object that is being worked on
42    */
43   public abstract Vobject getVObject();
44
45   /**
46    * endpoint for synchronize when all opreations are finished.
47    */
48   public abstract void nextObject();
49
50   /**
51    * called if the local object can be safely updated from the bound document
52    * object. public abstract void updateToDoc();
53    */
54
55   /**
56    * called if the associated document object can be safely updated with the
57    * local changes public abstract void updateToDoc();
58    */
59
60   /**
61    * @return true if the local object is modified
62    */
63   public abstract boolean locallyModified();
64
65   /**
66    * 
67    * @return true if the bound document object is modified
68    */
69   public abstract boolean documentModified();
70
71   /**
72    * 
73    * @return true if the document object is locked w.r.t. this object's update.
74    */
75   public abstract boolean documentObjectLocked();
76
77   /**
78    * 
79    * @return a new datastore item instance which binds the local object to a new
80    *         document object
81    */
82   public abstract LocalDocSyncObject newDocumentObject(); // could make this
83
84   // constructor(Lobject)
85
86   /**
87    * 
88    * @return a new datastore item instance which binds the document object to a
89    *         new local object.
90    */
91   public abstract LocalDocSyncObject newLocalObject(); // make this
92
93   // constructor(Vobject)
94
95   /**
96    * apply the update/commit logic as defined in the vamsas paper
97    * 
98    * @param documentIsUpdated
99    *          true if a document update event is being handled
100    */
101   public void synchronize(boolean documentIsUpdated)
102   {
103     Object Lobject = getLObject();
104     Vobject Vobject = getVObject();
105     if (Lobject == null)
106     {
107       // no local binding for document object
108       newLocalObject().synchronize(documentIsUpdated);
109       return;
110     }
111     if (Vobject == null)
112     {
113       // no document binding for local object
114       newDocumentObject().synchronize(documentIsUpdated);
115     }
116     // Check binding is valid
117     if (getjv2vObj(Lobject) != Vobject)
118     {
119       // no local binding for document object
120       newLocalObject().synchronize(documentIsUpdated);
121       // no document binding for local object
122       newDocumentObject().synchronize(documentIsUpdated);
123     }
124   }
125 }