uws.service
Class ExtendedUWS

java.lang.Object
  extended by uws.job.SerializableUWSObject
      extended by uws.service.AbstractUWS<JobList<AbstractJob>,AbstractJob>
          extended by uws.service.ExtendedUWS
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<JobList<AbstractJob>>, java.util.EventListener, javax.servlet.http.HttpSessionBindingListener
Direct Known Subclasses:
QueuedExtendedUWS

public class ExtendedUWS
extends AbstractUWS<JobList<AbstractJob>,AbstractJob>

Convenient implementation of AbstractUWS.

Contrary to BasicUWS this implementation of a UWS can manage several JobLists of a different kind of Job. That means it is possible to manage a JobList of JobA and another JobList of JobB whereas BasicUWS could manage several JobList only of JobA or of JobB.

IMPORTANT: THE EXTENSIONS OF AbstractJob MUST CONTAIN A CONSTRUCTOR WITH ONLY ONE PARAMETER OF TYPE MAP<STRING,STRING> !!!

Example:
        public class MyServlet extends HttpServlet {
 
                private ExtendedUWS uws = null;
 
                public void init(ServletConfig conf) throws ServletException {
                        super.init(conf);
                        try{
                                uws = new ExtendedUWS();
                                uws.addJobList(new JobList<JobA>("JobListA"), JobA.class);
                                uws.addJobList(new JobList<JobB>("JobListB"), JobB.class);
                        }catch(UWSException ex){
                                ex.printStackTrace();
                                throw new ServletException(ex);
                        }
                }
 
                public void destroy(){
                        uws.removeAllJobLists();
                        super.destroy();
                }

                public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
                        try{
                                uws.executeRequest(request, response);
                        }catch(UWSException ex){
                                res.sendError(uwsEx.getHttpErrorCode(), uwsEx.getMessage());
                        }
                }
        }
 

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

Nested Class Summary
protected  class ExtendedUWS.AddJobWithConstructor
          Action AddJob which initializes the attribute jlDestination with the job list in which a job must be added.
 
Field Summary
protected  java.util.Map<JobList<? extends AbstractJob>,java.lang.Class<? extends AbstractJob>> assocJobListClass
          Association between each JobList and the class object of the type of job that this JobList manages.
protected  java.util.Map<JobList<? extends AbstractJob>,java.lang.reflect.Constructor<? extends AbstractJob>> assocJobListConstructor
          Association between each JobList and the constructor to use when a job must be created and added into this JobList.
protected  JobList<? extends AbstractJob> jlDestination
          Current JobList.
 
Fields inherited from class uws.service.AbstractUWS
choosenSerializer, defaultSerializer, description, executedAction, homePage, homeRedirection, mapJobLists, name, reInitUrlInterpreter, serializers, urlInterpreter, userIdentifier, uwsActions
 
Constructor Summary
ExtendedUWS()
          Builds an ExtendedUWS.
ExtendedUWS(java.lang.String baseURI)
          Builds an ExtendedUWS with its base URI.
ExtendedUWS(UWSUrl urlInterpreter)
          Builds an ExtendedUWS with the UWS URL interpreter to use.
 
Method Summary
protected  void addConstructor(JobList<? extends AbstractJob> jl)
          Searches in assocJobListClass for the Class object of the given jobs list, gets the constructor with only one parameter of type Map<String,String> into this Class object, and finally saves in assocJobListConstructor the association between the given jobs list and the found constructor.
<J extends AbstractJob>
boolean
addJobList(JobList<J> jl, java.lang.Class<J> cl)
          Adds a JobList with the constructor of the type of job to use.
 AbstractJob createJob(java.util.Map<java.lang.String,java.lang.String> parameters)
          Creates a job of the type (extension of AbstractJob) which parameterized this implementation of AbstractUWS.
 boolean destroyJobList(JobList<AbstractJob> jl)
          Destroys the given jobs list.
protected  java.lang.reflect.Constructor<? extends AbstractJob> getConstructor(JobList<? extends AbstractJob> jl)
          Gets the constructor of the type of job to use.
 boolean removeJobList(JobList<AbstractJob> jl)
          Removes the given jobs list from this UWS.
 
Methods inherited from class uws.service.AbstractUWS
addJobList, addSerializer, addUWSAction, addUWSAction, destroyAllJobLists, destroyJobList, executeRequest, getBaseURI, getChoosenSerializer, getDefaultSerializer, getDescription, getDestructionManager, getDestructionTimeController, getExecutedAction, getExecutionDurationController, getExecutionManager, getHomePage, getJobList, getName, getNbJobList, getNbSerializers, getNbUWSActions, getSerializer, getSerializers, getUrlInterpreter, getUserIdentifier, getUWSAction, getUWSActions, getXsltURL, hasSerializerFor, isDefaultHomePage, isHomePageRedirection, iterator, redirect, removeAllJobLists, removeJobList, removeSerializer, removeUWSAction, removeUWSAction, replaceUWSAction, sendError, sendError, serialize, setDefaultHomePage, setDefaultSerializer, setDescription, setDestructionManager, setDestructionTimeController, setExecutionDurationController, setExecutionManager, setHomePage, setHomePage, setName, setUrlInterpreter, setUserIdentifier, setUWSAction, setXsltURL, sync, valueBound, valueUnbound
 
