X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fuk%2Fac%2Fvamsas%2Fclient%2Fsimpleclient%2FVamsasSession.java;fp=src%2Fuk%2Fac%2Fvamsas%2Fclient%2Fsimpleclient%2FVamsasSession.java;h=ffbdfa6b1e281cc1b8a516af6039301efa663651;hb=2e9acb15a289a317f04e6161bace75de35884e01;hp=310c6c285595d007b187325eb905e5cef69a8a75;hpb=55647a12bfb993e625980ab8c1b1e49043079c3b;p=vamsas.git diff --git a/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java b/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java index 310c6c2..ffbdfa6 100644 --- a/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java +++ b/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java @@ -35,6 +35,7 @@ import org.apache.log4j.PatternLayout; import uk.ac.vamsas.client.ClientHandle; import uk.ac.vamsas.client.Events; +import uk.ac.vamsas.client.InvalidSessionUrnException; import uk.ac.vamsas.client.UserHandle; /** @@ -228,6 +229,23 @@ public class VamsasSession { * new data into session in this way) */ protected VamsasSession(File sessionDir1, File extVamDoc) throws IOException { + this(sessionDir1,extVamDoc,null); + } + /** + * sets up the vamsas session files and watchers in sessionDir1 + * + * @param sessionDir1 + * @param extVamDoc + * null or an existing archive to initialise the session with + * @param preferredName - optional string to use to generate a new session URI + * @throws any + * IOExceptions from creating session directory and files. + * @throws error + * if both extVamDoc and sessionDir1 already exist (cannot import + * new data into session in this way) + * MalformedURI if preferredName cannot be used to derive a URI of the form simpleclient::preferredName + */ + public VamsasSession(File sessionDir1, File extVamDoc, String preferredName) throws IOException { // TODO: refactor to separate extVamDoc path from session URN - enables non-local URLs to be locally bound to sessions. if (sessionDir1 == null) throw new Error("Null directory for VamsasSession."); @@ -250,12 +268,21 @@ public class VamsasSession { } } this.sessionDir = sessionDir1; - if (extVamDoc==null) { - sessionHandle = new SimpleSessionHandle(new SessionUrn(sessionDir).getSessionUrn(),sessionDir); - } else { + // construct session URN + SessionUrn sessUrn = new SessionUrn(sessionDir); + if (extVamDoc!=null) { // Construct Session URN from the original vamsas document. - sessionHandle = new SimpleSessionHandle(new SessionUrn(extVamDoc).getSessionUrn(),sessionDir); + sessUrn = new SessionUrn(extVamDoc); } + if (preferredName!=null) { + try { + sessUrn = new SessionUrn(preferredName); + } catch (InvalidSessionUrnException e) { + throw new Error("Malformed URI : preferredName = "+preferredName,e); + } + } + // create the session handle + sessionHandle = new SimpleSessionHandle(sessUrn.getSessionUrn(),sessionDir); initSessionObjects(); if (existingSession) { slog.debug("Initialising additional VamsasSession instance"); @@ -271,6 +298,7 @@ public class VamsasSession { log.debug("Initialised VamsasSession in " + sessionDir1); } + /** * tests presence of existing sessionfiles files in dir *