X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fuk%2Fac%2Fvamsas%2Fclient%2Fsimpleclient%2FClientDocument.java;h=b9e918e2475d02185fb24944cc492d351381ca9d;hb=1e940bf58bbd9f228ff991b5ee6e5b38c36a78fe;hp=f853937d9a96765add1154e8112f207ffab36cd3;hpb=63b0b269c333a317ddd018c70a336c4cf839a2ee;p=vamsas.git diff --git a/src/uk/ac/vamsas/client/simpleclient/ClientDocument.java b/src/uk/ac/vamsas/client/simpleclient/ClientDocument.java index f853937..b9e918e 100644 --- a/src/uk/ac/vamsas/client/simpleclient/ClientDocument.java +++ b/src/uk/ac/vamsas/client/simpleclient/ClientDocument.java @@ -8,8 +8,6 @@ import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.vamsas.objects.utils.AppDataReference; -import org.vamsas.test.objects.Core; import uk.ac.vamsas.client.ClientHandle; import uk.ac.vamsas.client.IClientAppdata; @@ -21,16 +19,20 @@ import uk.ac.vamsas.objects.core.ApplicationData; import uk.ac.vamsas.objects.core.User; import uk.ac.vamsas.objects.core.VAMSAS; import uk.ac.vamsas.objects.core.VamsasDocument; +import uk.ac.vamsas.objects.utils.AppDataReference; +import uk.ac.vamsas.test.objects.Core; /** - * Maintains a collection of vamsas objects, appdatas and states, and provides api for a SimpleClient's client. + * Maintains a collection of vamsas objects, appdatas and states, + * and provides api for a SimpleClient's client. + * TODO: test and migrate ArchiveClient.getAppData methods to here and retest in ExampleApplication * @author jimp */ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implements IClientDocument { private static Log log = LogFactory.getLog(ClientDocument.class); private VamsasDocument doc; protected SimpleClient sclient; - protected VamsasArchive archive = null; + protected VamsasArchive iohandler = null; /** * indicate if new data has been incorporated */ @@ -42,10 +44,9 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement public boolean isModified() { return isModified; } - private Vector updatedObjects=null; /** * - * prepare Application-side dataset from the vamsas Document archive + * prepare Application-side dataset from the vamsas Document iohandler * @param doc - the dataset * @param docHandler - the sessionFile IO handler * @param Factory - the source of current and new vorbaIds @@ -56,12 +57,12 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement /** - * prepare Application-side dataset from the vamsas Document archive + * prepare Application-side dataset from the vamsas Document iohandler */ this.sclient = sclient; - archive = docHandler; + iohandler = docHandler; this.doc = doc; - updatedObjects=null; /// TODO: correct this line + _VamsasRoots=doc.getVAMSAS(); } /* @@ -102,7 +103,25 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement * internal reference to single copy of Document Roots array */ private VAMSAS[] _VamsasRoots=null; - /* + /** + * set if the client has corrupted the Vamsas Document structure somehow. + * if this is set the document will never be written back to the session unless the corruption is fixed. + */ + private boolean invalidModification=false; + + protected void updateDocumentRoots() { + if (doc==null) { + log.error("updateDocumentRoots called on null document. Probably an implementation error."); + return; + } + if (isModified) { + if (_VamsasRoots!=null) { + doc.setVAMSAS(_VamsasRoots); + _VamsasRoots=null; + } + } + } +/* * (non-Javadoc) * LATER: currently there is only one Vector of roots ever passed to client - decide if this is correct (means this is not thread safe and may behave unexpectedly) * @see uk.ac.vamsas.client.IClientDocument#getVamsasRoots() @@ -112,7 +131,7 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement log.debug("Null document for getVamsasRoots(), returning null"); return null; } - if (archive==null) { + if (iohandler==null) { // LATER: decide on read-only status of ClientDocument object log.warn("getVamsasRoots() called on possibly read-only document."); } @@ -122,6 +141,7 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement if (roots == null) { // Make a new one to return to client to get filled. _VamsasRoots = new VAMSAS[] { new VAMSAS() }; + registerObject(_VamsasRoots[0]); // Do provenance now. just in case. doc.getProvenance().addEntry(sclient.getProvenanceEntry("Created new document root [id="+_VamsasRoots[0].getId()+"]")); doc.addVAMSAS(_VamsasRoots[0]); @@ -138,39 +158,78 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement return -1; if (docRoots==null || docRoots.length==0) return -1; - String r_id = root.getId(); + VorbaId d_id=null,r_id = root.getVorbaId(); for (int i=0,j=docRoots.length; i-1) { - if (isValidUpdate(newr[k], original[i])) { - modified=true; + if (isValidUpdate(newr[k], original[i], modflag)) { + // set by isValidUpdate if the hashcodes were really different from last store rts.add(newr[k]); newr[k]=null; } else { @@ -248,14 +309,12 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement for (int i=0,j=newr.length; i