-/**
- *
- */
-package uk.ac.vamsas.client.simpleclient;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import uk.ac.vamsas.client.ClientHandle;
-import uk.ac.vamsas.client.SessionHandle;
-import uk.ac.vamsas.client.UserHandle;
-import uk.ac.vamsas.client.Vobject;
-import uk.ac.vamsas.client.VorbaId;
-import uk.ac.vamsas.client.VorbaIdFactory;
-import uk.ac.vamsas.objects.utils.document.VersionEntries;
-
-import java.util.Hashtable;
-import java.util.zip.CRC32;
-/**
- * Simplest VorbaId constructor
- * @author jimp
- *
- */
-public class IdFactory extends VorbaIdFactory {
- static Log log = LogFactory.getLog(IdFactory.class);
- private SessionHandle session=null;
- private ClientHandle client;
- private UserHandle user;
- private CRC32 unique=new CRC32(); // used to attempt a unique but predictable stream for IDs
- private String idstring;
- int sequence=1; // incrementing value for next new ID
- /**
- *
- */
- public IdFactory() {
- super();
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param session
- * @param client
- * @param user
- */
- protected IdFactory(SessionHandle session, ClientHandle client, UserHandle user) {
- super();
- this.session = session;
- this.client = client;
- this.user = user;
- unique.reset();
- unique.update(new Object[] { session, client, user}.toString().getBytes());
- // TODO: Ensure format of URNs and use standard composition methods.
- idstring = client.getClientNCname()+"_"+unique.getValue()+".";
- extantids=new Hashtable();
- this.extanthashv=new Hashtable();
- }
- /**
- * Create IdFactory with existing object hashes and id set
- * @param session
- * @param client
- * @param user
- * @param extanthashv hash of existing VorbaIds from a previous read of same document
- */
- protected IdFactory(SessionHandle session, ClientHandle client, UserHandle user, Hashtable extanthashv) {
- this(session, client, user);
- this.extanthashv = extanthashv;
- }
- /**
- * values for keys in this hash can be used to reference the uk.ac.vamsas.client.Vobject instance for the VorbaId string.
- * @return the hash of all VorbaIds
- */
- protected Hashtable getVorbaIdHash() {
- return extantids;
- }
- /**
- * values for keys in this hash are Vobjhash objects created for each Vobj with a VorbaId
- * after this factory has been used to write a vamsas archive.
- * @return the hash of all VorbaIds and their hash values.
- */
- protected Hashtable getVobjhashVals() {
- return extanthashv;
- }
- /* (non-Javadoc)
- * @see uk.ac.vamsas.client.VorbaIdFactory#makeVorbaId()
- */
- public VorbaId makeVorbaId(Vobject vobject) {
- if (session==null)
- throw new Error("makeVorbaId called on improperly initialised IdFactory Vobject!");
- if (!vobject.isRegisterable())
- throw new Error("makeVorbaId called on unregisterable object.");
- if (vobject.isRegistered())
- throw new Error("makeVorbaId called on already registered object.");
- String newidstring;
- do {
- if (sequence>0) {
- sequence++;
- } else {
- idstring+="1/";
- sequence=1;
- }
- newidstring=idstring+Integer.toString(sequence);
- } while (extantids.containsKey(newidstring));
- VorbaId id = newId(newidstring); // VorbaId.hash()==newidstring.hash() so we can still recover vobject
- extantids.put(id, vobject); // hash the Vobject by its new Id
- return id;
- }
-
- /* (non-Javadoc)
- * @see uk.ac.vamsas.client.VorbaIdFactory#setSession(uk.ac.vamsas.client.SessionHandle)
- */
- protected void setSession(SessionHandle sessionhandle) {
- if (sessionhandle!=null)
- session=sessionhandle;
- else
- log.warn("setSession(null) called.");
- }
-
- /* (non-Javadoc)
- * @see uk.ac.vamsas.client.VorbaIdFactory#getSessionHandle()
- */
- public SessionHandle getSessionHandle() {
- return session;
- }
-
- /* (non-Javadoc)
- * @see uk.ac.vamsas.client.VorbaIdFactory#setClient(uk.ac.vamsas.client.ClientHandle)
- */
- protected void setClient(ClientHandle appHandle) {
- if (appHandle!=null)
- client = appHandle;
- else
- log.warn("setClient(null) called.");
- }
-
- /* (non-Javadoc)
- * @see uk.ac.vamsas.client.VorbaIdFactory#getClientHandle()
- */
- public ClientHandle getClientHandle() {
- return client;
- }
-
- /* (non-Javadoc)
- * @see uk.ac.vamsas.client.VorbaIdFactory#setUser(uk.ac.vamsas.client.UserHandle)
- */
- protected void setUser(UserHandle userHandle) {
- if (userHandle!=null)
- user = userHandle;
- else
- log.warn("setUser(null) called.");
- }
-
- /* (non-Javadoc)
- * @see uk.ac.vamsas.client.VorbaIdFactory#getUserHandle()
- */
- public UserHandle getUserHandle() {
- return user;
- }
- /**
- * Convenience method used for default behaviour in testing
- * and any anonymous internal vamsasDocument unmarshalling
- * @param clientname
- * @return
- */
- protected static IdFactory getDummyFactory(String clientname) {
- if (clientname==null)
- clientname="uk.ac.vamsas.client.simpleclient.IdFactory";
- return new IdFactory(new SessionHandle("dummy.session"),
- new ClientHandle(clientname,VersionEntries.latestVersion()),
- new UserHandle(clientname, "Arnold User's Inc."));
- }
-}
+/*\r
+ * This file is part of the Vamsas Client version 0.1. \r
+ * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, \r
+ * Andrew Waterhouse and Dominik Lindner.\r
+ * \r
+ * Earlier versions have also been incorporated into Jalview version 2.4 \r
+ * since 2008, and TOPALi version 2 since 2007.\r
+ * \r
+ * The Vamsas Client is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Lesser General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ * \r
+ * The Vamsas Client is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Lesser General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU Lesser General Public License\r
+ * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package uk.ac.vamsas.client.simpleclient;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+\r
+import uk.ac.vamsas.client.ClientHandle;\r
+import uk.ac.vamsas.client.SessionHandle;\r
+import uk.ac.vamsas.client.UserHandle;\r
+import uk.ac.vamsas.client.Vobject;\r
+import uk.ac.vamsas.client.VorbaId;\r
+import uk.ac.vamsas.client.VorbaIdFactory;\r
+import uk.ac.vamsas.objects.utils.document.VersionEntries;\r
+\r
+import java.util.Hashtable;\r
+import java.util.zip.CRC32;\r
+\r
+/**\r
+ * Simplest VorbaId constructor\r
+ * \r
+ * @author jimp\r
+ * \r
+ */\r
+public class IdFactory extends VorbaIdFactory {\r
+ static Log log = LogFactory.getLog(IdFactory.class);\r
+\r
+ private SessionHandle session = null;\r
+\r
+ private ClientHandle client;\r
+\r
+ private UserHandle user;\r
+\r
+ private CRC32 unique = new CRC32(); // used to attempt a unique but\r
+ // predictable stream for IDs\r
+\r
+ private String idstring;\r
+\r
+ int sequence = 1; // incrementing value for next new ID\r
+\r
+ /**\r
+ * \r
+ */\r
+ public IdFactory() {\r
+ super();\r
+ // TODO Auto-generated constructor stub\r
+ }\r
+\r
+ /**\r
+ * @param session\r
+ * @param client\r
+ * @param user\r
+ */\r
+ protected IdFactory(SessionHandle session, ClientHandle client,\r
+ UserHandle user) {\r
+ super();\r
+ this.session = session;\r
+ this.client = client;\r
+ this.user = user;\r
+ unique.reset();\r
+ unique.update(new Object[] { session, client, user }.toString().getBytes());\r
+ // TODO: Ensure format of URNs and use standard composition methods.\r
+ idstring = client.getClientNCname() + "_" + unique.getValue() + ".";\r
+ extantids = new Hashtable();\r
+ this.extanthashv = new Hashtable();\r
+ }\r
+\r
+ /**\r
+ * Create IdFactory with existing object hashes and id set\r
+ * \r
+ * @param session\r
+ * @param client\r
+ * @param user\r
+ * @param extanthashv\r
+ * hash of existing VorbaIds from a previous read of same document\r
+ */\r
+ protected IdFactory(SessionHandle session, ClientHandle client,\r
+ UserHandle user, Hashtable extanthashv) {\r
+ this(session, client, user);\r
+ this.extanthashv = extanthashv;\r
+ }\r
+\r
+ /**\r
+ * values for keys in this hash can be used to reference the\r
+ * uk.ac.vamsas.client.Vobject instance for the VorbaId string.\r
+ * \r
+ * @return the hash of all VorbaIds\r
+ */\r
+ protected Hashtable getVorbaIdHash() {\r
+ return extantids;\r
+ }\r
+\r
+ /**\r
+ * values for keys in this hash are Vobjhash objects created for each Vobj\r
+ * with a VorbaId after this factory has been used to write a vamsas archive.\r
+ * \r
+ * @return the hash of all VorbaIds and their hash values.\r
+ */\r
+ protected Hashtable getVobjhashVals() {\r
+ return extanthashv;\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see uk.ac.vamsas.client.VorbaIdFactory#makeVorbaId()\r
+ */\r
+ public VorbaId makeVorbaId(Vobject vobject) {\r
+ if (session == null)\r
+ throw new Error(\r
+ "makeVorbaId called on improperly initialised IdFactory Vobject!");\r
+ if (!vobject.isRegisterable())\r
+ throw new Error("makeVorbaId called on unregisterable object.");\r
+ if (vobject.isRegistered())\r
+ throw new Error("makeVorbaId called on already registered object.");\r
+ String newidstring;\r
+ do {\r
+ if (sequence > 0) {\r
+ sequence++;\r
+ } else {\r
+ idstring += "1/";\r
+ sequence = 1;\r
+ }\r
+ newidstring = idstring + Integer.toString(sequence);\r
+ } while (extantids.containsKey(newidstring));\r
+ VorbaId id = newId(newidstring); // VorbaId.hash()==newidstring.hash() so we\r
+ // can still recover vobject\r
+ extantids.put(id, vobject); // hash the Vobject by its new Id\r
+ return id;\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see\r
+ * uk.ac.vamsas.client.VorbaIdFactory#setSession(uk.ac.vamsas.client.SessionHandle\r
+ * )\r
+ */\r
+ protected void setSession(SessionHandle sessionhandle) {\r
+ if (sessionhandle != null)\r
+ session = sessionhandle;\r
+ else\r
+ log.warn("setSession(null) called.");\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see uk.ac.vamsas.client.VorbaIdFactory#getSessionHandle()\r
+ */\r
+ public SessionHandle getSessionHandle() {\r
+ return session;\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see\r
+ * uk.ac.vamsas.client.VorbaIdFactory#setClient(uk.ac.vamsas.client.ClientHandle\r
+ * )\r
+ */\r
+ protected void setClient(ClientHandle appHandle) {\r
+ if (appHandle != null)\r
+ client = appHandle;\r
+ else\r
+ log.warn("setClient(null) called.");\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see uk.ac.vamsas.client.VorbaIdFactory#getClientHandle()\r
+ */\r
+ public ClientHandle getClientHandle() {\r
+ return client;\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see\r
+ * uk.ac.vamsas.client.VorbaIdFactory#setUser(uk.ac.vamsas.client.UserHandle)\r
+ */\r
+ protected void setUser(UserHandle userHandle) {\r
+ if (userHandle != null)\r
+ user = userHandle;\r
+ else\r
+ log.warn("setUser(null) called.");\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see uk.ac.vamsas.client.VorbaIdFactory#getUserHandle()\r
+ */\r
+ public UserHandle getUserHandle() {\r
+ return user;\r
+ }\r
+\r
+ /**\r
+ * Convenience method used for default behaviour in testing and any anonymous\r
+ * internal vamsasDocument unmarshalling\r
+ * \r
+ * @param clientname\r
+ * @return\r
+ */\r
+ protected static IdFactory getDummyFactory(String clientname) {\r
+ if (clientname == null)\r
+ clientname = "uk.ac.vamsas.client.simpleclient.IdFactory";\r
+ return new IdFactory(new SessionHandle("dummy.session"), new ClientHandle(\r
+ clientname, VersionEntries.latestVersion()), new UserHandle(clientname,\r
+ "Arnold User's Inc."));\r
+ }\r
+}\r