-/*
-* VAMSAS Project
-*
-* Dec 15, 2006
-*
-*/
-
-package uk.ac.vamsas.client.simpleclient;
-
-import java.io.File;
-import java.io.IOException;
-
-import uk.ac.vamsas.client.SessionHandle;
-
-/**
- * Class to deal with sessions
- *
- * retrieves list of available sessions
- *
- * adds an active session
- *
- * removes a close session (the last client has been closed)
- *
- *
- */
-public class SimpleSessionManager
-{
- private SessionsFile sessionFile = null;
-
-
- protected SimpleSessionManager(File sessionsFile) throws IOException
- {
- this.initManagerObjects(sessionsFile);
- }
-
-/**
- * construct SessionFile objects and watchers for each
- */
-private void initManagerObjects(File sessionsFile) throws IOException
- {
- if (this.sessionFile!=null )
- throw new IOException("initFactoryObjects called for initialised ClientFactory object.");
- this.sessionFile = new SessionsFile(sessionsFile);
- }
-
-
-/**
- * make a new watcher object for the sessionsFile
- * @return new SessionsFile watcher instance
- */
-public FileWatcher getSessionsWatcher() {
- return new FileWatcher(this.getSessionFile().sessionFile);
-}
-
-/**
- * @see uk.ac.vamsas.client.IClientFactory#getCurrentSessions()
- */
-public String[] getCurrentSessions()
-{
- String[] sessions = null;
- if (this.sessionFile!=null )
- {
- SessionHandle[] 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];
- sessions [i] = sessionHandle.getSessionUrn();
- }
- }
- }
- return sessions;
-}
-
-/**
- * adds SessionHandle me to the sessionList
- * @param newSession session to add to the session list
- * @return session index in list or 0 if lock was invalid or addSession operation failed.
- */
-public int addSession(SessionHandle newSession)
- {
- return this.sessionFile.addSession(newSession, false,this.getSessionsWatcher().getChangedState());
- }
-
-/**
- * @return the sessionFile
- */
-private SessionsFile getSessionFile()
- {
- return this.sessionFile;
- }
-
-/**
- * Removes a session from the list of currently active session
- *
- * @param session SessionHandle of the session to remove
- */
-protected void removeSession(SessionHandle session)
- {
- this.getSessionFile().removeSession(session,this.getSessionsWatcher().getChangedState());
- }
-}
-
-
+/*\r
+ * This file is part of the Vamsas Client version 0.1. \r
+ * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, \r
+ * Andrew Waterhouse and Dominik Lindner.\r
+ * \r
+ * Earlier versions have also been incorporated into Jalview version 2.4 \r
+ * since 2008, and TOPALi version 2 since 2007.\r
+ * \r
+ * The Vamsas Client is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Lesser General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ * \r
+ * The Vamsas Client is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Lesser General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU Lesser General Public License\r
+ * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package uk.ac.vamsas.client.simpleclient;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+import uk.ac.vamsas.client.SessionHandle;\r
+\r
+/**\r
+ * Class to deal with sessions\r
+ * \r
+ * retrieves list of available sessions\r
+ * \r
+ * adds an active session\r
+ * \r
+ * removes a close session (the last client has been closed)\r
+ * \r
+ * \r
+ */\r
+public class SimpleSessionManager {\r
+ private SessionsFile sessionFile = null;\r
+\r
+ protected SimpleSessionManager(File sessionsFile) throws IOException {\r
+ this.initManagerObjects(sessionsFile);\r
+ }\r
+\r
+ /**\r
+ * construct SessionFile objects and watchers for each\r
+ */\r
+ private void initManagerObjects(File sessionsFile) throws IOException {\r
+ if (this.sessionFile != null)\r
+ throw new IOException(\r
+ "initFactoryObjects called for initialised ClientFactory object.");\r
+ this.sessionFile = new SessionsFile(sessionsFile);\r
+ }\r
+\r
+ /**\r
+ * make a new watcher object for the sessionsFile\r
+ * \r
+ * @return new SessionsFile watcher instance\r
+ */\r
+ public FileWatcher getSessionsWatcher() {\r
+ return new FileWatcher(this.getSessionFile().sessionFile);\r
+ }\r
+\r
+ /**\r
+ * @see uk.ac.vamsas.client.IClientFactory#getCurrentSessions()\r
+ */\r
+ public String[] getCurrentSessions() {\r
+ String[] sessions = null;\r
+ if (this.sessionFile != null) {\r
+ SessionHandle[] 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
+ sessions[i] = sessionHandle.getSessionUrn();\r
+ }\r
+ }\r
+ }\r
+ return sessions;\r
+ }\r
+\r
+ /**\r
+ * adds SessionHandle me to the sessionList\r
+ * \r
+ * @param newSession\r
+ * session to add to the session list\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
+ return this.sessionFile.addSession(newSession, false, this\r
+ .getSessionsWatcher().getChangedState());\r
+ }\r
+\r
+ /**\r
+ * @return the sessionFile\r
+ */\r
+ private SessionsFile getSessionFile() {\r
+ return this.sessionFile;\r
+ }\r
+\r
+ /**\r
+ * Removes a session from the list of currently active session\r
+ * \r
+ * @param session\r
+ * SessionHandle of the session to remove\r
+ */\r
+ protected void removeSession(SessionHandle session) {\r
+ this.getSessionFile().removeSession(session,\r
+ this.getSessionsWatcher().getChangedState());\r
+ }\r
+}\r