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
6 * Earlier versions have also been incorporated into Jalview version 2.4
\r
7 * since 2008, and TOPALi version 2 since 2007.
\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
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
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
22 package uk.ac.vamsas.client.simpleclient;
\r
24 import java.io.File;
\r
25 import java.net.URI;
\r
27 import uk.ac.vamsas.client.InvalidSessionUrnException;
\r
30 * SessionUrn for simpleclient sessions: simpleclient://{Absolute path to
\r
31 * session directory}
\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
39 public class SessionUrn extends uk.ac.vamsas.client.SessionUrn {
\r
41 * a simple client session urn prefix
\r
43 public static final String SIMPLECLIENT = "simpleclient";
\r
45 public static String VAMSASDOCUMENT = "vdoc";
\r
47 TYPES.put(SIMPLECLIENT, SessionUrn.class);
\r
48 TYPES.put(SessionUrn.VAMSASDOCUMENT, SessionUrn.class);
\r
52 * Creates a SessionUrn object from a String. The string must be a string
\r
53 * representation of a URI
\r
56 * @throws InvalidSessionUrnException
\r
58 public SessionUrn(String urnString) throws InvalidSessionUrnException {
\r
60 this.setURN(urnString);
\r
64 * Generates a sessionURN from a file with a type of SIMPLECLIENT if it is a directory or VAMSASDOCUMENT if it is a file.
\r
66 * Note: No validation is performed, either for uniqueness of resultant URI or validity of the location.
\r
68 * @param sessionLocation
\r
69 * the file object to create the sessionURN from.
\r
72 public SessionUrn(File sessionLocation) {
\r
73 // TODO: refactor this and use a Urn factory - this inline switch is pretty ugly!
\r
74 super((sessionLocation.isFile() ? VAMSASDOCUMENT : SIMPLECLIENT)
\r
75 ,sessionLocation.getAbsoluteFile().toURI());
\r
79 * Generates a sessionURN bases on a vamsas session
\r
84 * Should return the same URN string than the creation with the
\r
87 public SessionUrn(VamsasSession session) {
\r
88 // throws MalformedURLException {
\r
89 // use URI instead of URL
\r
90 super(SIMPLECLIENT, session.sessionDir.getAbsoluteFile().toURI());
\r
94 * TODO: LATER: think about this again.
\r
96 * Retrieves the file associated to the current sessionURN. The sessionURN
\r
97 * (URI) is based on the session directory absolute path. Use the raw path of
\r
98 * the URN and change the scheme to file to generate a new file URI. Then,
\r
99 * from the URI create the File object (a File object can be created from an
\r
102 * @return File object representing the session URN // File(urn.getPath())
\r
104 public File asFile() {
\r
105 String path = this.urn.getRawPath();
\r
107 return new File(URI.create("file://" + path));
\r
109 // TODO: add abstract 'handler' methods for resolving the URN to a particular
\r