From: pmarguerite Date: Thu, 14 Dec 2006 21:13:03 +0000 (+0000) Subject: SimpleClientFactory Added support to create a IClient for a given Session to a given... X-Git-Tag: Release_0.2~217 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=713910e1326aa59dc6e2150d0f870e4f3f4c9f11;p=vamsas.git SimpleClientFactory Added support to create a IClient for a given Session to a given session URN git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@303 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/uk/ac/vamsas/client/simpleclient/SimpleClientFactory.java b/src/uk/ac/vamsas/client/simpleclient/SimpleClientFactory.java index f3dfb52..f93fa28 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SimpleClientFactory.java +++ b/src/uk/ac/vamsas/client/simpleclient/SimpleClientFactory.java @@ -12,6 +12,7 @@ package uk.ac.vamsas.client.simpleclient; import java.io.File; import java.io.IOException; +import java.net.MalformedURLException; import org.apache.commons.logging.Log; @@ -125,7 +126,7 @@ public class SimpleClientFactory implements IClientFactory { if (sessionHandles != null) { sessions = new String[sessionHandles.length]; - for (int i = sessionHandles.length -1; i > 0; i--) + for (int i = sessionHandles.length -1; i > -1; i--) { SessionHandle sessionHandle = sessionHandles[i]; sessions [i] = sessionHandle.getSessionUrn(); @@ -135,11 +136,6 @@ public class SimpleClientFactory implements IClientFactory { return sessions; } - - private void discoverSession() - { - - } /** * @see uk.ac.vamsas.client.IClientFactory#getIClient(uk.ac.vamsas.client.ClientHandle) @@ -149,25 +145,79 @@ public class SimpleClientFactory implements IClientFactory { */ public IClient getIClient(ClientHandle applicationHandle) throws NoDefaultSessionException { - + // create a new session + // register new ClientHandle in session + // create SimpleClient instance return this.getIClient(applicationHandle, (UserHandle) null); } /** + * the URN should be something like simpleclient:FILEPATH URL encoded * @see uk.ac.vamsas.client.IClientFactory#getIClient(uk.ac.vamsas.client.ClientHandle, java.lang.String) */ public IClient getIClient(ClientHandle applicationHandle, String sessionUrn) { - // TODO Auto-generated method stub - return null; +// locate session from Urn + // check that clientHandle is unique (with default user) - if not update the clientHandle urn to make it unique. + // wait for lock and attach to session + // create SimpleClient instance + log.debug("Trying to create session with URN "+sessionUrn); + return this.getIClient(applicationHandle, null, sessionUrn); + } + private File convertSessionUrnToFile(String sessionUrn) throws InvalidSessionUrnException + { + if (sessionUrn == null) + { + log.debug("Incorrect URN: can not open session."); + throw new InvalidSessionUrnException(); + } + + SessionUrn urn = new SessionUrn(sessionUrn); + return urn.asFile(); + + } + /** * @see uk.ac.vamsas.client.IClientFactory#getIClient(uk.ac.vamsas.client.ClientHandle, uk.ac.vamsas.client.UserHandle, java.lang.String) */ public IClient getIClient(ClientHandle applicationHandle, UserHandle userId, String sessionUrn) { - // TODO Auto-generated method stub - return null; +// locate session from Urn + // check Uniqueness of user + ClientHandle in the session. Update clientHandle urn accordingly. + // wait for lock, attach to session + // create client instance + SimpleClient client = null; + + try { + File sessionDirectory = this.convertSessionUrnToFile(sessionUrn); + //create session + log.debug("found session directory "+sessionDirectory.getAbsolutePath()); + VamsasSession vamsasSession = new VamsasSession(sessionDirectory); + + if (userId == null) + { + //create a default userHandle + //with current OS user and hostname + userId = new UserHandle(System.getProperty("user.name", System.getProperty("USERNAME","Joe Doe")), + System.getProperty("host.name",System.getProperty("HOSTNAME", "Unknown") ));// clientName, clientVersion, sessionPath); + } + + + //create simple client + client = new SimpleClient(userId, applicationHandle, vamsasSession); + } catch (MalformedURLException e) { + log.error("error while creating new IClient: incorrect session urn",e); + client = null; + + } catch (InvalidSessionUrnException e) { + log.error("error while creating new IClient: incorrect session urn",e); + client = null; + } catch (IOException e) { + log.error("error while creating new IClient: file access error",e); + client = null; + } + return client; } /** @@ -175,6 +225,9 @@ public class SimpleClientFactory implements IClientFactory { */ public IClient getIClient(ClientHandle applicationHandle, UserHandle userId) throws NoDefaultSessionException { + // create new session + // register SimpleClient and UserHandles in session + // create client instance SimpleClient client = null; if (this.sessionArena==null) throw new Error("Improperly initialised SimpleClientFactory object - null sessionArena.");