org.opentox.toxotis.client
Class VRI

java.lang.Object
  extended by org.opentox.toxotis.client.VRI
All Implemented Interfaces:
Serializable

public class VRI
extends Object
implements Serializable

VRI is an alternative to URI. Being final, the class java.net.URI cannot be sub-classed. VRI offers greater flexibility in this context as it stores in a highly structured way the parameters of the URL and applies URL encoding where necessary.

Author:
Pantelis Sopasakis, Charalampos Chomenides
See Also:
Serialized Form

Constructor Summary
VRI()
          Dummy constructor
VRI(String uri)
          Construct a new VRI providing its String representation.
VRI(String uri, String... params)
          Create a new VRI object providing its URI as String (can possibly include a query part which will be parsed) and a set of parameters (name-value pairs).
VRI(VRI other)
          Creates a VRI as a clone of a given VRI.
 
Method Summary
 VRI addUrlParameter(String paramName, double paramValue)
          Add a double valued URL parameter.
 VRI addUrlParameter(String paramName, int paramValue)
          Add an integer valued URL parameter.
 VRI addUrlParameter(String paramName, String paramValue)
          Add a URL parameter.
 VRI augment(Object... params)
          An alternative to #augment(String[])
 VRI augment(String... fragments)
          Augments the URI with additional string blocks.
 boolean equals(Object obj)
           
 String getHost()
          Returns the host of the URI.
 String getId()
           
 OntologicalClass getOntologicalClass()
          The Ontological Class of the URI.
 Class<?> getOpenToxType()
          Returns a Java class that best fits the pattern matched by this URI.
 int getPort()
          Delegates the method java.net.URI#getPort()::int
 String getProtocol()
          Returns the protocol of the URI (HTTP, HTTPS, etc)
 String getQueryAsString()
          Returns the query part of the URI as a String without the question mark.
 VRI getServiceBaseUri()
          Returns the base URI of the service.
 String getStringNoQuery()
          Returns the URI without the query part.
 String getUri()
          Equivalent method to toString().
 List<Pair<String,String>> getUrlParams()
          Returns a set of name-value pairs that constitute the set of URL parameters of the VRI.
 int hashCode()
           
 VRI removeUrlParameter(String paramName)
          Removes all parameters that match the given parameter name.
 void setUri(String uri)
           
 String toString()
           
 URI toURI()
          Converts the VRI object into the corresponding java.net.URI
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VRI

public VRI()
Dummy constructor


VRI

public VRI(String uri)
    throws URISyntaxException
Construct a new VRI providing its String representation. Parameters are parsed and stored separately in a map.

Parameters:
uri - The URI as a string.
Throws:
URISyntaxException - In case the provided URI is syntactically incorrect.

VRI

public VRI(VRI other)
Creates a VRI as a clone of a given VRI.

Parameters:
other - VRI to be cloned.

VRI

public VRI(String uri,
           String... params)
    throws URISyntaxException
Create a new VRI object providing its URI as String (can possibly include a query part which will be parsed) and a set of parameters (name-value pairs).

Parameters:
uri - The base URI
params - A sequence of parameter names followed by their values. For example VRI v = new VRI("http://myserver.com","a","2","option","true"). This will generate the URI: http://myserver.com?a=2&option=true. Note that the parameter names and values are URL encoded (using the UTF-8 encoding) as soon as they are provided to the constructor.
Throws:
URISyntaxException
Method Detail

getUrlParams

public List<Pair<String,String>> getUrlParams()
Returns a set of name-value pairs that constitute the set of URL parameters of the VRI. Every key in the map is a parameter name while the corresponding value is the value for this parameter.

Returns:
The ArrayList of URL parameters as a list of name-value pairs.

removeUrlParameter

public VRI removeUrlParameter(String paramName)
Removes all parameters that match the given parameter name. If no parameter is found to match the search criterion, no action is taken and the VRI is returned without any modifications.

Parameters:
paramName - Name of parameter to be removed from the set of name-value pairs
Returns:
The updated VRI without the parameter.

addUrlParameter

public VRI addUrlParameter(String paramName,
                           String paramValue)
Add a URL parameter. As soon as you provide the URL parameter and its value, these are encoded using the UTF-8 encoding so you do not need to encode them before submitting them.

