package uk.ac.vamsas.client.simpleclient;
import java.io.File;
-import java.net.MalformedURLException;
+import java.net.URI;
import uk.ac.vamsas.client.InvalidSessionUrnException;
/**
* SessionUrn for simpleclient sessions:
* simpleclient://{Absolute path to session directory}
+ *
+ * For simpleclient urn, it consideres as on the same machine, using the path to the session
+ * directory to generate the session URN
+ *
* @author jimp
*
*/
this.setURN(urnString);
}
- public SessionUrn(File sessionLocation) throws MalformedURLException {
+
+ /**
+ * Generates a sessionURN bases on a session directory location
+ *
+ * @param sessionLocation the file object to the session directory
+ */
+ public SessionUrn(File sessionLocation)
+ {//throws MalformedURLException {
// TODO: LATER: implement switch to have vamsas document or simpleclient sessions for same constructor
- super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURL());
- //else
- // super(VAMSASDOCUMENT, sessionLocation);
+ //use URI instead of URL
+ super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURI());
}
- public SessionUrn(VamsasSession session) throws MalformedURLException {
- super(SIMPLECLIENT, session.sessionDir.getAbsoluteFile().toURL());
- }
-
-
/**
- * @see uk.ac.vamsas.client.SessionUrn#setURN(java.lang.String)
+ * Generates a sessionURN bases on a vamsas session
+ * @param session a VamsasSession
+ *
+ * Should return the same URN string than the creation with the session directory
*/
- protected void setURN(String urnString) throws NullPointerException, IllegalArgumentException {
- super.setURN(urnString);
+ public SessionUrn(VamsasSession session)
+ {
+ //throws MalformedURLException {
+ // use URI instead of URL
+ super(SIMPLECLIENT, session.sessionDir.getAbsoluteFile().toURI());
}
+
+
+
+
/**
* TODO: LATER: think about this again.
- * @return File(urn.getPath())
+ *
+ * Retrieves the file associated to the current sessionURN.
+ * The sessionURN (URI) is based on the session directory absolute path.
+ * Use the raw path of the URN and change the scheme to file to generate a new file
+ * URI. Then, from the URI create the File object (a File object can be created from an uri)
+ *
+ * @return File object representing the session URN //
+ * File(urn.getPath())
*/
public File asFile() {
- String path = urn.getPath();
-
- if ("\\".equals(File.separator))
- {
- //remove last separator at last position if found
- if (path.charAt(path.length() - 1) == '/')path = path.substring(0, path.length() - 1);
- path = path.replaceAll("/", "\\\\");
- }
- int index = path.lastIndexOf(File.separator);
- /*don t remember why
- if (index >-1)
- {//separator found, keep last part of the urn - filename
- path = path.substring(index+1, path.length());
- }
- *yop
- */
- return new File(urn.getPath());
+ String path = this.urn.getRawPath();
+
+ return new File ( URI.create("file://"+path));
}
// TODO: add abstract 'handler' methods for resolving the URN to a particular class
}