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 handler that will effectively handle the call. Based on a given Handler subclass, it is also capable of instantiating the handler with the call's context, request and response without requiring the usage of a Finder 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 handler 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 Handler 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.

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
See Also:
Tutorial: Reaching target Resources

Constructor Summary
Finder()
          Constructor.
Finder(Context context)
          Constructor.
Finder(Context context, java.lang.Class<? extends Handler> targetClass)
          Constructor.
 
Method Summary
 Handler createResource(Request request, Response response)
          Deprecated. Use the createTarget(Request, Response) instead.
 Handler createTarget(java.lang.Class<? extends Handler> targetClass, Request request, Response response)
          Creates a new instance of a given handler class.
protected  Handler createTarget(Request request, Response response)
          Creates a new instance of the handler class designated by the "targetClass" property.
protected  Handler findTarget(Request request, Response response)
          Finds the target Handler if available.
 java.lang.Class<? extends Handler> getTargetClass()
          Returns the target Handler class.
 void handle(Request request, Response response)
          Handles a call.
 void setTargetClass(java.lang.Class<? extends Handler> targetClass)
          Sets the target Handler class.
 
Methods inherited from class org.restlet.Restlet
getApplication, 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,
              java.lang.Class<? extends Handler> targetClass)
Constructor.

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

createResource

@Deprecated
public Handler createResource(Request request,
                                         Response response)
Deprecated. Use the createTarget(Request, Response) instead.

Creates a new instance of the handler class designated by the "targetClass" property. The default behavior is to invoke the createTarget(Class, Request, Response) with the "targetClass" property as a parameter.

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

createTarget

public Handler createTarget(java.lang.Class<? extends Handler> targetClass,
                            Request request,
                            Response response)
Creates a new instance of a given handler class. Note that Error and RuntimeException thrown by Handler constructors are rethrown by this method. Other exception are caught and logged.

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

createTarget

protected Handler createTarget(Request request,
                               Response response)
Creates a new instance of the handler class designated by the "targetClass" property. The default behavior is to invoke the createTarget(Class, Request, Response) with the "targetClass" property as a parameter.

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

findTarget

protected Handler findTarget(Request request,
                             Response response)
Finds the target Handler if available. The default behavior is to invoke the createTarget(Request, Response) method.

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

getTargetClass

public java.lang.Class<? extends Handler> getTargetClass()
Returns the target Handler class.

Returns:
the target Handler 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.

setTargetClass

public void setTargetClass(java.lang.Class<? extends Handler> targetClass)
Sets the target Handler class.

Parameters:
targetClass - The target Handler class.


Copyright © 2005-2008 Noelios Technologies.