From 15f3e69bbb901fe59943db85fda5cedc53bef6b4 Mon Sep 17 00:00:00 2001 From: pmarguerite Date: Fri, 15 Dec 2006 16:13:25 +0000 Subject: [PATCH] Updated simple client sessionURN to use URI instead of URL to generate SessionURN (URI) from the session directory path (file location or vamsas session). Updated SimpleClient to match modified constructor (MalformedURL not throw anymore) git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@327 be28352e-c001-0410-b1a7-c7978e42abec --- src/uk/ac/vamsas/client/SessionUrn.java | 12 ++-- .../ac/vamsas/client/simpleclient/SessionUrn.java | 68 ++++++++++---------- .../vamsas/client/simpleclient/SimpleClient.java | 6 +- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/uk/ac/vamsas/client/SessionUrn.java b/src/uk/ac/vamsas/client/SessionUrn.java index 54f7226..66b73c3 100644 --- a/src/uk/ac/vamsas/client/SessionUrn.java +++ b/src/uk/ac/vamsas/client/SessionUrn.java @@ -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 @@ -63,14 +61,18 @@ public abstract class SessionUrn { } /** - * 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); + } } } diff --git a/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java b/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java index bdb4296..ac64f0e 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java +++ b/src/uk/ac/vamsas/client/simpleclient/SessionUrn.java @@ -1,7 +1,6 @@ package uk.ac.vamsas.client.simpleclient; import java.io.File; -import java.net.MalformedURLException; import java.net.URI; import uk.ac.vamsas.client.InvalidSessionUrnException; @@ -9,6 +8,10 @@ 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 * */ @@ -36,54 +39,49 @@ public class SessionUrn extends uk.ac.vamsas.client.SessionUrn { } - - public SessionUrn(File sessionLocation) throws MalformedURLException { + /** + * 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()); - // super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURL()); + //use URI instead of URL super(SIMPLECLIENT, sessionLocation.getAbsoluteFile().toURI()); - //else - // super(VAMSASDOCUMENT, sessionLocation); } - public SessionUrn(VamsasSession session) throws MalformedURLException { - super(SIMPLECLIENT, session.sessionDir.getAbsoluteFile().toURL()); - } - - /** - * @see uk.ac.vamsas.client.SessionUrn#setURN(java.lang.String) + * 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 */ - protected void setURN(String urnString) throws NullPointerException, IllegalArgumentException { - super.setURN(urnString); + 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() { String path = this.urn.getRawPath(); - - /*if ("\\".equals(File.separator)) - {//windows stuff - //remove last separator at last position if found - /* not needed anymore if (path.charAt(path.length() - 1) == '/')path = path.substring(0, path.length() - 1); - path = path.replaceAll("/", "\\\\"); - */ - /* int index = path.indexOf(File.separator); - - if (index >-1) - {//separator found, keep last part of the urn - filename - path = path.substring(index+1, path.length()); - } - //remove encoded space character - // path = path.replaceAll("%20", " "); - } - /*shall we use URI or String to create the object*/ - /* from URI : URI.create("file://path") , but first / */ - /* return new File(path);*/ return new File ( URI.create("file://"+path)); } // TODO: add abstract 'handler' methods for resolving the URN to a particular class diff --git a/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java b/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java index 9af8889..739cf58 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java +++ b/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java @@ -76,12 +76,12 @@ public class SimpleClient implements IClient { _session = sess; this.user = user; this.client = client; - try { + //try { session = new SessionUrn(_session); - } catch (MalformedURLException e) { + /*} catch (MalformedURLException e) { log.error("Couldn't form a valid SessionUrn object!",e); throw new InvalidSessionUrnException(_session.toString()); - } + }*/ } /** * construct new session by importing objects from an existing vamsas document -- 1.7.10.2