org.restlet.ext.wadl
Class WadlApplication

java.lang.Object
  extended by org.restlet.Uniform
      extended by org.restlet.Restlet
          extended by org.restlet.Application
              extended by org.restlet.ext.wadl.WadlApplication

public class WadlApplication
extends Application

WADL configured application. Can automatically configure itself given a WADL description document.

It creates a root router and for each resource found in the WADL document, it tries to attach a Restlet Resource class to the router using its WADL path.

It looks up the qualified name of the Resource class using the WADL "id" attribute of the "resource" elements. This is the only Restlet specific constraint on the WADL document.

Also, it has an attachToComponent(Component) to attach the application to an existing component and a attachToHost(VirtualHost) to attach it to an existing virtual host using the "base" attribute of the WADL "resources" element.
Such application is also able to generate a description of itself under two formats: WADL or HTML (the latter is actually a transformation of the former). You can obtain this representation with an OPTIONS request addressed exactly to the application URI (e.g. "http://host:port/path/to/application"). By default, the returned representation gleans the list of all attached Resources. This default behaviour can be customized by overriding the getApplicationInfo() method.
Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.

Author:
Jerome Louvel

Constructor Summary
WadlApplication()
          Creates an application that can automatically introspect and expose itself as with a WADL description upon reception of an OPTIONS request on the "*" target URI.
WadlApplication(Context context)
          Creates an application that can automatically introspect and expose itself as with a WADL description upon reception of an OPTIONS request on the "*" target URI.
WadlApplication(Context context, Representation wadl)
          Creates an application described using a WADL document.
WadlApplication(Representation wadl)
          Creates an application described using a WADL document.
 
Method Summary
 VirtualHost attachToComponent(Component component)
          Attaches the application to the given component if the application has a WADL base reference.
 void attachToHost(VirtualHost host)
          Attaches the application to the given host using the WADL base reference.
 ApplicationInfo getApplicationInfo(Request request, Response response)
          Returns a WADL description of the current application.
 Reference getBaseRef()
          Returns the WADL base reference.
protected  Variant getPreferredWadlVariant(ClientInfo clientInfo)
          Returns the preferred WADL variant according to the client preferences specified in the request.
 Router getRouter()
          Returns the router where the Resources created from the WADL description document are attached.
 java.lang.String getTitle()
          Returns the title of this documented application.
protected  java.util.List<Variant> getWadlVariants()
          Returns the available WADL variants.
 void handle(Request request, Response response)
          Handles the requests normally in all cases then handles the special case of the OPTIONS requests that exactly target the application.
 boolean isAutoDescribed()
          Indicates if the application should be automatically described via WADL when an OPTIONS request handles a "*" target URI.
 void setAutoDescribed(boolean autoDescribed)
          Indicates if the application should be automatically described via WADL when an OPTIONS request handles a "*" target URI.
 void setBaseRef(Reference baseRef)
          Sets the WADL base reference.
 void setTitle(java.lang.String title)
          Sets the title of this documented application.
protected  Representation wadlRepresent(Request request, Response response)
          Represents the resource as a WADL description.
 Representation wadlRepresent(Variant variant, Request request, Response response)
          Represents the resource as a WADL description for the given variant.
 
Methods inherited from class org.restlet.Application
createRoot, getAuthor, getConnectorService, getConverterService, getCurrent, getDecoderService, getDescription, getMetadataService, getName, getOwner, getRangeService, getRoot, getStatusService, getTaskService, getTunnelService, setAuthor, setConnectorService, setConverterService, setCurrent, setDecoderService, setDescription, setMetadataService, setName, setOwner, setRangeService, setRoot, setStatusService, setTaskService, setTunnelService, start, stop
 
Methods inherited from class org.restlet.Restlet
getApplication, getContext, getLogger, init, isStarted, isStopped, setContext
 
Methods inherited from class org.restlet.Uniform
delete, delete, get, get, handle, head, head, options, options, post, post, put, put
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WadlApplication

public WadlApplication()
Creates an application that can automatically introspect and expose itself as with a WADL description upon reception of an OPTIONS request on the "*" target URI.


WadlApplication

