X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fuk%2Fac%2Fvamsas%2Fclient%2FSessionUrn.java;h=66b73c33d85e299bb0032e05d59788c062249cb9;hb=de9546f3a8c5d8b7f0bc93c98a8a94aa518c7439;hp=519c287fc6b40ba8a75062eb821b8d803cb3ceb0;hpb=ea8b10ee787a2b1e2b35f2acb4dccaf12fd2a6fd;p=vamsas.git diff --git a/src/uk/ac/vamsas/client/SessionUrn.java b/src/uk/ac/vamsas/client/SessionUrn.java index 519c287..66b73c3 100644 --- a/src/uk/ac/vamsas/client/SessionUrn.java +++ b/src/uk/ac/vamsas/client/SessionUrn.java @@ -5,7 +5,6 @@ package uk.ac.vamsas.client; import java.net.URI; import java.util.Hashtable; -import java.util.Vector; /** * @author jimp @@ -19,6 +18,11 @@ public abstract class SessionUrn { */ protected static final Hashtable TYPES=new Hashtable(); + + protected SessionUrn() + { + // + } /** * construct urn for a locally stored session file * @param type @@ -28,13 +32,47 @@ 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+"://"+url.getPath()); + + this.setURN(type+"://"+url.getPath()); + // urn = URI.create(type+"://"+url.getPath()); } catch (Exception e) { // TODO: something better than throwing an error should be done here. + e.printStackTrace(System.err); 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 urn.toString(); + return this.urn.toString(); } + + /** + * 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 InvalidSessionUrnException// NullPointerException, IllegalArgumentException + { + try { + this.urn = URI.create(urnString); + } catch (Exception e) { + throw new InvalidSessionUrnException(e); + } + } + }