org.restlet.ext.wadl
Class WadlServerResource

java.lang.Object
  extended by org.restlet.resource.Resource
      extended by org.restlet.resource.UniformResource
          extended by org.restlet.resource.ServerResource
              extended by org.restlet.ext.wadl.WadlServerResource

public class WadlServerResource
extends ServerResource

Resource that is able to automatically describe itself with WADL. This description can be customized by overriding the describe() and describeMethod(Method, MethodInfo) methods.

When used to describe a class of resources in the context of a parent application, a special instance will be created using the default constructor (with no request, response associated). In this case, the resource should do its best to return the generic information when the WADL description methods are invoked, like describe() and delegate methods.

Author:
Jerome Louvel

Constructor Summary
WadlServerResource()
          Constructor.
 
Method Summary
 boolean canDescribe(Method method)
          Indicates if the given method exposes its WADL description.
protected  Representation createHtmlRepresentation(ApplicationInfo applicationInfo)
          Creates a new HTML representation for a given ApplicationInfo instance describing an application.
protected  Representation createWadlRepresentation(ApplicationInfo applicationInfo)
          Creates a new WADL representation for a given ApplicationInfo instance describing an application.
protected  Representation describe()
          Describes the resource as a standalone WADL document.
protected  void describe(ApplicationInfo applicationInfo)
          Updates the description of the parent application.
protected  RepresentationInfo describe(MethodInfo methodInfo, Class<?> representationClass, Variant variant)
          Describes a representation class and variant couple as WADL information.
protected  RepresentationInfo describe(MethodInfo methodInfo, RequestInfo requestInfo, Class<?> representationClass, Variant variant)
          Describes a representation class and variant couple as WADL information for the given method and request.
protected  RepresentationInfo describe(MethodInfo methodInfo, ResponseInfo responseInfo, Class<?> representationClass, Variant variant)
          Describes a representation class and variant couple as WADL information for the given method and response.
 void describe(ResourceInfo info)
          Returns a WADL description of the current resource, leveraging the getResourcePath() method.
 void describe(String path, ResourceInfo info)
          Returns a WADL description of the current resource.
protected  Representation describe(Variant variant)
          Describes the resource as a WADL document for the given variant.
protected  void describeDelete(MethodInfo info)
          Describes the DELETE method.
protected  void describeGet(MethodInfo info)
          Describes the GET method.
By default, it describes the response with the available variants based on the ServerResource.getVariants() method.
protected  MethodInfo describeMethod()
          Returns a WADL description of the current method.
protected  void describeMethod(Method method, MethodInfo info)
          Returns a WADL description of the given method.
protected  void describeOptions(MethodInfo info)
          Describes the OPTIONS method.
By default it describes the response with the available variants based on the getWadlVariants() method.
protected  List<ParameterInfo> describeParameters()
          Returns the description of the parameters of this resource.
protected  void describePost(MethodInfo info)
          Describes the POST method.
protected  void describePut(MethodInfo info)
          Describes the PUT method.
protected  void doInit()
           
 String getDescription()
          Returns the description of this documented resource.
 String getName()
          Returns the name of this documented resource.
protected  NamedValue<String> getParameter(String name)
          Returns the first parameter found in the current context (entity, query, headers, etc) with the given name.
protected  Series<? extends NamedValue<String>> getParameters(String name)
          Returns a collection of parameters found in the current context (entity, query, headers, etc) given a parameter name.
protected  Variant getPreferredWadlVariant()
          Returns the preferred WADL variant according to the client preferences specified in the request.
protected  String getResourcePath()
          Returns the resource's relative path.
protected  Reference getResourcesBase()
          Returns the application resources base URI.
protected  List<Variant> getWadlVariants()
          Returns the available WADL variants.
 boolean isAutoDescribing()
          Indicates if the resource should be automatically described via WADL when an OPTIONS request is handled.
 Representation options()
           
 void setAutoDescribing(boolean autoDescribed)
          Indicates if the resource should be automatically described via WADL when an OPTIONS request is handled.
 void setDescription(String description)
          Sets the description of this documented resource.
 void setName(String name)
          Sets the name of this documented resource.
 
