org.objectweb.jonathan.libs.kernel

Class JContextFactory.JContext

Enclosing Class:
JContextFactory
Implemented Interfaces:
Component, Context, Forkable
Known Direct Subclasses:
TreeContextFactory.TreeContext

protected class JContextFactory.JContext
extends JComponent
implements Context

Implementation of Context.

Nested Class Summary

protected class
JContextFactory.JContext.InnerEnumeration

Field Summary

protected Context
enclosing_context
The enclosing context (scope)
protected int
id
Identifies the target context

Fields inherited from class org.objectweb.jonathan.libs.kernel.JComponent

int_value, reference, type, value

Fields inherited from interface org.objectweb.jonathan.apis.kernel.Context

NO_VALUE

Constructor Summary

JContext()
Constructs a new JContext instance.
JContext(Context _scope)
Creates a new JContext with the specified enclosing context.

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.
protected Element
addLocalElement(JContextFactory.ContextElement element, boolean _check_types)
Adds an Element to the Context if no other exists with the same name.
Context
addOrGetContext(String _name, char _separator)
Context
addOrGetContext(Name _name)
protected JContextFactory.JContext
addOrGetLocalContext(String _id)
Component
duplicate()
protected void
finalize()
Component
getComponent(String name, char separator)
Returns the component contained in the element registered in the target context under the name name.
protected Element
getElement(String name, boolean local)
Returns the local element identified by name, or null if none exists.
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.
Element
getElement(Name _name)
may need to be synchronized
Enumeration
getElements()
Returns an enumeration of the elements found in the target context.
Object
getFactoryValue(String name, char separator)
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.
protected Element
handleScopeElement(Element element)
Component
internalFork()
protected Component
newComponent(Class type, Object value)
protected Component
newComponent(Class type, int value)
protected JContextFactory.ContextElement
newContextElement(String name, Component component, Context container)
Creates a new context element, using the provided parameters to initialize it.
protected JContextFactory.ContextElement
newContextElement(Context _container)
Creates a new empty context element.
protected void
recycle()
void
release()
Releases the target context, releasing all the resources it uses, if no one still uses it.
void
reset()
needs to be synchronized.
Context
setScope(Context scope)
Sets the scope of the target context;
String
toString()

Methods inherited from class org.objectweb.jonathan.libs.kernel.JComponent

duplicate, fork, getComponent, getElement, getFactoryValue, getIntValue, getReference, getType, getValue, getValue, internalFork, reset, setReference, toString

Field Details

enclosing_context

protected Context enclosing_context
The enclosing context (scope)


id

protected final int id
Identifies the target context

Constructor Details

JContext

protected JContext()
Constructs a new JContext instance.


JContext

protected JContext(Context _scope)
Creates a new JContext with the specified enclosing context.

Parameters:
_scope - a Context.

Method Details

acquire

public void acquire()
Acquires the target context.
Specified by:
acquire in interface Context


addElement

public final 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.
Specified by:
addElement in interface 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 final 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.
Specified by:
addElement in interface 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 final 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.
Specified by:
addElement in interface Context

Parameters:
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 final Element addElement(Name _name,
                                Class _type,
                                Object _value)
            throws JonathanException
Adds an element in the target context.
Specified by:
addElement in interface Context

Parameters:

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

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


addElement

public final 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.
Specified by:
addElement in interface Context

Parameters:

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

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


addElement

public final 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.
Specified by:
addElement in interface Context

Parameters:

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

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


addLocalElement

protected Element addLocalElement(JContextFactory.ContextElement element,
                                  boolean _check_types)
            throws JonathanException
Adds an Element to the Context if no other exists with the same name.

must be called in a synchronized context

Parameters:

Returns:
the Element already present in the Context with the same name, null if none existed.

Throws:
JonathanException -


addOrGetContext

public Context addOrGetContext(String _name,
                               char _separator)
            throws JonathanException
Specified by:
addOrGetContext in interface Context


addOrGetContext

public Context addOrGetContext(Name _name)
            throws JonathanException
Specified by:
addOrGetContext in interface Context


addOrGetLocalContext

protected JContextFactory.JContext addOrGetLocalContext(String _id)
            throws JonathanException


duplicate

public Component duplicate()
Overrides:
duplicate in interface JComponent


finalize

protected void finalize()
            throws Throwable


getComponent

public final 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.
Specified by:
getComponent in interface 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

protected Element getElement(String name,
                             boolean local)
Returns the local element identified by name, or null if none exists.

Parameters:
name - a local name;
local - if true, don't search the enclosing context.

Returns:
the local element identified by name, or null if none exists.


getElement

public final 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.
Specified by:
getElement in interface Context

Parameters:

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


getElement

public final Element getElement(Name _name)
may need to be synchronized
Specified by:
getElement in interface Component
Overrides:
getElement in interface JComponent

Parameters:
_name -

Returns:
the element corresponding to _name, if any.


getElements

public Enumeration getElements()
Returns an enumeration of the elements found in the target context.
Specified by:
getElements in interface Context

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


getFactoryValue

public final Object getFactoryValue(String name,
                                    char separator)
            throws JonathanException


getIntValue

public final 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.
Specified by:
getIntValue in interface 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 final 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.

Specified by:
getIntValue in interface Context

Parameters:

Returns:
the corresponding value, or Integer.MAX_VALUE


getScope

public Context getScope()
Returns the scope of the target context;
Specified by:
getScope in interface Context

Returns:
the scope of the target context;


getValue

public final 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.
Specified by:
getValue in interface 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.


handleScopeElement

protected Element handleScopeElement(Element element)


internalFork

public Component internalFork()
Specified by:
internalFork in interface Forkable
Overrides:
internalFork in interface JComponent


newComponent

protected Component newComponent(Class type,
                                 Object value)


newComponent

protected Component newComponent(Class type,
                                 int value)


newContextElement

protected final JContextFactory.ContextElement newContextElement(String name,
                                                                 Component component,
                                                                 Context container)
Creates a new context element, using the provided parameters to initialize it.

Parameters:
name - a name;

Returns:
a new context element, initialized using the provided parameters


newContextElement

protected JContextFactory.ContextElement newContextElement(Context _container)
Creates a new empty context element.

Returns:
a new context element.


recycle

protected void recycle()


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.
Specified by:
release in interface Context


reset

public void reset()
needs to be synchronized.
Specified by:
reset in interface Context
Overrides:
reset in interface JComponent


setScope

public Context setScope(Context scope)
Sets the scope of the target context;
Specified by:
setScope in interface Context

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

Returns:
the previous scope of the target context;


toString

public String toString()
Overrides:
toString in interface JComponent