Methods inherited from class uws.job.SerializableUWSObject
serialize, serialize, serialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

assocJobListClass

protected final java.util.Map<JobList<? extends AbstractJob>,java.lang.Class<? extends AbstractJob>> assocJobListClass
Association between each JobList and the class object of the type of job that this JobList manages.


assocJobListConstructor

protected transient java.util.Map<JobList<? extends AbstractJob>,java.lang.reflect.Constructor<? extends AbstractJob>> assocJobListConstructor
Association between each JobList and the constructor to use when a job must be created and added into this JobList.


jlDestination

protected JobList<? extends AbstractJob> jlDestination
Current JobList. (ALWAYS null EXCEPT WHILE ADDING A JOB !!)

Constructor Detail

ExtendedUWS

public ExtendedUWS()
Builds an ExtendedUWS.

See Also:
AbstractUWS.AbstractUWS(), AbstractUWS.replaceUWSAction(uws.service.actions.UWSAction), ExtendedUWS.AddJobWithConstructor

ExtendedUWS

public ExtendedUWS(java.lang.String baseURI)
            throws UWSException
Builds an ExtendedUWS with its base URI.

Parameters:
baseURI - The base UWS URI.
Throws:
UWSException - If there is an error when calling the constructor super(String).
See Also:
AbstractUWS.AbstractUWS(String), AbstractUWS.replaceUWSAction(uws.service.actions.UWSAction), ExtendedUWS.AddJobWithConstructor

ExtendedUWS

public ExtendedUWS(UWSUrl urlInterpreter)
Builds an ExtendedUWS with the UWS URL interpreter to use.

Parameters:
urlInterpreter - The UWS URL interpreter this UWS must use.
See Also:
AbstractUWS.AbstractUWS(UWSUrl), AbstractUWS.replaceUWSAction(uws.service.actions.UWSAction), ExtendedUWS.AddJobWithConstructor
Method Detail

getConstructor

protected final java.lang.reflect.Constructor<? extends AbstractJob> getConstructor(JobList<? extends AbstractJob> jl)
                                                                             throws UWSException

Gets the constructor of the type of job to use. This constructor has only one parameter of type Map<String,String>.

Note: If this UWS has just been de-serialized, the constructor is extracted one more time from the stored class object !

Parameters:
jl - The job list which manages the kind of job whose the constructor must be extracted.
Returns:
The constructor of the type of job to use.
Throws:
UWSException - If it is impossible to extract the constructor with one parameter (Map<String, String>) from a stored class object.
See Also:
addConstructor(JobList)

addConstructor

protected final void addConstructor(JobList<? extends AbstractJob> jl)
                             throws UWSException
Searches in assocJobListClass for the Class object of the given jobs list, gets the constructor with only one parameter of type Map<String,String> into this Class object, and finally saves in assocJobListConstructor the association between the given jobs list and the found constructor.

Parameters:
jl - The jobs list with which a job constructor must be associated.
Throws:
UWSException - If no corresponding Class object can be found or if the found class is abstract or if there is no constructor with only one parameter of type Map<String,String>.

addJobList

public <J extends AbstractJob> boolean addJobList(JobList<J> jl,
                                                  java.lang.Class<J> cl)
                   throws UWSException
Adds a JobList with the constructor of the type of job to use.

Type Parameters:
J - The type of job that the given JobList manages.
Parameters:
jl - The JobList to add.
cl - The class of job J which are managed in the given JobList.
Returns:
true if the JobList has been added successfully, false otherwise.
Throws:
UWSException - If the given class object corresponds to an abstract class or if the given class does not contain a constructor with only one parameter of type Map<String,String>.

removeJobList

public boolean removeJobList(JobList<AbstractJob> jl)
Description copied from class: AbstractUWS
Removes the given jobs list from this UWS.

Overrides:
removeJobList in class AbstractUWS<JobList<AbstractJob>,AbstractJob>
Parameters:
jl - The jobs list to remove.
Returns:
true if the jobs list has been successfully removed, false otherwise.
See Also:
JobList.removeAll(), JobList.setUWS(AbstractUWS)

destroyJobList

public boolean destroyJobList(JobList<AbstractJob> jl)
Description copied from class: AbstractUWS
Destroys the given jobs list.

Overrides:
destroyJobList in class AbstractUWS<JobList<AbstractJob>,AbstractJob>
Parameters:
jl - The jobs list to destroy.
Returns:
true if the given jobs list has been destroyed, false otherwise.
See Also:
JobList.clear(), JobList.setUWS(AbstractUWS)

createJob

public AbstractJob createJob(java.util.Map<java.lang.String,java.lang.String> parameters)
                      throws UWSException
Description copied from class: AbstractUWS
Creates a job of the type (extension of AbstractJob) which parameterized this implementation of AbstractUWS.

Specified by:
createJob in class AbstractUWS<JobList<AbstractJob>,AbstractJob>
Parameters:
parameters - The map of parameters to give to the constructor of AbstractJob.
Returns:
The created job.
Throws:
UWSException - If any error occurs while creating the job.
See Also:
AbstractUWS.createJob(java.util.Map), Constructor.newInstance(Object...)