\r
import java.io.File;\r
import java.io.IOException;\r
+import java.util.ArrayList;\r
\r
import uk.ac.vamsas.client.SessionHandle;\r
\r
+\r
/**\r
* Class to deal with sessions\r
* \r
public String[] getCurrentSessions() {\r
String[] sessions = null;\r
if (this.sessionFile != null) {\r
- SessionHandle[] sessionHandles = this.sessionFile.retrieveSessionsList();\r
+ SimpleSessionHandle[] sessionHandles = this.sessionFile.retrieveSessionsList();\r
if (sessionHandles != null) {\r
sessions = new String[sessionHandles.length];\r
for (int i = sessionHandles.length - 1; i > -1; i--) {\r
- SessionHandle sessionHandle = sessionHandles[i];\r
+ SimpleSessionHandle sessionHandle = sessionHandles[i];\r
sessions[i] = sessionHandle.getSessionUrn();\r
}\r
}\r
}\r
return sessions;\r
}\r
+ /**\r
+ * recover session(s) corresponding to SessionUrn\r
+ * @param urn\r
+ * @return null, or one or more SimpleSessionHandle objects with the given sessionUrn\r
+ */\r
+ public SimpleSessionHandle[] getSessionFor(SessionUrn urn) {\r
+ ArrayList sessions=new ArrayList();\r
+ if (sessionFile != null) {\r
+ SessionHandle pattern = new SessionHandle(urn.getSessionUrn());\r
+ SimpleSessionHandle[] sessionHandles = sessionFile.retrieveSessionsList();\r
+ if (sessionHandles != null) {\r
+ for (int i = sessionHandles.length - 1; i > -1; i--) {\r
+ SimpleSessionHandle sessionHandle = sessionHandles[i];\r
+ if (sessionHandle.equals(pattern))\r
+ {\r
+ sessions.add(sessionHandle);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ if (sessions.size()>0)\r
+ {\r
+ SimpleSessionHandle[] sh = new SimpleSessionHandle[sessions.size()];\r
+ sessions.toArray(sh);\r
+ return sh;\r
+ }\r
+ return null;\r
+ }\r
\r
/**\r
* adds SessionHandle me to the sessionList\r
* @return session index in list or 0 if lock was invalid or addSession\r
* operation failed.\r
*/\r
- public int addSession(SessionHandle newSession) {\r
+ public int addSession(SimpleSessionHandle newSession) {\r
return this.sessionFile.addSession(newSession, false, this\r
.getSessionsWatcher().getChangedState());\r
}\r
* SessionHandle of the session to remove\r
*/\r
protected void removeSession(SessionHandle session) {\r
- this.getSessionFile().removeSession(session,\r
+ getSessionFile().removeSession(session,\r
this.getSessionsWatcher().getChangedState());\r
}\r
}\r