org.objectweb.jonathan.apis.kernel

Interface Context

All Superinterfaces:
Component
Known Implementing Classes:
JConfigurationFactory.JConfiguration, JContextFactory.JContext, TreeContextFactory.TreeContext

public interface Context
extends Component

A context represents a set of typed objects, each identified by a name.

Nested Class Summary

class
Context.NO_VALUE

Field Summary

static Object
NO_VALUE
The NO_VALUE object is returned by getValue if no value corresponds to the provided name.

Method Summary

void
acquire()
Acquires the target context.
Element
addElement(String name, Class type, Object value, char separator)
Adds an element to the target context.
Element
addElement(String name, Class type, int value, char separator)
Adds an element to the target context.
Element
addElement(String name, Component component, char separator)
Adds an element to the target context.
Element
addElement(Name name, Class type, Object value)
Adds an element in the target context.
Element
addElement(Name name, Class type, int value)
Adds an element to the target context.
Element
addElement(Name name, Component component)
Adds an element in the target context.
Context
addOrGetContext(String _name, char _separator)
Context
addOrGetContext(Name _name)
Component
getComponent(String name, char separator)
Returns the component contained in the element registered in the target context under the name name.
Element
getElement(String name, char separator)
Returns the element in the target context identified by name, null if no element is registered under name name.
Enumeration
getElements()
Returns an enumeration of the elements found in the target context.
int
getIntValue(String name, char separator)
Returns the value of the element registered in the target context under the name name.
int
getIntValue(Name name)
Returns the value of the element registered in the target context under the name name.
Context
getScope()
Returns the scope of the target context;
Object
getValue(String name, char separator)
Returns the value of the element registered in the target context under the name name.
void
release()
Releases the target context, releasing all the resources it uses, if no one still uses it.
void
reset()
Resets the target context, removing all its current elements.
Context
setScope(Context scope)
Sets the scope of the target context;

Methods inherited from interface org.objectweb.jonathan.apis.kernel.Component

fork, getComponent, getElement, getFactoryValue, getIntValue, getReference, getType, getValue, getValue, setReference

Field Details

NO_VALUE

public static final Object NO_VALUE
The NO_VALUE object is returned by getValue if no value corresponds to the provided name.

Method Details

acquire

public void acquire()
Acquires the target context.


addElement

public Element addElement(String name,
                          Class type,
                          Object value,
                          char separator)
            throws JonathanException
Adds an element to the target context. This method is equivalent to addElement(Name,Class,Object), except that the name to use is specified by a string and a separator separating the different elements of the name. If separator == 0, the name corresponds to an object local to the target context. If the name begins with the separator, the name is an absolute name (this only makes sense if the context has a tree structure); otherwise, the name is relative to the target context.

Parameters:
name - a string representing the name of the seeked element;
type - the type of the object to be added;
value - the object to be added;
separator - the separator character used to parse name;

Returns:
the previous element, if any; null otherwise.

Throws:
JonathanException - if something goes wrong (usually, a type exception).


addElement

public Element addElement(String name,
                          Class type,
                          int value,
                          char separator)
            throws JonathanException
Adds an element to the target context. This method is equivalent to addElement(Name,Class,int), except that the name to use is specified by a string and a separator separating the different elements of the name. If separator == 0, the name corresponds to an object local to the target context. If the name begins with the separator, the name is an absolute name (this only makes sense if the context has a tree structure); otherwise, the name is relative to the target context.

Parameters:
name - a string representing the name of the seeked element;
value - the integer value of the element to be added;
separator - the separator character used to parse name;

Returns:
the previous element, if any; null otherwise.

Throws:
JonathanException - if something goes wrong (usually, a type exception).


addElement

public Element addElement(String name,
                          Component component,
                          char separator)
            throws JonathanException
Adds an element to the target context. This method is equivalent to addElement(Name,Component), except that the name to use is specified by a string and a separator separating the different elements of the name. If separator == 0, the name corresponds to an object local to the target context. If the name begins with the separator, the name is an absolute name (this only makes sense if the context has a tree structure); otherwise, the name is relative to the target context.

Parameters:
name - a string representing the name of the added element;
component - the component to be added;
separator - the separator character used to parse name;

Returns:
the previous element, if any; null otherwise.

Throws:
JonathanException - if something goes wrong (usually, a type exception).


addElement

public Element addElement(Name name,
                          Class type,
                          Object value)
            throws JonathanException
