From: jprocter Date: Mon, 8 Jun 2009 12:30:03 +0000 (+0000) Subject: locate first session or sessions for a given URN X-Git-Tag: Release_0.2~18 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=5973bb590fb78f2a3b05f9ba96f6f76f790092c5;p=vamsas.git locate first session or sessions for a given URN git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@503 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/uk/ac/vamsas/client/simpleclient/SimpleSessionManager.java b/src/uk/ac/vamsas/client/simpleclient/SimpleSessionManager.java index ea5fb60..2c562d1 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SimpleSessionManager.java +++ b/src/uk/ac/vamsas/client/simpleclient/SimpleSessionManager.java @@ -23,9 +23,11 @@ package uk.ac.vamsas.client.simpleclient; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import uk.ac.vamsas.client.SessionHandle; + /** * Class to deal with sessions * @@ -69,17 +71,45 @@ public class SimpleSessionManager { public String[] getCurrentSessions() { String[] sessions = null; if (this.sessionFile != null) { - SessionHandle[] sessionHandles = this.sessionFile.retrieveSessionsList(); + SimpleSessionHandle[] sessionHandles = this.sessionFile.retrieveSessionsList(); if (sessionHandles != null) { sessions = new String[sessionHandles.length]; for (int i = sessionHandles.length - 1; i > -1; i--) { - SessionHandle sessionHandle = sessionHandles[i]; + SimpleSessionHandle sessionHandle = sessionHandles[i]; sessions[i] = sessionHandle.getSessionUrn(); } } } return sessions; } + /** + * recover session(s) corresponding to SessionUrn + * @param urn + * @return null, or one or more SimpleSessionHandle objects with the given sessionUrn + */ + public SimpleSessionHandle[] getSessionFor(SessionUrn urn) { + ArrayList sessions=new ArrayList(); + if (sessionFile != null) { + SessionHandle pattern = new SessionHandle(urn.getSessionUrn()); + SimpleSessionHandle[] sessionHandles = sessionFile.retrieveSessionsList(); + if (sessionHandles != null) { + for (int i = sessionHandles.length - 1; i > -1; i--) { + SimpleSessionHandle sessionHandle = sessionHandles[i]; + if (sessionHandle.equals(pattern)) + { + sessions.add(sessionHandle); + } + } + } + } + if (sessions.size()>0) + { + SimpleSessionHandle[] sh = new SimpleSessionHandle[sessions.size()]; + sessions.toArray(sh); + return sh; + } + return null; + } /** * adds SessionHandle me to the sessionList @@ -89,7 +119,7 @@ public class SimpleSessionManager { * @return session index in list or 0 if lock was invalid or addSession * operation failed. */ - public int addSession(SessionHandle newSession) { + public int addSession(SimpleSessionHandle newSession) { return this.sessionFile.addSession(newSession, false, this .getSessionsWatcher().getChangedState()); } @@ -108,7 +138,7 @@ public class SimpleSessionManager { * SessionHandle of the session to remove */ protected void removeSession(SessionHandle session) { - this.getSessionFile().removeSession(session, + getSessionFile().removeSession(session, this.getSessionsWatcher().getChangedState()); } }