Methods inherited from class org.restlet.resource.ServerResource
abort, commit, delete, delete, describeVariants, doCatch, doConditionalHandle, doError, doHandle, doHandle, doNegotiatedHandle, get, get, getAttribute, getInfo, getInfo, getOnSent, getPreferredVariant, getVariants, getVariants, handle, hasAnnotations, head, head, isAnnotated, isAutoCommitting, isCommitted, isConditional, isExisting, isInRole, isNegotiated, options, post, post, put, put, redirectPermanent, redirectPermanent, redirectSeeOther, redirectSeeOther, redirectTemporary, redirectTemporary, setAllowedMethods, setAnnotated, setAttribute, setAutoCommitting, setChallengeRequests, setCommitted, setConditional, setCookieSettings, setDimensions, setExisting, setLocationRef, setLocationRef, setNegotiated, setOnSent, setProxyChallengeRequests, setServerInfo, setStatus, setStatus, setStatus, setStatus, updateAllowedMethods, updateDimensions
 
Methods inherited from class org.restlet.resource.Resource
doError, doRelease, getAllowedMethods, getApplication, getChallengeRequests, getChallengeResponse, getClientInfo, getConditions, getConnegService, getContext, getConverterService, getCookies, getCookieSettings, getDimensions, getHostRef, getLocationRef, getLogger, getMatrix, getMatrixValue, getMaxForwards, getMetadataService, getMethod, getOriginalRef, getProtocol, getProxyChallengeRequests, getProxyChallengeResponse, getQuery, getQueryValue, getRanges, getReference, getReferrerRef, getRequest, getRequestAttributes, getRequestCacheDirectives, getRequestEntity, getResponse, getResponseAttributes, getResponseCacheDirectives, getResponseEntity, getRootRef, getServerInfo, getStatus, getStatusService, init, isConfidential, isLoggable, release, setApplication, setQueryValue, setRequest, setResponse, toObject, toRepresentation, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WadlServerResource

public WadlServerResource()
Constructor.

Method Detail

canDescribe

public boolean canDescribe(Method method)
Indicates if the given method exposes its WADL description. By default, HEAD and OPTIONS are not exposed. This method is called by describe(String, ResourceInfo).

Parameters:
method - The method
Returns:
True if the method exposes its description, false otherwise.

createHtmlRepresentation

protected Representation createHtmlRepresentation(ApplicationInfo applicationInfo)
Creates a new HTML representation for a given ApplicationInfo instance describing an application.

Parameters:
applicationInfo - The application description.
Returns:
The created WadlRepresentation.

createWadlRepresentation

protected Representation createWadlRepresentation(ApplicationInfo applicationInfo)
Creates a new WADL representation for a given ApplicationInfo instance describing an application.

Parameters:
applicationInfo - The application description.
Returns:
The created WadlRepresentation.

describe

protected Representation describe()
Describes the resource as a standalone WADL document.

Returns:
The WADL description.

describe

protected void describe(ApplicationInfo applicationInfo)
Updates the description of the parent application. This is typically used to add documentation on global representations used by several methods or resources. Does nothing by default.

Parameters:
applicationInfo - The parent application.

describe

protected RepresentationInfo describe(MethodInfo methodInfo,
                                      Class<?> representationClass,
                                      Variant variant)
Describes a representation class and variant couple as WADL information. The variant contains the target media type that can be converted to by one of the available Restlet converters.

Parameters:
methodInfo - The parent method description.
representationClass - The representation bean class.
variant - The target variant.
Returns:
The WADL representation information.

describe

protected RepresentationInfo describe(MethodInfo methodInfo,
                                      RequestInfo requestInfo,
                                      Class<?> representationClass,
                                      Variant variant)
Describes a representation class and variant couple as WADL information for the given method and request. The variant contains the target media type that can be converted to by one of the available Restlet converters.

By default, it calls describe(MethodInfo, Class, Variant).

Parameters:
methodInfo - The parent method description.
requestInfo - The parent request description.
representationClass - The representation bean class.
variant - The target variant.
Returns:
The WADL representation information.

describe

protected RepresentationInfo describe(MethodInfo methodInfo,
                                      ResponseInfo responseInfo,
                                      Class<?> representationClass,
                                      Variant variant)
