uws.service
Class UWSUrl

java.lang.Object
  extended by uws.service.UWSUrl
All Implemented Interfaces:
java.io.Serializable

public class UWSUrl
extends java.lang.Object
implements java.io.Serializable

This class helps managing with UWS URLs and URIs.

Version:
02/2011
Author:
Grégory Mantelet (CDS)
See Also:
Serialized Form

Field Summary
protected  java.lang.String[] attributes
          Name of the job attribute found in uwsURI (i.e.
protected  java.lang.String baseURI
          Base UWS URI (i.e.
protected  java.lang.String jobId
          The JobID found in uwsURI (i.e. job1).
protected  java.lang.String jobListName
          Name of a jobs list found in uwsURI (i.e. jobList).
protected  java.lang.String requestURI
          The request URI (i.e.
protected  java.lang.String requestURL
          The whole request URL (i.e. http://foo.org/mySite/uws/jobList/job1/results/report).
protected  java.lang.String urlHeader
          The URL prefix (i.e. http://foo.org/mySite).
protected  java.lang.String uwsURI
          The URI from the base UWS URI (i.e.
 
Constructor Summary
UWSUrl(javax.servlet.http.HttpServletRequest request)
          Builds a UWSUrl considering the given request to set the baseURI.
UWSUrl(java.lang.String baseURI)
          Builds a UWSUrl with a fixed baseURI.
UWSUrl(UWSUrl toCopy)
          Builds a copy of the given UWSUrl.
 
Method Summary
 java.lang.String abortJob(java.lang.String jobListName, java.lang.String jobId)
          Gets the UWS URL (HTTP-GET ONLY) to abort the specified job.
 java.lang.String changeDestructionTime(java.lang.String jobListName, java.lang.String jobId, java.lang.String newDestructionTime)
          Gets the UWS URL (HTTP-GET ONLY) to change the destruction time.
 java.lang.String changeExecDuration(java.lang.String jobListName, java.lang.String jobId, java.lang.String newExecDuration)
          Gets the UWS URL (HTTP-GET ONLY) to change the execution duration.
 java.lang.String changeJobName(java.lang.String jobListName, java.lang.String jobId, java.lang.String newName)
          Gets the UWS URL (HTTP-GET ONLY) to change the run ID.
 java.lang.String changeJobParam(java.lang.String jobListName, java.lang.String jobId, java.lang.String paramName, java.lang.String paramValue)
          Gets the UWS URL (HTTP-GET ONLY) to change the specified parameter.
 java.lang.String createJob(java.lang.String jobListName, java.util.Map<java.lang.String,java.lang.String> parameters)
          Gets the UWS URL (HTTP-GET ONLY) to create a job with the given parameters.
 java.lang.String deleteJob(java.lang.String jobListName, java.lang.String jobId)
          Gets the UWS URL (HTTP-GET ONLY) to delete the specified job.
protected  java.lang.String extractBaseURI(javax.servlet.http.HttpServletRequest request)
          Extracts the base UWS URI from the given request.
 java.lang.String[] getAttributes()
          Gets all the job attributes extracted from the last request or request URL.
 java.lang.String getBaseURI()
          Gets the base UWS URI given at the initialization of this instance of UWSUrl.
 java.lang.String getJobId()
          Gets the job ID extracted from the last parsed request or request URL.
 java.lang.String getJobListName()
          Gets the jobs list name extracted from the last parsed request or request URL.
 java.lang.String getRequestURI()
          Gets the request URI.
 java.lang.String getRequestURL()
          Gets the request URL.
 java.lang.String getUrlHeader()
          Gets the URL header of the request URL.
 java.lang.String getUWSName()
          Gets the SUPPOSED name of the UWS from its baseURI.
 java.lang.String getUwsURI()
          Gets the UWS URI.
 boolean hasAttribute()
          Tells whether the last loaded request or request URL contains at least one job attribute.
 boolean hasAttribute(java.lang.String attributeName)
          Tells whether the last loaded request or request URL contains a job attribute with the given name.
 boolean hasJob()
          Tells whether the last loaded request or request URL contains a job ID.
 boolean hasJobList()
          Tells whether the last loaded request or request URL contains a jobs list name.
 UWSUrl homePage()
          Gets the base UWS URI = UWS home page.
 UWSUrl jobDestruction(java.lang.String jobListName, java.lang.String jobId)
          Gets the UWS URL to get the destruction time.
 UWSUrl jobError(java.lang.String jobListName, java.lang.String jobId)
          Gets the UWS URL to get the error summary.
 UWSUrl jobExecDuration(java.lang.String jobListName, java.lang.String jobId)
          Gets the UWS URL to get the execution duration.
 UWSUrl jobName(java.lang.String jobListName, java.lang.String jobId)
          Gets the UWS URL to get the runID.
 UWSUrl jobOwner(java.lang.String jobListName, java.lang.String jobId)
          Gets the UWS URL to get the owner ID.
 UWSUrl jobParameter(java.lang.String jobListName, java.lang.String jobId, java.lang.String paramName)
          Gets the UWS URL to get the parameters/parameter.
 UWSUrl jobParameters(java.lang.String jobListName, java.lang.String jobId)
          Gets the UWS URL to get the parameters.
 UWSUrl jobPhase(java.lang.String jobListName, java.lang.String jobId)
          Gets the UWS URL to get the phase.
 UWSUrl jobQuote(java.lang.String jobListName, java.lang.String jobId)
          Gets the UWS URL to get the quote.
 UWSUrl jobResult(java.lang.String jobListName, java.lang.String jobId, java.lang.String resultId)
          Gets the UWS URL to get the specified result.
 UWSUrl jobResults(java.lang.String jobListName, java.lang.String jobId)
          Gets the UWS URL to get the results.
 UWSUrl jobSummary(java.lang.String jobListName, java.lang.String jobId)
          Gets the UWS URL to get the summary.
 UWSUrl listJobs(java.lang.String jobListName)
          Gets the UWS URL to get the specified jobs list.
 void load(javax.servlet.http.HttpServletRequest request)
          Parses and loads the given request.
 void load(java.net.URL requestUrl)
          Parses and loads the given request URL.
protected  void loadUwsURI()
          Loads and parses the URI stored in the member uwsURI.
protected static java.lang.String normalizeURI(java.lang.String uri)
          Normalizes the given URI.
 void setAttributes(java.lang.String[] newAttributes)
          Sets all the job attributes.
 void setJobId(java.lang.String jobId)
          Sets the job ID.
 void setJobListName(java.lang.String jobListName)
          Sets the jobs list name.
 void setUwsURI(java.lang.String uwsURI)
          Sets the whole UWS URI (that is to say a URI starting with the jobs list name).
 java.lang.String startJob(java.lang.String jobListName, java.lang.String jobId)
          Gets the UWS URL (HTTP-GET ONLY) to start the specified job.
 java.lang.String toString()
          Gets the corresponding request URL.
 java.lang.String toURI()
          Gets the full request URI corresponding to this UWSUrl.
 java.net.URL toURL()
          Gets the full request URL corresponding to this UWSUrl.
protected  void updateRequestURL()
           Updates the fields requestURI and requestURL as following: requestURI = baseURI+uwsURI requestURL = urlHeader+requestURI (or null if urlHeader is null)
protected  void updateUwsURI()
          Updates the field uwsURI in function of jobListName, jobId and attributes as following: uwsURI = "/"+jobListName+"/"+jobId+"/"+attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

requestURL

protected java.lang.String requestURL
The whole request URL (i.e. http://foo.org/mySite/uws/jobList/job1/results/report).


urlHeader

protected java.lang.String urlHeader
The URL prefix (i.e. http://foo.org/mySite).


requestURI

protected java.lang.String requestURI
The request URI (i.e. /uws/jobList/job1/results/report)


baseURI

protected final java.lang.String baseURI
Base UWS URI (i.e. /uws).


uwsURI

protected java.lang.String uwsURI
The URI from the base UWS URI (i.e. /jobList/job1/results/report).


jobListName

protected java.lang.String jobListName
Name of a jobs list found in uwsURI (i.e. jobList).


jobId

protected java.lang.String jobId
The JobID found in uwsURI (i.e. job1).


attributes

protected java.lang.String[] attributes
Name of the job attribute found in uwsURI (i.e. {results, report}).

Constructor Detail

UWSUrl

public UWSUrl(UWSUrl toCopy)
Builds a copy of the given UWSUrl.

Parameters:
toCopy - The UWSUrl to copy.

UWSUrl

public UWSUrl(java.lang.String baseURI)
       throws UWSException
Builds a UWSUrl with a fixed baseURI.

Parameters:
baseURI - The baseURI to consider in all URL or request parsing.
Throws:
UWSException - If the given baseURI is null or is an empty string.

UWSUrl

public UWSUrl(javax.servlet.http.HttpServletRequest request)
       throws UWSException
Builds a UWSUrl considering the given request to set the baseURI.

Parameters:
request - The request to parse to get the baseURI.
Throws:
UWSException - If the given request is null or if the extracted baseURI is null or is an empty string.
See Also:
extractBaseURI(HttpServletRequest)
Method Detail

extractBaseURI

protected java.lang.String extractBaseURI(javax.servlet.http.HttpServletRequest request)
Extracts the base UWS URI from the given request.

Parameters:
request - The request from which the base UWS URI must be extracted.
Returns:
The extracted URI (may be null).

normalizeURI

protected static final java.lang.String normalizeURI(java.lang.String uri)

Normalizes the given URI.

Note: A normalized URI always starts with a / and ends with no /.

Parameters:
uri - The URI to normalize.
Returns:
The normalized URI.

load

public void load(javax.servlet.http.HttpServletRequest request)

Parses and loads the given request.

Before all, extractBaseURI(HttpServletRequest) is called so that extracting the base URI from the request. If this URI is different from the URI stored in this UWSUrl, load(URL) is called so that parsing only the request URL and then this method ends immediately.

Otherwise this method sets its fields as following:

Note: If the given request is NULL, all fields are set to NULL.

Parameters:
request - The request to parse and to load.
See Also:
extractBaseURI(HttpServletRequest), load(URL), loadUwsURI()

load

public void load(java.net.URL requestUrl)

Parses and loads the given request URL.

All the fields are set as following:

Note: If the given URL is NULL, all fields are set to NULL.

Parameters:
requestUrl - The URL to parse and to load.
See Also:
loadUwsURI()

loadUwsURI

protected void loadUwsURI()

Loads and parses the URI stored in the member uwsURI.

The URI is split by the / character. The items of the resulting array corresponds to:

Note: If uwsURI is NULL, jobListName and jobId are set to null while attributes is set to an empty array.


getBaseURI

public final java.lang.String getBaseURI()
Gets the base UWS URI given at the initialization of this instance of UWSUrl.

Returns:
The baseUri.

getUWSName

public final java.lang.String getUWSName()
Gets the SUPPOSED name of the UWS from its baseURI.

Returns:
The presumed UWS name.

getRequestURL

public final java.lang.String getRequestURL()
Gets the request URL.

Returns:
The last loaded request URL.

getUrlHeader

public final java.lang.String getUrlHeader()

Gets the URL header of the request URL.

Example: If the base URI is "/uws" and the request URL is "http://foo.org/mySite/uws/jobList/job1/results/report", then the URL header will be: "http://foo.org/mySite".

Returns:
The last loaded URL header.

getRequestURI

public final java.lang.String getRequestURI()

Gets the request URI.

Example: If the base URI is "/uws" and the request URL is "http://foo.org/mySite/uws/jobList/job1/results/report", then the request URI will be: "/uws/jobList/jobId/results/report".

Returns:
The last loaded request URI.

getUwsURI

public final java.lang.String getUwsURI()

Gets the UWS URI.

Example: If the base URI is "/uws" and the request URL is "http://foo.org/mySite/uws/jobList/job1/results/report", then the request URI will be: "/jobList/jobId/results/report".

Returns:
The extracted UWS URI.

hasJobList

public final boolean hasJobList()
Tells whether the last loaded request or request URL contains a jobs list name.

Returns:
true if a jobs list name has been extracted, false otherwise.

getJobListName

public final java.lang.String getJobListName()
Gets the jobs list name extracted from the last parsed request or request URL.

Returns:
The extracted jobs list name.

hasJob

public final boolean hasJob()
Tells whether the last loaded request or request URL contains a job ID.

Returns:
true if a job ID has been extracted, false otherwise.

getJobId

public final java.lang.String getJobId()
Gets the job ID extracted from the last parsed request or request URL.

Returns:
The extracted job ID.

hasAttribute

public final boolean hasAttribute()
Tells whether the last loaded request or request URL contains at least one job attribute.

Returns:
true if at least one job attribute has been extracted, false otherwise.

hasAttribute

public final boolean hasAttribute(java.lang.String attributeName)
Tells whether the last loaded request or request URL contains a job attribute with the given name.

Parameters:
attributeName - The name of the job attribute expected in the last request or request URL.
Returns:
true if the specified job attribute has been extracted, false otherwise.

getAttributes

public final java.lang.String[] getAttributes()
Gets all the job attributes extracted from the last request or request URL.

Returns:
The extracted job attributes.

updateUwsURI

protected void updateUwsURI()

Updates the field uwsURI in function of jobListName, jobId and attributes as following: uwsURI = "/"+jobListName+"/"+jobId+"/"+attributes.

Once uwsURI updated the request URL and URI are also updated.

See Also:
updateRequestURL()

updateRequestURL

protected void updateRequestURL()

Updates the fields requestURI and requestURL as following:


setUwsURI

public final void setUwsURI(java.lang.String uwsURI)
Sets the whole UWS URI (that is to say a URI starting with the jobs list name). Once done all the other fields of this UWS URL are updated.

Parameters:
uwsURI - The UWS URI to set.
See Also:
loadUwsURI(), updateRequestURL()

setJobListName

public final void setJobListName(java.lang.String jobListName)
Sets the jobs list name. Once done all the other fields of this UWS URL are updated.

Parameters:
jobListName - A jobs list name.
See Also:
updateUwsURI()

setJobId

public final void setJobId(java.lang.String jobId)
Sets the job ID. Once done all the other fields of this UWS URL are updated.

Parameters:
jobId - A job ID.
See Also:
updateUwsURI()

setAttributes

public final void setAttributes(java.lang.String[] newAttributes)

Sets all the job attributes. Once done all the other fields of this UWS URL are updated.

Note: The given array is entirely copied.

Parameters:
newAttributes - The new job attributes.
See Also:
updateUwsURI()

homePage

public final UWSUrl homePage()
Gets the base UWS URI = UWS home page.


listJobs

public final UWSUrl listJobs(java.lang.String jobListName)
Gets the UWS URL to get the specified jobs list.


jobSummary

public final UWSUrl jobSummary(java.lang.String jobListName,
                               java.lang.String jobId)
Gets the UWS URL to get the summary.


jobName

public final UWSUrl jobName(java.lang.String jobListName,
                            java.lang.String jobId)
Gets the UWS URL to get the runID.


jobPhase

public final UWSUrl jobPhase(java.lang.String jobListName,
                             java.lang.String jobId)
Gets the UWS URL to get the phase.


jobExecDuration

public final UWSUrl jobExecDuration(java.lang.String jobListName,
                                    java.lang.String jobId)
Gets the UWS URL to get the execution duration.


jobDestruction

public final UWSUrl jobDestruction(java.lang.String jobListName,
                                   java.lang.String jobId)
Gets the UWS URL to get the destruction time.


jobError

public final UWSUrl jobError(java.lang.String jobListName,
                             java.lang.String jobId)
Gets the UWS URL to get the error summary.


jobQuote

public final UWSUrl jobQuote(java.lang.String jobListName,
                             java.lang.String jobId)
Gets the UWS URL to get the quote.


jobResults

public final UWSUrl jobResults(java.lang.String jobListName,
                               java.lang.String jobId)
Gets the UWS URL to get the results.


jobResult

public final UWSUrl jobResult(java.lang.String jobListName,
                              java.lang.String jobId,
                              java.lang.String resultId)
Gets the UWS URL to get the specified result.


jobParameters

public final UWSUrl jobParameters(java.lang.String jobListName,
                                  java.lang.String jobId)
Gets the UWS URL to get the parameters.


jobParameter

public final UWSUrl jobParameter(java.lang.String jobListName,
                                 java.lang.String jobId,
                                 java.lang.String paramName)
Gets the UWS URL to get the parameters/parameter.


jobOwner

public final UWSUrl jobOwner(java.lang.String jobListName,
                             java.lang.String jobId)
Gets the UWS URL to get the owner ID.


createJob

public final java.lang.String createJob(java.lang.String jobListName,
                                        java.util.Map<java.lang.String,java.lang.String> parameters)
Gets the UWS URL (HTTP-GET ONLY) to create a job with the given parameters.


deleteJob

public final java.lang.String deleteJob(java.lang.String jobListName,
                                        java.lang.String jobId)
Gets the UWS URL (HTTP-GET ONLY) to delete the specified job.


startJob

public final java.lang.String startJob(java.lang.String jobListName,
                                       java.lang.String jobId)
Gets the UWS URL (HTTP-GET ONLY) to start the specified job.


abortJob

public final java.lang.String abortJob(java.lang.String jobListName,
                                       java.lang.String jobId)
Gets the UWS URL (HTTP-GET ONLY) to abort the specified job.


changeJobName

public final java.lang.String changeJobName(java.lang.String jobListName,
                                            java.lang.String jobId,
                                            java.lang.String newName)
Gets the UWS URL (HTTP-GET ONLY) to change the run ID.


changeDestructionTime

public final java.lang.String changeDestructionTime(java.lang.String jobListName,
                                                    java.lang.String jobId,
                                                    java.lang.String newDestructionTime)
Gets the UWS URL (HTTP-GET ONLY) to change the destruction time.


changeExecDuration

public final java.lang.String changeExecDuration(java.lang.String jobListName,
                                                 java.lang.String jobId,
                                                 java.lang.String newExecDuration)
Gets the UWS URL (HTTP-GET ONLY) to change the execution duration.


changeJobParam

public final java.lang.String changeJobParam(java.lang.String jobListName,
                                             java.lang.String jobId,
                                             java.lang.String paramName,
                                             java.lang.String paramValue)
Gets the UWS URL (HTTP-GET ONLY) to change the specified parameter.


toURL

public java.net.URL toURL()
                   throws java.net.MalformedURLException
Gets the full request URL corresponding to this UWSUrl.

Returns:
The corresponding request URL.
Throws:
java.net.MalformedURLException - If there is an error while building the URL object from the requestURL field.
See Also:
getRequestURL()

toURI

public java.lang.String toURI()
Gets the full request URI corresponding to this UWSUrl.

Returns:
The corresponding request URI.
See Also:
getRequestURI()

toString

public java.lang.String toString()
Gets the corresponding request URL.

Overrides:
toString in class java.lang.Object
See Also:
getRequestURL(), Object.toString()