/*
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This file is part of Jalview.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
*/
package jalview.io.vamsas;
Hashtable vobj2jv;
IdentityHashMap jv2vobj;
-
- boolean tojalview=false;
+
+ boolean tojalview = false;
+
/**
* shared log instance
*/
- protected static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(DatastoreItem.class);
+ protected static org.apache.log4j.Logger log = org.apache.log4j.Logger
+ .getLogger(DatastoreItem.class);
+
/**
* note: this is taken verbatim from jalview.io.VamsasAppDatastore
+ *
* @return the Vobject bound to Jalview datamodel object
*/
protected Vobject getjv2vObj(Object jvobj)
}
/**
- * note: this is taken verbatim from jalview.io.VamsasAppDatastore
-
+ * note: this is taken verbatim from jalview.io.VamsasAppDatastore with added
+ * call to updateRegistryEntry
+ *
* @param jvobj
* @param vobj
*/
: "unregisterable") + " object " + vobj);
}
}
-
if (vobj2jv.containsKey(vobj.getVorbaId())
&& !(vobj2jv.get(vobj.getVorbaId())).equals(jvobj))
{
vobj2jv.put(vobj.getVorbaId(), jvobj);
// JBPNote - better implementing a hybrid invertible hash.
jv2vobj.put(jvobj, vobj.getVorbaId());
+ if (jvobj == this.jvobj || vobj == this.vobj)
+ {
+ updateRegistryEntry(jvobj, vobj);
+ }
+ }
+
+ /**
+ * update the vobj and jvobj references and the registry entry for this
+ * datastore object called by bindjvvobj and replacejvobjmapping
+ */
+ private void updateRegistryEntry(Object jvobj, Vobject vobj)
+ {
+ if (this.jvobj != null && this.vobj != null)
+ {
+ Cache.log.debug("updating dsobj registry. ("
+ + this.getClass().getName() + ")");
+ }
+ this.jvobj = jvobj;
+ this.vobj = vobj;
+ dsReg.registerDsObj(this);
}
+
/**
* replaces oldjvobject with newjvobject in the Jalview Object <> VorbaID
- * binding tables
- * note: this is taken verbatim from jalview.io.VamsasAppDatastore
+ * binding tables note: originally taken verbatim from
+ * jalview.io.VamsasAppDatastore with added call to updateRegistryEntry
+ *
* @param oldjvobject
- * @param newjvobject (may be null to forget the oldjvobject's document mapping)
+ * @param newjvobject
+ * (may be null to forget the oldjvobject's document mapping)
*
*/
protected void replaceJvObjMapping(Object oldjvobject, Object newjvobject)
"IMPLEMENTATION ERROR: old jalview object is not bound ! ("
+ oldjvobject + ")");
}
- if (newjvobject!=null)
+ if (newjvobject != null)
{
jv2vobj.put(newjvobject, vobject);
vobj2jv.put(vobject, newjvobject);
+ updateRegistryEntry(newjvobject, vobj);
}
}
initDatastoreItem(datastore);
// TODO Auto-generated constructor stub
}
+
/**
- * construct and initialise datastore object and retrieve object bound to vobj2 and validate it against boundType
+ * construct and initialise datastore object and retrieve object bound to
+ * vobj2 and validate it against boundType
+ *
* @param datastore2
* @param vobj2
* @param boundType
*/
- public DatastoreItem(VamsasAppDatastore datastore2, Vobject vobj2, Class boundType)
+ public DatastoreItem(VamsasAppDatastore datastore2, Vobject vobj2,
+ Class boundType)
{
this(datastore2);
vobj = vobj2;
jvobj = getvObj2jv(vobj2);
- tojalview=true;
- if (jvobj!=null && !(boundType.isAssignableFrom(jvobj.getClass())))
+ tojalview = true;
+ if (jvobj != null && !(boundType.isAssignableFrom(jvobj.getClass())))
{
- throw new Error("Implementation Error: Vamsas Document Class "+vobj.getClass()+" should bind to a "+boundType+" (found a "+jvobj.getClass()+")");
+ throw new Error("Implementation Error: Vamsas Document Class "
+ + vobj.getClass() + " should bind to a " + boundType
+ + " (found a " + jvobj.getClass() + ")");
}
dsReg.registerDsObj(this);
}
+
/**
- * construct and initialise datastore object and retrieve document object bound to Jalview object jvobj2 and validate it against boundType
- * @param datastore2 the datastore
- * @param jvobj2 the jalview object
- * @param boundToType - the document object class that the bound object should be assignable from
+ * construct and initialise datastore object and retrieve document object
+ * bound to Jalview object jvobj2 and validate it against boundType
+ *
+ * @param datastore2
+ * the datastore
+ * @param jvobj2
+ * the jalview object
+ * @param boundToType
+ * - the document object class that the bound object should be
+ * assignable from
*/
- public DatastoreItem(VamsasAppDatastore datastore2, Object jvobj2, Class boundToType)
+ public DatastoreItem(VamsasAppDatastore datastore2, Object jvobj2,
+ Class boundToType)
{
this(datastore2);
jvobj = jvobj2;
- tojalview=false;
+ tojalview = false;
vobj = getjv2vObj(jvobj);
- if (vobj!=null && !(boundToType.isAssignableFrom(vobj.getClass())))
+ if (vobj != null && !(boundToType.isAssignableFrom(vobj.getClass())))
{
- throw new Error("Implementation Error: Jalview Class "+jvobj2.getClass()+" should bind to a "+boundToType+" (found a "+vobj.getClass()+")");
+ throw new Error("Implementation Error: Jalview Class "
+ + jvobj2.getClass() + " should bind to a " + boundToType
+ + " (found a " + vobj.getClass() + ")");
}
dsReg.registerDsObj(this);
}
+
/**
- * create a new vobj to be added to the document
- * for the jalview object jvobj
+ * create a new vobj to be added to the document for the jalview object jvobj
* (jvobj!=null, vobj==null)
*/
public abstract void addToDocument();
+
/**
- * handle a conflict where both an existing vobj has been updated
- * and a local jalview object has been updated. This method
- * is only called from doSync, when an incoming update from the vamsas
- * session conflicts with local modifications made by the Jalview user.
- * (jvobj!=null, vobj!=null)
+ * handle a conflict where both an existing vobj has been updated and a local
+ * jalview object has been updated. This method is only called from doSync,
+ * when an incoming update from the vamsas session conflicts with local
+ * modifications made by the Jalview user. (jvobj!=null, vobj!=null)
*/
public abstract void conflict();
+
/**
- * update an existing vobj in the document with the data and settings from jvobj
- * (jvobj!=null, vobj!=null)
+ * update an existing vobj in the document with the data and settings from
+ * jvobj (jvobj!=null, vobj!=null)
*/
public abstract void updateToDoc();
+
/**
- * update the local jalview object with the data from an existing vobj in the document
- * (jvobj!=null, vobj!=null)
+ * update the local jalview object with the data from an existing vobj in the
+ * document (jvobj!=null, vobj!=null)
*/
public abstract void updateFromDoc();
+
/**
- * create a new local jvobj bound to the vobj in the document.
- * (jvobj==null, vobj!=null)
+ * create a new local jvobj bound to the vobj in the document. (jvobj==null,
+ * vobj!=null)
*/
public abstract void addFromDocument();
- boolean addtodoc=false, conflicted=false,updated=false,addfromdoc=false,success=false;
+
+ boolean addtodoc = false, conflicted = false, updated = false,
+ addfromdoc = false, success = false;
private boolean updatedtodoc;
private boolean updatedfromdoc;
+
/**
- * Sync jalview to document. Enact addToDocument, conflict or update dependent on
- * existence of a vobj bound to the local jvobj.
+ * Sync jalview to document. Enact addToDocument, conflict or update dependent
+ * on existence of a vobj bound to the local jvobj.
*/
protected void doSync()
{
if (vobj == null)
{
log.debug("adding new vobject to document.");
- addtodoc=true;
+ addtodoc = true;
addToDocument();
}
else
if (vobj.isUpdated())
{
log.debug("Handling update conflict for existing bound vobject.");
- conflicted=true;
+ conflicted = true;
conflict();
}
else
{
log.debug("updating existing vobject in document.");
- updatedtodoc=true;
+ updatedtodoc = true;
updateToDoc();
}
}
// no exceptions were encountered...
- success=true;
+ success = true;
}
+
/**
- * Update jalview from document. enact addFromDocument if no local jvobj exists, or update iff jvobj
- * exists and the vobj.isUpdated() flag is set.
+ * Update jalview from document. enact addFromDocument if no local jvobj
+ * exists, or update iff jvobj exists and the vobj.isUpdated() flag is set.
*/
protected void doJvUpdate()
{
if (jvobj == null)
{
log.debug("adding new vobject to Jalview from Document");
- addfromdoc=true;
+ addfromdoc = true;
addFromDocument();
}
else
if (vobj.isUpdated())
{
log.debug("updating Jalview from existing bound vObject");
- updatedfromdoc=true;
+ updatedfromdoc = true;
updateFromDoc();
}
}
}
VamsasAppDatastore datastore = null;
+
/**
* object in vamsas document
*/
protected Vobject vobj = null;
+
/**
* local jalview object
*/
{
datastore = ds;
dsReg = ds.getDatastoreRegisty();
- initDatastoreItem(ds.getProvEntry(), ds.getClientDocument(), ds
- .getVamsasObjectBinding(), ds.getJvObjectBinding());
+ initDatastoreItem(ds.getProvEntry(), ds.getClientDocument(),
+ ds.getVamsasObjectBinding(), ds.getJvObjectBinding());
}
private void initDatastoreItem(Entry provEntry, IClientDocument cdoc,
*
* @param visSeg
* @param ensureDirection
- * when true - always ensure start is less than end.
+ * when true - always ensure start is less than end.
* @return int[] { start, end, direction} where direction==1 for range running
* from end to start.
*/
p.addEntry(dummyPEntry(action));
}
-
/**
* @return true if jalview was being updated from the vamsas document
*/
{
return updatedfromdoc;
}
+
/**
* @return true if updateToDoc() was called
*/