1 package uk.ac.vamsas.client.simpleclient;
4 import java.net.MalformedURLException;
7 import uk.ac.vamsas.client.InvalidSessionUrnException;
10 * SessionUrn for simpleclient sessions:
11 * simpleclient://{Absolute path to session directory}
15 public class SessionUrn extends uk.ac.vamsas.client.SessionUrn {
17 * a simple client session urn prefix
19 public static final String SIMPLECLIENT="simpleclient";
20 public static String VAMSASDOCUMENT="vdoc";
22 TYPES.put(SIMPLECLIENT, SessionUrn.class);
23 TYPES.put(SessionUrn.VAMSASDOCUMENT, SessionUrn.class);
27 * Creates a SessionUrn object from a String.
28 * The string must be a string representation of a URI
30 * @throws InvalidSessionUrnException
32 public SessionUrn(String urnString) throws InvalidSessionUrnException
35 this.setURN(urnString);
40 public SessionUrn(File sessionLocation) throws MalformedURLException {
41 // TODO: LATER: implement switch to have vamsas document or simpleclient sessions for same constructor
42 // super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURL());
43 // super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURL());
44 super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURI());
46 // super(VAMSASDOCUMENT, sessionLocation);
48 public SessionUrn(VamsasSession session) throws MalformedURLException {
49 super(SIMPLECLIENT, session.sessionDir.getAbsoluteFile().toURL());
55 * @see uk.ac.vamsas.client.SessionUrn#setURN(java.lang.String)
57 protected void setURN(String urnString) throws NullPointerException, IllegalArgumentException {
58 super.setURN(urnString);
62 * TODO: LATER: think about this again.
63 * @return File(urn.getPath())
65 public File asFile() {
66 String path = this.urn.getRawPath();
68 /*if ("\\".equals(File.separator))
70 //remove last separator at last position if found
71 /* not needed anymore if (path.charAt(path.length() - 1) == '/')path = path.substring(0, path.length() - 1);
72 path = path.replaceAll("/", "\\\\");
75 /* int index = path.indexOf(File.separator);
78 {//separator found, keep last part of the urn - filename
79 path = path.substring(index+1, path.length());
81 //remove encoded space character
82 // path = path.replaceAll("%20", " ");
84 /*shall we use URI or String to create the object*/
85 /* from URI : URI.create("file://path") , but first / */
86 /* return new File(path);*/
87 return new File ( URI.create("file://"+path));
89 // TODO: add abstract 'handler' methods for resolving the URN to a particular class