org.restlet
Class Application

java.lang.Object
  extended by org.restlet.Uniform
      extended by org.restlet.Restlet
          extended by org.restlet.Application

public class Application
extends Restlet

Restlet that can be attached to one or more VirtualHosts. Applications are guaranteed to receive calls with their base reference set relatively to the VirtualHost that served them. This class is both a descriptor able to create the root Restlet and the actual Restlet that can be attached to one or more VirtualHost instances.

Applications also have many useful Services associated. They are available as properties that can be eventually overriden:

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
Application()
          Constructor.
Application(Context context)
          Constructor.
 
Method Summary
 Restlet createRoot()
          Creates a root Restlet that will receive all incoming calls.
 java.lang.String getAuthor()
          Returns the author(s).
 ConnectorService getConnectorService()
          Returns the connector service.
 ConverterService getConverterService()
          Deprecated. Since 1.1 with no replacement as it doesn't fit well with content negotiation. Most users prefer to handle those conversion in Resource subclasses.
static Application getCurrent()
          This variable is stored internally as a thread local variable and updated each time a call enters an application.
 DecoderService getDecoderService()
          Returns the decoder service.
 java.lang.String getDescription()
          Returns the description.
 MetadataService getMetadataService()
          Returns the metadata service.
 java.lang.String getName()
          Returns the display name.
 java.lang.String getOwner()
          Returns the owner(s).
 RangeService getRangeService()
          Returns the range service.
 Restlet getRoot()
          Returns the root Restlet.
 StatusService getStatusService()
          Returns the status service.
 TaskService getTaskService()
          Returns a task service to run concurrent tasks.
 TunnelService getTunnelService()
          Returns the tunnel service.
 void handle(Request request, Response response)
          Handles a call.
 void setAuthor(java.lang.String author)
          Sets the author(s).
 void setConnectorService(ConnectorService connectorService)
          Sets the connector service.
 void setConverterService(ConverterService converterService)
          Deprecated. Since 1.1 with no replacement as it doesn't fit well with content negotiation. Most users prefer to handle those conversion in Resource subclasses.
static void setCurrent(Application application)
          Sets the context to associated with the current thread.
 void setDecoderService(DecoderService decoderService)
          Sets the decoder service.
 void setDescription(java.lang.String description)
          Sets the description.
 void setMetadataService(MetadataService metadataService)
          Sets the metadata service.
 void setName(java.lang.String name)
          Sets the display name.
 void setOwner(java.lang.String owner)
          Sets the owner(s).
 void setRangeService(RangeService rangeService)
          Sets the range service.
 void setRoot(Restlet root)
          Sets the root Restlet.
 void setStatusService(StatusService statusService)
          Sets the status service.
 void setTaskService(TaskService taskService)
          Sets the task service.
 void setTunnelService(TunnelService tunnelService)
          Sets the tunnel service.
 void start()
          Starts the application then all the enabled associated services.
 void stop()
          Stops all the enabled associated services the the application itself.
 
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

Application

public Application()
Constructor. Note this constructor is convenient because you don't have to provide a context like for Application(Context). Therefore the context will initially be null. It's only when you attach the application to a virtual host via one of its attach*() methods that a proper context will be set.


Application

public Application(Context context)
Constructor.

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.
Method Detail

getCurrent

public static Application getCurrent()
This variable is stored internally as a thread local variable and updated each time a call enters an application. Warning: this method should only be used under duress. You should by default prefer obtaining the current application using methods such as Handler.getApplication()

Returns:
The current context.

setCurrent

public static void setCurrent(Application application)
Sets the context to associated with the current thread.

Parameters:
application - The thread's context.

createRoot

public Restlet createRoot()
Creates a root Restlet that will receive all incoming calls. In general, instances of Router, Filter or Handler classes will be used as initial application Restlet. The default implementation returns null by default. This method is intended to be overriden by subclasses.

Returns:
The root Restlet.

getAuthor

public java.lang.String getAuthor()
Returns the author(s).

Returns:
The author(s).

getConnectorService

