package jalview.io.vamsas; import jalview.bin.Cache; import jalview.gui.TreePanel; import jalview.io.VamsasAppDatastore; import java.util.Enumeration; import java.util.Hashtable; import java.util.IdentityHashMap; import java.util.Vector; import uk.ac.vamsas.client.IClientDocument; import uk.ac.vamsas.client.Vobject; import uk.ac.vamsas.client.VorbaId; import uk.ac.vamsas.objects.core.Entry; import uk.ac.vamsas.objects.core.Provenance; import uk.ac.vamsas.objects.core.Seg; /** * Holds all the common machinery for binding objects to vamsas objects * @author JimP * */ public class DatastoreItem { /** * */ Entry provEntry = null; IClientDocument cdoc; Hashtable vobj2jv; IdentityHashMap jv2vobj; /** * @return the Vobject bound to Jalview datamodel object */ protected Vobject getjv2vObj(Object jvobj) { if (jv2vobj.containsKey(jvobj)) { return cdoc.getObject( (VorbaId) jv2vobj.get(jvobj)); } if (Cache.log.isDebugEnabled()) { Cache.log.debug("Returning null VorbaID binding for jalview object "+jvobj); } return null; } /** * * @param vobj * @return Jalview datamodel object bound to the vamsas document object */ protected Object getvObj2jv(uk.ac.vamsas.client.Vobject vobj) { if (vobj2jv==null) return null; VorbaId id = vobj.getVorbaId(); if (id == null) { id = cdoc.registerObject(vobj); Cache.log .debug("Registering new object and returning null for getvObj2jv"); return null; } if (vobj2jv.containsKey(vobj.getVorbaId())) { return vobj2jv.get(vobj.getVorbaId()); } return null; } protected void bindjvvobj(Object jvobj, uk.ac.vamsas.client.Vobject vobj) { VorbaId id = vobj.getVorbaId(); if (id == null) { id = cdoc.registerObject(vobj); if (id == null || vobj.getVorbaId() == null || cdoc.getObject(id)!=vobj) { Cache.log.error("Failed to get id for " + (vobj.isRegisterable() ? "registerable" : "unregisterable") + " object " + vobj); } } if (vobj2jv.containsKey(vobj.getVorbaId()) && ! ( (VorbaId) vobj2jv.get(vobj.getVorbaId())).equals(jvobj)) { Cache.log.debug("Warning? Overwriting existing vamsas id binding for " + vobj.getVorbaId(), new Exception("Overwriting vamsas id binding.")); } else if (jv2vobj.containsKey(jvobj) && ! ( (VorbaId) jv2vobj.get(jvobj)).equals(vobj.getVorbaId())) { Cache.log.debug( "Warning? Overwriting existing jalview object binding for " + jvobj, new Exception("Overwriting jalview object binding.")); } /* Cache.log.error("Attempt to make conflicting object binding! "+vobj+" id " +vobj.getVorbaId()+" already bound to "+getvObj2jv(vobj)+" and "+jvobj+" already bound to "+getjv2vObj(jvobj),new Exception("Excessive call to bindjvvobj")); }*/ // we just update the hash's regardless! Cache.log.debug("Binding "+vobj.getVorbaId()+" to "+jvobj); vobj2jv.put(vobj.getVorbaId(), jvobj); // JBPNote - better implementing a hybrid invertible hash. jv2vobj.put(jvobj, vobj.getVorbaId()); } public DatastoreItem() { super(); } public DatastoreItem(VamsasAppDatastore datastore) { this(); initDatastoreItem(datastore); // TODO Auto-generated constructor stub } public void initDatastoreItem(VamsasAppDatastore ds) { initDatastoreItem(ds.getProvEntry(), ds.getClientDocument(), ds.getVamsasObjectBinding(), ds.getJvObjectBinding()); } public void initDatastoreItem(Entry provEntry, IClientDocument cdoc, Hashtable vobj2jv, IdentityHashMap jv2vobj) { this.provEntry = provEntry; this.cdoc = cdoc; this.vobj2jv = vobj2jv; this.jv2vobj = jv2vobj; } protected boolean isModifiable(String modifiable) { return modifiable==null; // TODO: USE VAMSAS LIBRARY OBJECT LOCK METHODS) } protected Vector getjv2vObjs(Vector alsq) { Vector vObjs = new Vector(); Enumeration elm = alsq.elements(); while (elm.hasMoreElements()) { vObjs.addElement(getjv2vObj(elm.nextElement())); } return vObjs; } // utility functions /** * get start