org.restlet.client
Class Context

java.lang.Object
  extended by org.restlet.client.Context

public class Context
extends Object

Contextual data and services provided to a set of Restlets. The context is the means by which a Restlet may access the software environment within the framework. It is typically provided by the immediate parent Restlet (Application is the most common case).

Concurrency note: attributes and parameters of a context are stored in concurrent collections that guarantee thread safe access and modification. If several threads concurrently access objects and modify these collections, they should synchronize on the lock of the Context instance.

Author:
Jerome Louvel

Constructor Summary
Context()
          Constructor.
Context(Logger logger)
          Constructor.
Context(String loggerName)
          Constructor.
 
Method Summary
 Context createChildContext()
          Creates a protected child context.
 ConcurrentMap<String,Object> getAttributes()
          Returns a modifiable attributes map that can be used by developers to save information relative to the context.
 Client getClientDispatcher()
          Returns a request dispatcher to available client connectors.
static Context getCurrent()
          Returns the context associated to the current Restlet.
static Logger getCurrentLogger()
          Returns the current context's logger.
 Logger getLogger()
          Returns the logger.
 Series<Parameter> getParameters()
          Returns the modifiable series of parameters.
 void setAttributes(Map<String,Object> attributes)
          Sets the modifiable map of attributes.
 void setClientDispatcher(Client clientDispatcher)
          Sets the client dispatcher.
 void setLogger(Logger logger)
          Sets the logger.
 void setLogger(String loggerName)
          Sets the logger.
 void setParameters(Series<Parameter> parameters)
          Sets the modifiable series of parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Context

public Context()
Constructor. Writes log messages to "org.restlet.client".


Context

public Context(Logger logger)
Constructor.

Parameters:
logger - The logger instance of use.

Context

public Context(String loggerName)
Constructor.

Parameters:
loggerName - The name of the logger to use.
Method Detail

getCurrent

public static Context getCurrent()
Returns the context associated to the current Restlet. The context can be the one of a Component, an Application, a Filter or any other Restlet subclass. Warning: this method should only be used under duress. You should by default prefer obtaining the current context using methods such as Restlet.getContext() or org.restlet.client.resource.Resource#getContext(). This variable is stored internally as a thread local variable and updated each time a request is handled by a Restlet via the Restlet.handle(org.restlet.client.Request, org.restlet.client.Response) method.

Returns:
The current context.

getCurrentLogger

public static Logger getCurrentLogger()
Returns the current context's logger.

Returns:
The current context's logger.

createChildContext

public Context createChildContext()
Creates a protected child context. This is especially useful for new application attached to their parent component, to ensure their isolation from the other applications. By default it just creates a new context instance.

Returns:
The child context.

getAttributes

public ConcurrentMap<String,Object> getAttributes()
Returns a modifiable attributes map that can be used by developers to save information relative to the context. This is a convenient means to provide common objects to all the Restlets and Resources composing an Application.

In addition, this map is a shared space between the developer and the Restlet implementation. For this purpose, all attribute names starting with "org.restlet.client" are reserved. Currently the following attributes are used:
Attribute name Class name Description
org.restlet.client.application org.restlet.client.Application The parent application providing this context, if any.

Returns:
The modifiable attributes map.

getClientDispatcher

public Client getClientDispatcher()
Returns a request dispatcher to available client connectors. When you ask the dispatcher to handle a request, it will automatically select the appropriate client connector for your request, based on the request.protocol property or on the resource URI's scheme. This call is blocking and will return an updated response object.

Returns:
A request dispatcher to available client connectors.

getLogger

public Logger getLogger()
Returns the logger.

Returns:
The logger.

getParameters

public Series<Parameter> getParameters()
Returns the modifiable series of parameters. A parameter is a pair composed of a name and a value and is typically used for configuration purpose, like Java properties. Note that multiple parameters with the same name can be declared and accessed.

Returns:
The modifiable series of parameters.

setAttributes

public void setAttributes(Map<String,Object> attributes)
Sets the modifiable map of attributes. This method clears the current map and puts all entries in the parameter map.

Parameters:
attributes - A map of attributes.

setClientDispatcher

public void setClientDispatcher(Client clientDispatcher)
Sets the client dispatcher.

Parameters:
clientDispatcher - The new client dispatcher.

setLogger

public void setLogger(Logger logger)
Sets the logger.

Parameters:
logger - The logger.

setLogger

public void setLogger(String loggerName)
Sets the logger.

Parameters:
loggerName - The name of the logger to use.

setParameters

public void setParameters(Series<Parameter> parameters)
Sets the modifiable series of parameters. This method clears the current series and adds all entries in the parameter series.

Parameters:
parameters - A series of parameters.


Copyright © 2005-2010 Noelios Technologies.