4 package uk.ac.vamsas.client;
8 import java.util.Hashtable;
9 import java.util.Vector;
13 * base class for vamsas session/document types
14 * uses java.net.URI internally for construction of URN
16 public abstract class SessionUrn {
19 * The types of URI protocols we understand
21 protected static final Hashtable TYPES=new Hashtable();
24 protected SessionUrn()
29 * construct urn for a locally stored session file
33 protected SessionUrn(String type, java.net.URL url) {
34 if (!TYPES.containsKey(type.toLowerCase()))
35 throw new Error("Unknown "+this.getClass().getName()+" type '"+type+"' for URL '"+url+"'");
38 this.setURN(type+"://"+url.getPath());
39 // urn = URI.create(type+"://"+url.getPath());
40 } catch (Exception e) {
41 // TODO: something better than throwing an error should be done here.
42 e.printStackTrace(System.err);
47 protected SessionUrn(String type, URI uri) {
48 if (!TYPES.containsKey(type.toLowerCase()))
49 throw new Error("Unknown "+this.getClass().getName()+" type '"+type+"' for URI '"+uri+"'");
51 // this.setURN(type+"://"+uri.getPath());
52 //bad hack but should do the trick
53 this.setURN(type+"://"+uri.getRawPath());
54 } catch (Exception e) {
55 // TODO: something better than throwing an error should be done here.
56 e.printStackTrace(System.err);
61 public String getSessionUrn() {
62 return this.urn.toString();
67 * create a URI from the provided String
69 * @param urnString urn to convert to a URN
71 protected void setURN(String urnString) throws NullPointerException, IllegalArgumentException
73 this.urn = URI.create(urnString);