applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / client / simpleclient / SessionUrn.java
1 /*\r
2  * This file is part of the Vamsas Client version 0.1. \r
3  * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, \r
4  *  Andrew Waterhouse and Dominik Lindner.\r
5  * \r
6  * Earlier versions have also been incorporated into Jalview version 2.4 \r
7  * since 2008, and TOPALi version 2 since 2007.\r
8  * \r
9  * The Vamsas Client is free software: you can redistribute it and/or modify\r
10  * it under the terms of the GNU Lesser General Public License as published by\r
11  * the Free Software Foundation, either version 3 of the License, or\r
12  * (at your option) any later version.\r
13  *  \r
14  * The Vamsas Client is distributed in the hope that it will be useful,\r
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
17  * GNU Lesser General Public License for more details.\r
18  * \r
19  * You should have received a copy of the GNU Lesser General Public License\r
20  * along with the Vamsas Client.  If not, see <http://www.gnu.org/licenses/>.\r
21  */\r
22 package uk.ac.vamsas.client.simpleclient;\r
23 \r
24 import java.io.File;\r
25 import java.net.URI;\r
26 \r
27 import uk.ac.vamsas.client.InvalidSessionUrnException;\r
28 \r
29 /**\r
30  * SessionUrn for simpleclient sessions: simpleclient://{Absolute path to\r
31  * session directory}\r
32  * \r
33  * For simpleclient urn, it consideres as on the same machine, using the path to\r
34  * the session directory to generate the session URN\r
35  * \r
36  * @author jimp\r
37  * \r
38  */\r
39 public class SessionUrn extends uk.ac.vamsas.client.SessionUrn {\r
40   /**\r
41    * a simple client session urn prefix\r
42    */\r
43   public static final String SIMPLECLIENT = "simpleclient";\r
44 \r
45   public static String VAMSASDOCUMENT = "vdoc";\r
46   static {\r
47     TYPES.put(SIMPLECLIENT, SessionUrn.class);\r
48     TYPES.put(SessionUrn.VAMSASDOCUMENT, SessionUrn.class);\r
49   }\r
50 \r
51   /**\r
52    * Creates a SessionUrn object from a String. The string must be a string\r
53    * representation of a URI\r
54    * \r
55    * @param urnString\r
56    * @throws InvalidSessionUrnException\r
57    */\r
58   public SessionUrn(String urnString) throws InvalidSessionUrnException {\r
59     super();\r
60     this.setURN(urnString);\r
61   }\r
62 \r
63   /**\r
64    * Generates a sessionURN bases on a session directory location\r
65    * \r
66    * @param sessionLocation\r
67    *          the file object to the session directory\r
68    */\r
69   public SessionUrn(File sessionLocation) {// throws MalformedURLException {\r
70     // TODO: LATER: implement switch to have vamsas document or simpleclient\r
71     // sessions for same constructor\r
72     // use URI instead of URL\r
73     super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURI());\r
74   }\r
75 \r
76   /**\r
77    * Generates a sessionURN bases on a vamsas session\r
78    * \r
79    * @param session\r
80    *          a VamsasSession\r
81    * \r
82    *          Should return the same URN string than the creation with the\r
83    *          session directory\r
84    */\r
85   public SessionUrn(VamsasSession session) {\r
86     // throws MalformedURLException {\r
87     // use URI instead of URL\r
88     super(SIMPLECLIENT, session.sessionDir.getAbsoluteFile().toURI());\r
89   }\r
90 \r
91   /**\r
92    * TODO: LATER: think about this again.\r
93    * \r
94    * Retrieves the file associated to the current sessionURN. The sessionURN\r
95    * (URI) is based on the session directory absolute path. Use the raw path of\r
96    * the URN and change the scheme to file to generate a new file URI. Then,\r
97    * from the URI create the File object (a File object can be created from an\r
98    * uri)\r
99    * \r
100    * @return File object representing the session URN // File(urn.getPath())\r
101    */\r
102   public File asFile() {\r
103     String path = this.urn.getRawPath();\r
104 \r
105     return new File(URI.create("file://" + path));\r
106   }\r
107   // TODO: add abstract 'handler' methods for resolving the URN to a particular\r
108   // class\r
109 }\r