Parameters:
paramName - The name of the parameter
paramValue - The value for the parameter
Returns:
The updated VRI on which the method is applied.

addUrlParameter

public VRI addUrlParameter(String paramName,
                           double paramValue)
Add a double valued URL parameter. As soon as you provide the URL parameter and its value, these are encoded using the UTF-8 encoding so you do not need to encode them before submitting them.

Parameters:
paramName - The name of the parameter
paramValue - The value for the parameter (double)
Returns:
The updated VRI on which the method is applied.

addUrlParameter

public VRI addUrlParameter(String paramName,
                           int paramValue)
Add an integer valued URL parameter. As soon as you provide the URL parameter and its value, these are encoded using the UTF-8 encoding so you do not need to (and must not) encode them before submitting them.

Parameters:
paramName - The name of the parameter
paramValue - The value for the parameter (integer value)
Returns:
The updated VRI on which the method is applied.

toURI

public URI toURI()
Converts the VRI object into the corresponding java.net.URI

Returns:
Corresponding URI

toString

public String toString()
Overrides:
toString in class Object

augment

public VRI augment(String... fragments)
Augments the URI with additional string blocks. Each string provided in the list of arguments of this method is URL-encoded and appended at the end of the current URI. The current URI is also modified and this is an important detail to take into account. So, for example consider the following piece of code:
 VRI myUri = new VRI("http://server.com/");
 VRI datasetUri = myUri.augment("dataset");
 VRI modelUri = myUri.augment("model");
Not surprisingly, modelUri will be http://server.com/dataset/model instead of http://server.com/model. This is because the invocation myUri.augment("dataset") already modified the URI. In order to achieve the desired result, one should use:
 VRI myUri = new VRI("http://server.com/");
 VRI datasetUri = new VRI(myUri).augment("dataset");
 VRI modelUri = new VRI(myUri).augment("model");
This way, a copy of the initial URI is created and modified on-the-fly.

Parameters:
fragments - List of fragments to be appended at the end of the current URI.
Returns:
The current modifiable URI updated with the new additional fragments.

augment

public VRI augment(Object... params)
An alternative to #augment(String[])

Parameters:
params - List of fragments
Returns:
The instance of the current modifiable URI updated with the new additional fragments.

getProtocol

public String getProtocol()
Returns the protocol of the URI (HTTP, HTTPS, etc)

Returns:
Protocol as a string

getPort

public int getPort()
Delegates the method java.net.URI#getPort()::int


getQueryAsString

public String getQueryAsString()
Returns the query part of the URI as a String without the question mark.

Returns:
Query as String.

getOpenToxType

public Class<?> getOpenToxType()
Returns a Java class that best fits the pattern matched by this URI. For example the URI http://someserver.com:9876/OpenTox/query/compound/phenol/smiles will return the class org.opentox.toxotis.core.Dataset. Note that this method will return null in case the URI does not comply with the pattern for the URI of OpenTox resource and it will also return null for URIs that identify sets/collections of resource such as /compound (list all compounds). So the following code will print null:
 VRI uri = new VRI("http://someserver.com/opentox/dataset");
 Class<?> cl = uri.getOpenToxType();
 System.out.println(cl);
 

Returns:
Corresponding OpenTox class (usually a subclass of OTComponent ).
See Also:
OTComponent, Dataset

getOntologicalClass

public OntologicalClass getOntologicalClass()
The Ontological Class of the URI. Every OpenTox resource follows a pattern according to the resource it points to. For example, all dataset URIs follow the pattern /dataset/{id} or formally .+/(?i)dataset(s||)/([^/]+/$|[^/]+)$ or as well .+/(?i)query/(?i)compound/.+/([^/]+/$|[^/]+)$.

Returns:

getHost

public String getHost()
Returns the host of the URI. This is a proxy method to URI#getHost().

Returns:
The host of the URI as a String.

getServiceBaseUri

public VRI getServiceBaseUri()
Returns the base URI of the service.

Returns:
The base URI of the service.

getStringNoQuery

public String getStringNoQuery()
Returns the URI without the query part.

Returns:
URI without the query part

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

getUri

public String getUri()
Equivalent method to toString().

Returns:
The current object as a String (representing the URI of the resource).

setUri

public void setUri(String uri)

getId

public String getId()


Copyright © 2011-2012 OpenTox. All Rights Reserved.