ac64f0e0c2ef4ffa4bdb66477da4f8f944569944
[vamsas.git] / src / uk / ac / vamsas / client / simpleclient / SessionUrn.java
1 package uk.ac.vamsas.client.simpleclient;
2
3 import java.io.File;
4 import java.net.URI;
5
6 import uk.ac.vamsas.client.InvalidSessionUrnException;
7
8 /**
9  * SessionUrn for simpleclient sessions:
10  * simpleclient://{Absolute path to session directory}
11  * 
12  * For simpleclient urn, it consideres as on the same machine, using the path to the session
13  *  directory to generate the session URN
14  * 
15  * @author jimp
16  *
17  */
18 public class SessionUrn extends uk.ac.vamsas.client.SessionUrn {
19   /**
20    * a simple client session urn prefix
21    */
22   public static final String SIMPLECLIENT="simpleclient";
23   public static String VAMSASDOCUMENT="vdoc";
24   static {
25     TYPES.put(SIMPLECLIENT, SessionUrn.class);
26     TYPES.put(SessionUrn.VAMSASDOCUMENT, SessionUrn.class);
27   }
28   
29   /**
30    * Creates a SessionUrn object from a String.
31    * The string must be a string representation of a URI
32    * @param urnString
33    * @throws InvalidSessionUrnException
34    */
35   public SessionUrn(String urnString) throws InvalidSessionUrnException
36     {
37       super();
38       this.setURN(urnString);
39     }
40   
41   
42   /**
43    * Generates a sessionURN bases on a session directory location
44    * 
45    * @param sessionLocation the file object to the session directory
46    */
47   public SessionUrn(File sessionLocation) 
48   {//throws MalformedURLException {
49   // TODO: LATER: implement switch to have vamsas document or simpleclient sessions for same constructor
50  //use URI instead of URL
51     super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURI());
52   }
53   
54   /**
55    * Generates a sessionURN bases on a vamsas session
56    * @param session a VamsasSession
57    * 
58    * Should return the same URN string than the creation with the session directory
59    */
60   public SessionUrn(VamsasSession session)
61   {
62     //throws MalformedURLException {
63     //  use URI instead of URL
64     super(SIMPLECLIENT, session.sessionDir.getAbsoluteFile().toURI());
65   }
66   
67   
68   
69
70
71   /**
72    * TODO: LATER: think about this again.
73    * 
74    * Retrieves the file associated to the current sessionURN.
75    * The sessionURN (URI) is based on the session directory absolute path.
76    * Use the raw path of the URN and change the scheme to file to generate a new file 
77    * URI. Then, from the URI create the File object (a File object  can be created from an uri)
78    * 
79    * @return File object representing the session URN //
80    * File(urn.getPath())
81    */
82   public File asFile() {
83     String path = this.urn.getRawPath();
84       
85      return   new File (  URI.create("file://"+path)); 
86   }
87   // TODO: add abstract 'handler' methods for resolving the URN to a particular class
88 }