import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
import org.apache.commons.logging.Log;
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();
return sessions;
}
-
- private void discoverSession()
- {
-
- }
/**
* @see uk.ac.vamsas.client.IClientFactory#getIClient(uk.ac.vamsas.client.ClientHandle)
*/
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;
}
/**
*/
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.");