added legacy import of version 0.1 SessionLists
[vamsas.git] / src / uk / ac / vamsas / client / simpleclient / SessionsFile.java
index ab26d20..9871bbf 100644 (file)
@@ -26,6 +26,7 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;\r
 import java.io.ObjectInputStream;\r
 import java.io.ObjectOutputStream;\r
+import java.net.URL;\r
 \r
 import org.apache.commons.logging.Log;\r
 import org.apache.commons.logging.LogFactory;\r
@@ -80,7 +81,30 @@ public class SessionsFile extends ListFile {
           o = is.readObject();\r
           if (o != null) {\r
             try {\r
-              sessions = (SimpleSessionHandle[]) o;\r
+              if (o instanceof SimpleSessionHandle[]) {\r
+                sessions = (SimpleSessionHandle[]) o;\r
+              } else {\r
+                // legacy support or incorrect path.\r
+                if (o instanceof SessionHandle[]) {\r
+                  log.info("Importing VAMSAS 0.1 clientHandle list.");\r
+                  SessionHandle[] oldsess = (SessionHandle[]) o;\r
+                  File sessdir;\r
+                  sessions = new SimpleSessionHandle[oldsess.length];\r
+                  for (int s=0;s<oldsess.length;s++)\r
+                  {\r
+                    try {\r
+                      sessdir = new SessionUrn(oldsess[s].getSessionUrn()).asFile();\r
+                      // try to locate it.\r
+                      sessions[s] = new SimpleSessionHandle(oldsess[s].getSessionUrn(), sessdir);\r
+                    } catch (Exception e)\r
+                    {\r
+                      // give up and report an error.\r
+                      sessions = null;\r
+                      throw new Exception("Legacy SessionFile problem. Couldn't locate "+oldsess[s]+" as a file.",e);\r
+                    }\r
+                  }\r
+                }\r
+              }\r
             } catch (Exception e) {\r
               log.error("Garbage in the clientHandle list " + this.sessionFile,\r
                   e);\r