org.restlet
Class Finder

java.lang.Object
  extended by org.restlet.Uniform
      extended by org.restlet.Restlet
          extended by org.restlet.Finder
Direct Known Subclasses:
Directory

public class Finder
extends Restlet

Restlet that can find the target resource that will concretely handle a call. Based on a given resource class, it is also capable of instantiating the resource with the call's context, request and response without requiring the usage of a subclass. It will use either the constructor with three arguments: context, request, response; or it will invoke the default constructor then invoke the init() method with the same arguments.

Once the target resource has been found, the call is automatically dispatched to the appropriate handle*() method (where the '*' character corresponds to the method name) if the corresponding allow*() method returns true.

For example, if you want to support a MOVE method for a WebDAV server, you just have to add a handleMove() method in your subclass of Resource and it will be automatically be used by the Finder instance at runtime.

If no matching handle*() method is found, then a Status.CLIENT_ERROR_METHOD_NOT_ALLOWED is returned.

Author:
Jerome Louvel (contact@noelios.com)
See Also:
Tutorial: Reaching target Resources

Constructor Summary
Finder()
          Constructor.
Finder(Context context)
          Constructor.
Finder(Context context, Class<? extends Resource> targetClass)
          Constructor.
 
Method Summary
 Resource createResource(Request request, Response response)
          Creates a new instance of the resource class designated by the "targetClass" property.
 Resource findTarget(Request request, Response response)
          Finds the target Resource if available.
 Class<? extends Resource> getTargetClass()
          Returns the target Resource class.
 void handle(Request request, Response response)
          Handles a call.
 
Methods inherited from class org.restlet.Restlet
getContext, getLogger, init, isStarted, isStopped, setContext, start, stop
 
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

Finder

public Finder()
Constructor.


Finder

public Finder(Context context)
Constructor.

Parameters:
context - The context.

Finder

public Finder(Context context,
              Class<? extends Resource> targetClass)
Constructor.

Parameters:
context - The context.
targetClass - The target resource class.
Method Detail

findTarget

public Resource findTarget(Request request,
                           Response response)
Finds the target Resource if available. The default behavior is to invoke the createResource(Request, Response) method.

Parameters:
request - The request to handle.
response - The response to update.
Returns:
The target resource if available or null.

createResource

public Resource createResource(Request request,
                               Response response)
Creates a new instance of the resource class designated by the "targetClass" property.

Parameters:
request - The request to handle.
response - The response to update.
Returns:
The created resource or null.

getTargetClass

public Class<? extends Resource> getTargetClass()
Returns the target Resource class.

Returns:
the target Resource class.

handle

public void handle(Request request,
                   Response response)
Handles a call.

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


Copyright © 2005-2007 Noelios Technologies.