4 package uk.ac.vamsas.client;
7 import java.util.Hashtable;
11 * base class for vamsas session/document types
12 * uses java.net.URI internally for construction of URN
14 public abstract class SessionUrn {
17 * The types of URI protocols we understand
19 protected static final Hashtable TYPES=new Hashtable();
22 protected SessionUrn()
27 * construct urn for a locally stored session file
31 protected SessionUrn(String type, java.net.URL url) {
32 if (!TYPES.containsKey(type.toLowerCase()))
33 throw new Error("Unknown "+this.getClass().getName()+" type '"+type+"' for URL '"+url+"'");
36 this.setURN(type+"://"+url.getPath());
37 // urn = URI.create(type+"://"+url.getPath());
38 } catch (Exception e) {
39 // TODO: something better than throwing an error should be done here.
40 e.printStackTrace(System.err);
45 protected SessionUrn(String type, URI uri) {
46 if (!TYPES.containsKey(type.toLowerCase()))
47 throw new Error("Unknown "+this.getClass().getName()+" type '"+type+"' for URI '"+uri+"'");
49 // this.setURN(type+"://"+uri.getPath());
50 //bad hack but should do the trick
51 this.setURN(type+"://"+uri.getRawPath());
52 } catch (Exception e) {
53 // TODO: something better than throwing an error should be done here.
54 e.printStackTrace(System.err);
59 public String getSessionUrn() {
60 return this.urn.toString();
64 * Set the urn attribute
65 * create a URI from the provided String
67 * @param urnString urn to convert to a URN
69 protected void setURN(String urnString) throws InvalidSessionUrnException// NullPointerException, IllegalArgumentException
72 this.urn = URI.create(urnString);
73 } catch (Exception e) {
74 throw new InvalidSessionUrnException(e);