public ConnectorService getConnectorService()
Returns the connector service. The service is enabled by default.

Returns:
The connector service.

getConverterService

@Deprecated
public ConverterService getConverterService()
Deprecated. Since 1.1 with no replacement as it doesn't fit well with content negotiation. Most users prefer to handle those conversion in Resource subclasses.

Returns the converter service. The service is enabled by default.

Returns:
The converter service.

getDecoderService

public DecoderService getDecoderService()
Returns the decoder service. The service is enabled by default.

Returns:
The decoderservice.

getDescription

public java.lang.String getDescription()
Returns the description.

Returns:
The description

getMetadataService

public MetadataService getMetadataService()
Returns the metadata service. The service is enabled by default.

Returns:
The metadata service.

getName

public java.lang.String getName()
Returns the display name.

Returns:
The display name.

getOwner

public java.lang.String getOwner()
Returns the owner(s).

Returns:
The owner(s).

getRangeService

public RangeService getRangeService()
Returns the range service.

Returns:
The range service.

getRoot

public Restlet getRoot()
Returns the root Restlet. Invokes the createRoot() method if no root has been set, and stores the Restlet created for future uses.

Returns:
The root Restlet.

getStatusService

public StatusService getStatusService()
Returns the status service. The service is enabled by default.

Returns:
The status service.

getTaskService

public TaskService getTaskService()
Returns a task service to run concurrent tasks. The service is enabled by default.

Returns:
A task service.

getTunnelService

public TunnelService getTunnelService()
Returns the tunnel service. The service is enabled by default.

Returns:
The tunnel service.

handle

public void handle(Request request,
                   Response response)
Description copied from class: Restlet
Handles a call. The default behavior is to call the (now deprecated) Restlet.init(Request, Response) method. In next version, Restlet.init(Request, Response) will be removed and its logic directly added to this method instead.

Subclasses overriding this method should make sure that they call super.handle(request, response) before adding their own logic.

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

setAuthor

public void setAuthor(java.lang.String author)
Sets the author(s).

Parameters:
author - The author(s).

setConnectorService

public void setConnectorService(ConnectorService connectorService)
Sets the connector service.

Parameters:
connectorService - The connector service.

setConverterService

@Deprecated
public void setConverterService(ConverterService converterService)
Deprecated. Since 1.1 with no replacement as it doesn't fit well with content negotiation. Most users prefer to handle those conversion in Resource subclasses.

Sets the converter service.

Parameters:
converterService - The converter service.

setDecoderService

public void setDecoderService(DecoderService decoderService)
Sets the decoder service.

Parameters:
decoderService - The decoder service.

setDescription

public void setDescription(java.lang.String description)
Sets the description.

Parameters:
description - The description.

setMetadataService

public void setMetadataService(MetadataService metadataService)
Sets the metadata service.

Parameters:
metadataService - The metadata service.

setName

public void setName(java.lang.String name)
Sets the display name.

Parameters:
name - The display name.

setOwner

public void setOwner(java.lang.String owner)
Sets the owner(s).

Parameters:
owner - The owner(s).

setRangeService

public void setRangeService(RangeService rangeService)
Sets the range service.

Parameters:
rangeService - The range service.

setRoot

public void setRoot(Restlet root)
Sets the root Restlet.

Parameters:
root - The root Restlet.

setStatusService

public void setStatusService(StatusService statusService)
Sets the status service.

Parameters:
statusService - The status service.

setTaskService

public void setTaskService(TaskService taskService)
Sets the task service.

Parameters:
taskService - The task service.

setTunnelService

public void setTunnelService(TunnelService tunnelService)
Sets the tunnel service.

Parameters:
tunnelService - The tunnel service.

start

public void start()
           throws java.lang.Exception
Starts the application then all the enabled associated services.

Overrides:
start in class Restlet
Throws:
java.lang.Exception

stop

public void stop()
          throws java.lang.Exception
Stops all the enabled associated services the the application itself.

Overrides:
stop in class Restlet
Throws:
java.lang.Exception


Copyright © 2005-2008 Noelios Technologies.