org.restlet.resource

## Class Finder

- java.lang.Object
- - org.restlet.Restlet
  - - org.restlet.resource.Finder

All Implemented Interfaces:
  Uniform

Direct Known Subclasses:
  Directory

    public class Finder
    extends Restlet

Restlet that can find the target server resource that will effectively handle incoming calls. By default, based on a given `ServerResource` (or the now deprecated `Handler`) subclass available via the `getTargetClass()` method, it automatically instantiates for each incoming call the target resource class using its default constructor and invoking the `UniformResource.init(Context, Request, Response)` method.
Once the target has been created, the call is automatically dispatched to the `ServerResource.handle()` method (or for `Handler` subclasses to the handle*() method (where the '*' character corresponds to the method name) if the corresponding allow*() method returns true).
Once the call is handled, the `UniformResource.release()` method is invoked to permit clean-up actions.
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

Constructors
Constructor and Description
`Finder()` Constructor.
`Finder(Context context)` Constructor.
`Finder(Context context, java.lang.Class<?> targetClass)` Constructor.

### Method Summary

Methods
`ServerResource` `create(java.lang.Class<? extends ServerResource> targetClass, Request request, Response response)` Creates a new instance of a given `ServerResource` subclass.
`ServerResource` `create(Request request, Response response)` Creates a new instance of the `ServerResource` subclass designated by the "targetClass" property.
`static Finder` `createFinder(java.lang.Class<?> targetClass, java.lang.Class<? extends Finder> finderClass, Context context, java.util.logging.Logger logger)` Creates a new finder instance based on the "targetClass" property.
`protected Handler` `createTarget(java.lang.Class<? extends Handler> targetClass, Request request, Response response)` Deprecated. Use `create(Request, Response)` instead.
`protected Handler` `createTarget(Request request, Response response)` Deprecated. Use `create(Request, Response)` instead.
`ServerResource` `find(Request request, Response response)` Finds the target `ServerResource` if available.
`Handler` `findTarget(Request request, Response response)` Deprecated. Use `find(Request, Response)` instead.
`java.lang.Class<?>` `getTargetClass()` Returns the target handler class which must be either a subclass of `Handler` or of `ServerResource`.
`void` `handle(Request request, Response response)` Handles a call.
`void` `setTargetClass(java.lang.Class<?> targetClass)` Sets the target handler class which must be either a subclass of `Handler` or of `ServerResource`.

### Methods inherited from class org.restlet.Restlet

`finalize, getApplication, getAuthor, getContext, getDescription, getLogger, getName, getOwner, isStarted, isStopped, setAuthor, setContext, setDescription, setName, setOwner, start, stop`

### Methods inherited from class java.lang.Object

`clone, equals, 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<?> targetClass)

Constructor.

Parameters:
  `context` - The context.
  `targetClass` - The target handler class. It must be either a subclass of `Handler` or of `ServerResource`.

### Method Detail

#### createFinder

    public static Finder createFinder(java.lang.Class<?> targetClass,
                      java.lang.Class<? extends Finder> finderClass,
                      Context context,
                      java.util.logging.Logger logger)

Creates a new finder instance based on the "targetClass" property.

Parameters:
  `targetClass` - The target Resource class to attach.
  `finderClass` - The optional finder class to instantiate.
  `logger` - The logger.
Returns:
  The new finder instance.

#### create

    public ServerResource create(java.lang.Class<? extends ServerResource> targetClass,
                        Request request,
                        Response response)

Creates a new instance of a given `ServerResource` subclass. Note that Error and RuntimeException thrown by `ServerResource` constructors are re-thrown 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.

#### create

    public ServerResource create(Request request,
                        Response response)

Creates a new instance of the `ServerResource` subclass designated by the "targetClass" property. The default behavior is to invoke the `create(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

    @Deprecated
    protected Handler createTarget(java.lang.Class<? extends Handler> targetClass,
                                  Request request,
                                  Response response)

Deprecated. Use `create(Request, Response)` instead.
Creates a new instance of a given handler class. Note that Error and RuntimeException thrown by Handler constructors are re-thrown 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

    @Deprecated
    protected Handler createTarget(Request request,
                                  Response response)

Deprecated. Use `create(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.

#### find

    public ServerResource find(Request request,
                      Response response)

Finds the target `ServerResource` if available. The default behavior is to invoke the `create(Request, Response)` method.

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

#### findTarget

    @Deprecated
    public Handler findTarget(Request request,
                                Response response)

Deprecated. Use `find(Request, Response)` instead.
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<?> getTargetClass()

Returns the target handler class which must be either a subclass of `Handler` or of `ServerResource`.

Returns:
  the target Handler class.

#### handle

    public void handle(Request request,
              Response response)

Handles a call.

Specified by:
  `handle` in interface `Uniform`
Overrides:
  `handle` in class `Restlet`
Parameters:
  `request` - The request to handle.
  `response` - The response to update.

#### setTargetClass

    public void setTargetClass(java.lang.Class<?> targetClass)

Sets the target handler class which must be either a subclass of `Handler` or of `ServerResource`.

Parameters:
  `targetClass` - The target handler class. It must be either a subclass of `Handler` or of `ServerResource`.