created setURN to generated sessionUrn from a urn as String. Allow to be replaced...
[vamsas.git] / src / uk / ac / vamsas / client / SessionUrn.java
1 /**
2  * 
3  */
4 package uk.ac.vamsas.client;
5
6 import java.io.File;
7 import java.net.URI;
8 import java.util.Hashtable;
9 import java.util.Vector;
10
11 /**
12  * @author jimp
13  * base class for vamsas session/document types
14  * uses java.net.URI internally for construction of URN
15  */
16 public abstract class SessionUrn {
17   protected URI urn;
18   /**
19    * The types of URI protocols we understand
20    */
21   protected static final Hashtable TYPES=new Hashtable();
22   
23   
24   protected SessionUrn()
25   {
26     //
27   }
28   /**
29    * construct urn for a locally stored session file
30    * @param type
31    * @param url
32    */
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+"'");
36     try {
37       //urn = URI.create(type+"://"+urlString);
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);
43       throw new Error(e);
44     }
45   }
46   public String getSessionUrn() {
47     return this.urn.toString();
48   }
49   
50   /**
51    * Set arun attribute
52    * create a URI from the provided String
53    * 
54    * @param urnString urn to convert to a URN
55    */
56   protected void setURN(String urnString) throws     NullPointerException, IllegalArgumentException 
57     {
58       this.urn = URI.create(urnString);
59     }
60   
61 }