Adds an element in the target context.

Parameters:
name - the name of the object to be added;
type - the type of the object to be added;
value - the object to be added.

Returns:
the previous element, if any; null otherwise.

Throws:
JonathanException - if something goes wrong (usually, a type exception).


addElement

public Element addElement(Name name,
                          Class type,
                          int value)
            throws JonathanException
Adds an element to the target context. In this case, the value's type must be promotable to an integer. Class is one of int.class, short.class, char.class, or byte.class.

Parameters:
name - the name of the element to be added;
value - the integer value of the element to be added;

Returns:
the previous element, if any, null otherwise.

Throws:
JonathanException - if something goes wrong (usually, a type exception).


addElement

public Element addElement(Name name,
                          Component component)
            throws JonathanException
Adds an element in the target context. If the component is already attached to some element, this attachment will be lost in this operation.

Parameters:
name - the name of the element to be added;
component - the component to be added;

Returns:
the previous element, if any; null otherwise.

Throws:
JonathanException - if something goes wrong (usually, a type exception).


addOrGetContext

public Context addOrGetContext(String _name,
                               char _separator)
            throws JonathanException


addOrGetContext

public Context addOrGetContext(Name _name)
            throws JonathanException


getComponent

public Component getComponent(String name,
                              char separator)
Returns the component contained in the element registered in the target context under the name name. This method is equivalent to getComponent(Name), except that the name to use is specified by a string and a separator separating the different elements of the name. If separator == 0, the name corresponds to an object local to the target context. If the name begins with the separator, the name is an absolute name (this only makes sense if the context has a tree structure); otherwise, the name is relative to the target context.

Parameters:
name - the name of the element whose component is seeked;
separator - the separator character used to parse name;

Returns:
the corresponding component, or null.


getElement

public Element getElement(String name,
                          char separator)
Returns the element in the target context identified by name, null if no element is registered under name name. This method is equivalent to getElement(Name), except that the name to use is specified by a string and a separator separating the different elements of the name. If separator == 0, the name corresponds to an object local to the target context. If the name begins with the separator, the name is an absolute name (this only makes sense if the context has a tree structure); otherwise, the name is relative to the target context.

Parameters:
name - a string representing the name of the seeked element;
separator - the separator character used to parse name;

Returns:
the corresponding element, if any; null otherwise.


getElements

public Enumeration getElements()
Returns an enumeration of the elements found in the target context.

Returns:
an enumeration of the elements found in the target context.


getIntValue

public int getIntValue(String name,
                       char separator)
Returns the value of the element registered in the target context under the name name. This method is equivalent to getIntValue(Name), except that the name to use is specified by a string and a separator separating the different elements of the name. If separator == 0, the name corresponds to an object local to the target context. If the name begins with the separator, the name is an absolute name (this only makes sense if the context has a tree structure); otherwise, the name is relative to the target context.

Parameters:
name - the name of the element whose value is seeked;
separator - the separator character used to parse name;

Returns:
the corresponding value, or Integer.MAX_VALUE


getIntValue

public int getIntValue(Name name)
Returns the value of the element registered in the target context under the name name.

A call to getIntValue(name) is equivalent to getElement(name).getIntValue() if the provided name actually corresponds to an element. If it is not the case, Integer.MAX_VALUE is returned.

Parameters:
name - the name of the element whose value is seeked;

Returns:
the corresponding value, or Integer.MAX_VALUE


getScope

public Context getScope()
Returns the scope of the target context;

Returns:
the scope of the target context;


getValue

public Object getValue(String name,
                       char separator)
Returns the value of the element registered in the target context under the name name. This method is equivalent to getValue(Name), except that the name to use is specified by a string and a separator separating the different elements of the name. If separator == 0, the name corresponds to an object local to the target context. If the name begins with the separator, the name is an absolute name (this only makes sense if the context has a tree structure); otherwise, the name is relative to the target context.

Parameters:
name - the name of the element whose value is seeked;
separator - the separator character used to parse name;

Returns:
the corresponding value, or NO_VALUE.


release

public void release()
Releases the target context, releasing all the resources it uses, if no one still uses it. The context should no longer be used once it has been released.


reset

public void reset()
Resets the target context, removing all its current elements.


setScope

public Context setScope(Context scope)
Sets the scope of the target context;

Parameters:
scope - the new scope of the target context;

Returns:
the previous scope of the target context;