X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fuk%2Fac%2Fvamsas%2Fclient%2Fsimpleclient%2FSessionUrn.java;h=ac64f0e0c2ef4ffa4bdb66477da4f8f944569944;hb=1e940bf58bbd9f228ff991b5ee6e5b38c36a78fe;hp=dfcd5b3bdf5138a44c206bdcde8e723f23d75945;hpb=ea8b10ee787a2b1e2b35f2acb4dccaf12fd2a6fd;p=vamsas.git diff --git a/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java b/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java index dfcd5b3..ac64f0e 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java +++ b/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java @@ -1,11 +1,17 @@ package uk.ac.vamsas.client.simpleclient; import java.io.File; -import java.net.MalformedURLException; +import java.net.URI; + +import uk.ac.vamsas.client.InvalidSessionUrnException; /** * SessionUrn for simpleclient sessions: * simpleclient://{Absolute path to session directory} + * + * For simpleclient urn, it consideres as on the same machine, using the path to the session + * directory to generate the session URN + * * @author jimp * */ @@ -20,21 +26,63 @@ public class SessionUrn extends uk.ac.vamsas.client.SessionUrn { TYPES.put(SessionUrn.VAMSASDOCUMENT, SessionUrn.class); } - public SessionUrn(File sessionLocation) throws MalformedURLException { + /** + * Creates a SessionUrn object from a String. + * The string must be a string representation of a URI + * @param urnString + * @throws InvalidSessionUrnException + */ + public SessionUrn(String urnString) throws InvalidSessionUrnException + { + super(); + this.setURN(urnString); + } + + + /** + * Generates a sessionURN bases on a session directory location + * + * @param sessionLocation the file object to the session directory + */ + public SessionUrn(File sessionLocation) + {//throws MalformedURLException { // TODO: LATER: implement switch to have vamsas document or simpleclient sessions for same constructor - super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURL()); - //else - // super(VAMSASDOCUMENT, sessionLocation); + //use URI instead of URL + super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURI()); } - public SessionUrn(VamsasSession session) throws MalformedURLException { - super(SIMPLECLIENT, session.sessionDir.getAbsoluteFile().toURL()); + + /** + * Generates a sessionURN bases on a vamsas session + * @param session a VamsasSession + * + * Should return the same URN string than the creation with the session directory + */ + public SessionUrn(VamsasSession session) + { + //throws MalformedURLException { + // use URI instead of URL + super(SIMPLECLIENT, session.sessionDir.getAbsoluteFile().toURI()); } + + + + + /** * TODO: LATER: think about this again. - * @return File(urn.getPath()) + * + * Retrieves the file associated to the current sessionURN. + * The sessionURN (URI) is based on the session directory absolute path. + * Use the raw path of the URN and change the scheme to file to generate a new file + * URI. Then, from the URI create the File object (a File object can be created from an uri) + * + * @return File object representing the session URN // + * File(urn.getPath()) */ public File asFile() { - return new File(urn.getPath()); + String path = this.urn.getRawPath(); + + return new File ( URI.create("file://"+path)); } // TODO: add abstract 'handler' methods for resolving the URN to a particular class }