update detection mechanism based comparing the difference between the position of...
[vamsas.git] / src / uk / ac / vamsas / client / SessionUrn.java
index 158389c..66b73c3 100644 (file)
@@ -3,10 +3,8 @@
  */
 package uk.ac.vamsas.client;
 
-import java.io.File;
 import java.net.URI;
 import java.util.Hashtable;
-import java.util.Vector;
 
 /**
  * @author jimp
@@ -34,7 +32,7 @@ public abstract class SessionUrn {
     if (!TYPES.containsKey(type.toLowerCase()))
       throw new Error("Unknown "+this.getClass().getName()+" type '"+type+"' for URL '"+url+"'");
     try {
-      //urn = URI.create(type+"://"+urlString);
+      
         this.setURN(type+"://"+url.getPath());
     //  urn = URI.create(type+"://"+url.getPath());
     } catch (Exception e) {
@@ -43,19 +41,38 @@ public abstract class SessionUrn {
       throw new Error(e);
     }
   }
+  
+  protected SessionUrn(String type, URI uri) {
+    if (!TYPES.containsKey(type.toLowerCase()))
+      throw new Error("Unknown "+this.getClass().getName()+" type '"+type+"' for URI '"+uri+"'");
+    try {
+      //  this.setURN(type+"://"+uri.getPath());
+      //bad hack but should do the trick
+      this.setURN(type+"://"+uri.getRawPath());
+   } catch (Exception e) {
+      // TODO: something better than throwing an error should be done here.
+      e.printStackTrace(System.err);
+      throw new Error(e);
+    }
+  }
+  
   public String getSessionUrn() {
     return this.urn.toString();
   }
   
   /**
-   * Set arun attribute
+   * Set the urn attribute
    * create a URI from the provided String
    * 
    * @param urnString urn to convert to a URN
    */
-  protected void setURN(String urnString) throws     NullPointerException, IllegalArgumentException 
+  protected void setURN(String urnString) throws    InvalidSessionUrnException// NullPointerException, IllegalArgumentException 
     {
-      this.urn = URI.create(urnString);
+      try {
+        this.urn = URI.create(urnString);
+      } catch (Exception e) {
+        throw new InvalidSessionUrnException(e);
+      }
     }
   
 }