public WadlApplication(Context context)
Creates an application that can automatically introspect and expose itself as with a WADL description upon reception of an OPTIONS request on the "*" target URI.

Parameters:
context - The context to use based on parent component context. This context should be created using the Context.createChildContext() method to ensure a proper isolation with the other applications.

WadlApplication

public WadlApplication(Context context,
                       Representation wadl)
Creates an application described using a WADL document. Creates a router where Resource classes are attached and set it as the root Restlet. By default the application is not automatically described. If you want to, you can call setAutoDescribed(boolean).

Parameters:
context - The context to use based on parent component context. This context should be created using the Context.createChildContext() method to ensure a proper isolation with the other applications.
wadl - The WADL description document.

WadlApplication

public WadlApplication(Representation wadl)
Creates an application described using a WADL document. Creates a router where Resource classes are attached and set it as the root Restlet. By default the application is not automatically described. If you want to, you can call setAutoDescribed(boolean).

Parameters:
wadl - The WADL description document.
Method Detail

attachToComponent

public VirtualHost attachToComponent(Component component)
Attaches the application to the given component if the application has a WADL base reference. The application will be attached to an existing virtual host if possible, otherwise a new one will be created.

Parameters:
component - The parent component to update.
Returns:
The parent virtual host.

attachToHost

public void attachToHost(VirtualHost host)
Attaches the application to the given host using the WADL base reference.

Parameters:
host - The virtual host to attach to.

getApplicationInfo

public ApplicationInfo getApplicationInfo(Request request,
                                          Response response)
Returns a WADL description of the current application. By default, this method discovers all the resources attached to this application. It can be overriden to add documentation, list of representations, etc.

Parameters:
request - The current request.
response - The current response.
Returns:
An application description.

getBaseRef

public Reference getBaseRef()
Returns the WADL base reference.

Returns:
The WADL base reference.

getPreferredWadlVariant

protected Variant getPreferredWadlVariant(ClientInfo clientInfo)
Returns the preferred WADL variant according to the client preferences specified in the request.

Parameters:
clientInfo - The client preferences and info.
Returns:
The preferred WADL variant.

getRouter

public Router getRouter()
Returns the router where the Resources created from the WADL description document are attached.

Returns:
The root router.

getTitle

public java.lang.String getTitle()
Returns the title of this documented application.

Returns:
The title of this documented application.

getWadlVariants

protected java.util.List<Variant> getWadlVariants()
Returns the available WADL variants.

Returns:
The available WADL variants.

handle

public void handle(Request request,
                   Response response)
Handles the requests normally in all cases then handles the special case of the OPTIONS requests that exactly target the application. In this case, the application is automatically introspected and described as a WADL representation based on the result of the getApplicationInfo(Request, Response) method.
The automatic introspection happens only if the request hasn't already been successfully handled. That is to say, it lets users to provide their own handling of OPTIONS requests.

Overrides:
handle in class Application
Parameters:
request - The request to handle.
response - The response to update.

isAutoDescribed

public boolean isAutoDescribed()
Indicates if the application should be automatically described via WADL when an OPTIONS request handles a "*" target URI.

Returns:
True if the application should be automatically described via WADL.

setAutoDescribed

public void setAutoDescribed(boolean autoDescribed)
Indicates if the application should be automatically described via WADL when an OPTIONS request handles a "*" target URI.

Parameters:
autoDescribed - True if the application should be automatically described via WADL.

setBaseRef

public void setBaseRef(Reference baseRef)
Sets the WADL base reference.

Parameters:
baseRef - The WADL base reference.

setTitle

public void setTitle(java.lang.String title)
Sets the title of this documented application.

Parameters:
title - The title of this documented application.

wadlRepresent

protected Representation wadlRepresent(Request request,
                                       Response response)
Represents the resource as a WADL description.

Parameters:
request - The current request.
response - The current response.
Returns:
The WADL description.

wadlRepresent

public Representation wadlRepresent(Variant variant,
                                    Request request,
                                    Response response)
Represents the resource as a WADL description for the given variant.

Parameters:
variant - The WADL variant.
request - The current request.
response - The current response.
Returns:
The WADL description.


Copyright © 2005-2008 Noelios Technologies.