2 * This file is part of the Vamsas Client version 0.2.
\r
3 * Copyright 2010 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;
\r
24 import java.net.URI;
\r
25 import java.util.Hashtable;
\r
28 * @author jimp base class for vamsas session/document types uses java.net.URI
\r
29 * internally for construction of URN
\r
31 public abstract class SessionUrn {
\r
35 * The types of URI protocols we understand
\r
37 protected static final Hashtable TYPES = new Hashtable();
\r
39 protected SessionUrn() {
\r
44 * construct urn for a locally stored session file
\r
49 protected SessionUrn(String type, java.net.URL url) {
\r
50 if (!TYPES.containsKey(type.toLowerCase()))
\r
51 throw new Error("Unknown " + this.getClass().getName() + " type '" + type
\r
52 + "' for URL '" + url + "'");
\r
55 this.setURN(type + "://" + url.getPath());
\r
56 // urn = URI.create(type+"://"+url.getPath());
\r
57 } catch (Exception e) {
\r
58 // TODO: something better than throwing an error should be done here.
\r
59 e.printStackTrace(System.err);
\r
64 protected SessionUrn(String type, URI uri) {
\r
65 if (!TYPES.containsKey(type.toLowerCase()))
\r
66 throw new Error("Unknown " + this.getClass().getName() + " type '" + type
\r
67 + "' for URI '" + uri + "'");
\r
69 // this.setURN(type+"://"+uri.getPath());
\r
70 // bad hack but should do the trick
\r
71 this.setURN(type + "://" + uri.getRawPath());
\r
72 } catch (Exception e) {
\r
73 // TODO: something better than throwing an error should be done here.
\r
74 e.printStackTrace(System.err);
\r
79 public String getSessionUrn() {
\r
80 return this.urn.toString();
\r
84 * Set the urn attribute create a URI from the provided String
\r
87 * urn to convert to a URN
\r
89 protected void setURN(String urnString) throws InvalidSessionUrnException// NullPointerException,
\r
90 // IllegalArgumentException
\r
93 this.urn = URI.create(urnString);
\r
94 } catch (Exception e) {
\r
95 throw new InvalidSessionUrnException(e);
\r