Describes a representation class and variant couple as WADL information for the given method and response. The variant contains the target media type that can be converted to by one of the available Restlet converters.

By default, it calls describe(MethodInfo, Class, Variant).

Parameters:
methodInfo - The parent method description.
responseInfo - The parent response description.
representationClass - The representation bean class.
variant - The target variant.
Returns:
The WADL representation information.

describe

public void describe(ResourceInfo info)
Returns a WADL description of the current resource, leveraging the getResourcePath() method.

Parameters:
info - WADL description of the current resource to update.

describe

public void describe(String path,
                     ResourceInfo info)
Returns a WADL description of the current resource.

Parameters:
path - Path of the current resource.
info - WADL description of the current resource to update.

describe

protected Representation describe(Variant variant)
Describes the resource as a WADL document for the given variant.

Parameters:
variant - The WADL variant.
Returns:
The WADL description.

describeDelete

protected void describeDelete(MethodInfo info)
Describes the DELETE method.

Parameters:
info - The method description to update.

describeGet

protected void describeGet(MethodInfo info)
Describes the GET method.
By default, it describes the response with the available variants based on the ServerResource.getVariants() method. Thus in the majority of cases, the method of the super class must be called when overridden.

Parameters:
info - The method description to update.

describeMethod

protected MethodInfo describeMethod()
Returns a WADL description of the current method.

Returns:
A WADL description of the current method.

describeMethod

protected void describeMethod(Method method,
                              MethodInfo info)
Returns a WADL description of the given method.

Parameters:
method - The method to describe.
info - The method description to update.

describeOptions

protected void describeOptions(MethodInfo info)
Describes the OPTIONS method.
By default it describes the response with the available variants based on the getWadlVariants() method.

Parameters:
info - The method description to update.

describeParameters

protected List<ParameterInfo> describeParameters()
Returns the description of the parameters of this resource. Returns null by default.

Returns:
The description of the parameters.

describePost

protected void describePost(MethodInfo info)
Describes the POST method.

Parameters:
info - The method description to update.

describePut

protected void describePut(MethodInfo info)
Describes the PUT method.

Parameters:
info - The method description to update.

doInit

protected void doInit()
               throws ResourceException
Overrides:
doInit in class Resource
Throws:
ResourceException

getDescription

public String getDescription()
Returns the description of this documented resource. Is seen as the text content of the "doc" tag of the "resource" element in a WADL document.

Returns:
The description of this documented resource.

getName

public String getName()
Returns the name of this documented resource. Is seen as the title of the "doc" tag of the "resource" element in a WADL document.

Returns:
The name of this documented resource.

getParameter

protected NamedValue<String> getParameter(String name)
Returns the first parameter found in the current context (entity, query, headers, etc) with the given name.

Parameters:
name - The parameter name.
Returns:
The first parameter found with the given name.

getParameters

protected Series<? extends NamedValue<String>> getParameters(String name)
Returns a collection of parameters found in the current context (entity, query, headers, etc) given a parameter name. It returns null if the parameter name is unknown.

Parameters:
name - The name of the parameter.
Returns:
A collection of parameters.

getPreferredWadlVariant

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

Returns:
The preferred WADL variant.

getResourcePath

protected String getResourcePath()
Returns the resource's relative path.

Returns:
The resource's relative path.

getResourcesBase

protected Reference getResourcesBase()
Returns the application resources base URI.

Returns:
The application resources base URI.

getWadlVariants

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

Returns:
The available WADL variants.

isAutoDescribing

public boolean isAutoDescribing()
Indicates if the resource should be automatically described via WADL when an OPTIONS request is handled.

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

options

public Representation options()
Overrides:
options in class ServerResource

setAutoDescribing

public void setAutoDescribing(boolean autoDescribed)
Indicates if the resource should be automatically described via WADL when an OPTIONS request is handled.

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

setDescription

public void setDescription(String description)
Sets the description of this documented resource. Is seen as the text content of the "doc" tag of the "resource" element in a WADL document.

Parameters:
description - The description of this documented resource.

setName

public void setName(String name)
Sets the name of this documented resource. Is seen as the title of the "doc" tag of the "resource" element in a WADL document.

Parameters:
name - The name of this documented resource.


Copyright © 2005-2013 Restlet.