org.objectweb.jonathan.libs.kernel
Class JContextFactory.JContext

java.lang.Object
  extended by org.objectweb.jonathan.libs.kernel.JComponent
      extended by org.objectweb.jonathan.libs.kernel.JContextFactory.JContext
All Implemented Interfaces:
Component, Context, Forkable
Direct Known Subclasses:
TreeContextFactory.TreeContext
Enclosing class:
JContextFactory

protected class JContextFactory.JContext
extends JComponent
implements Context

Implementation of Context.


Nested Class Summary
protected  class JContextFactory.JContext.InnerEnumeration
           
 
Nested classes/interfaces inherited from interface org.objectweb.jonathan.apis.kernel.Context
Context.NO_VALUE
 
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
protected JContextFactory.JContext()
          Constructs a new JContext instance.
protected JContextFactory.JContext(Context _scope)
          Creates a new JContext with the specified enclosing context.
 
Method Summary
 void acquire()
          Acquires the target context.
 Element addElement(Name _name, java.lang.Class _type, int _value)
          Adds an element to the target context.
 Element addElement(Name _name, java.lang.Class _type, java.lang.Object _value)
          Adds an element in the target context.
 Element addElement(Name _name, Component _component)
          Adds an element in the target context.
 Element addElement(java.lang.String name, java.lang.Class type, int value, char separator)
          Adds an element to the target context.
 Element addElement(java.lang.String name, java.lang.Class type, java.lang.Object value, char separator)
          Adds an element to the target context.
 Element addElement(java.lang.String _name, Component _component, char separator)
          Adds an element to 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(Name _name)
           
 Context addOrGetContext(java.lang.String _name, char _separator)
           
protected  JContextFactory.JContext addOrGetLocalContext(java.lang.String _id)
           
 Component duplicate()
           
protected  void finalize()
           
 Component getComponent(java.lang.String name, char separator)
          Returns the component contained in the element registered in the target context under the name name.
 Element getElement(Name _name)
          may need to be synchronized
protected  Element getElement(java.lang.String name, boolean local)
          Returns the local element identified by name, or null if none exists.
 Element getElement(java.lang.String _name, char _separator)
          Returns the element in the target context identified by name, null if no element is registered under name name.
 java.util.Enumeration getElements()
          Returns an enumeration of the elements found in the target context.
 java.lang.Object getFactoryValue(java.lang.String name, char separator)
           
 int getIntValue(Name _name)
          Returns the value of the element registered in the target context under the name name.
 int getIntValue(java.lang.String name, char separator)
          Returns the value of the element registered in the target context under the name name.
 Context getScope()
          Returns the scope of the target context;
 java.lang.Object getValue(java.lang.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(java.lang.Class type, int value)
           
protected  Component newComponent(java.lang.Class type, java.lang.Object value)
           
protected  JContextFactory.ContextElement newContextElement(Context _container)
          Creates a new empty context element.
protected  JContextFactory.ContextElement newContextElement(java.lang.String name, Component component, Context container)
          Creates a new context element, using the provided parameters to initialize it.
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;
 java.lang.String toString()
           
 
Methods inherited from class org.objectweb.jonathan.libs.kernel.JComponent
fork, getComponent, getFactoryValue, getIntValue, getReference, getType, getValue, getValue, setReference
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.objectweb.jonathan.apis.kernel.Component
fork, getComponent, getFactoryValue, getIntValue, getReference, getType, getValue, getValue, setReference
 

Field Detail

enclosing_context

protected Context enclosing_context
The enclosing context (scope)


id

protected final int id
Identifies the target context

Constructor Detail

JContextFactory.JContext

protected JContextFactory.JContext()
Constructs a new JContext instance.


JContextFactory.JContext

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

Parameters:
_scope - a Context.
Method Detail

getElement

public final Element getElement(Name _name)
may need to be synchronized

Specified by:
getElement in interface Component
Overrides:
getElement in class JComponent
Parameters:
_name -
Returns:
the element corresponding to _name, if any.

getIntValue

public final int getIntValue(Name _name)
Description copied from interface: Context
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:
_name - the name of the element whose value is seeked;
Returns:
the corresponding value, or Integer.MAX_VALUE

getElement

public final Element getElement(java.lang.String _name,
                                char _separator)
Description copied from interface: Context
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:
_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.

getComponent

public final Component getComponent(java.lang.String name,
                                    char separator)
Description copied from interface: Context
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.

getFactoryValue

public final java.lang.Object getFactoryValue(java.lang.String name,
                                              char separator)
                                       throws JonathanException
Throws:
JonathanException

getValue

public final java.lang.Object getValue(java.lang.String name,
                                       char separator)
Description copied from interface: Context
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.

getIntValue

public final int getIntValue(java.lang.String name,
                             char separator)
Description copied from interface: Context
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

addElement

public final Element addElement(Name _name,
                                Component _component)
                         throws JonathanException
Description copied from interface: Context
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:
_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).

addElement

public final Element addElement(Name _name,
                                java.lang.Class _type,
                                java.lang.Object _value)
                         throws JonathanException
Description copied from interface: Context
Adds an element in the target context.

Specified by:
addElement in interface 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 final Element addElement(Name _name,
                                java.lang.Class _type,
                                int _value)
                         throws JonathanException
Description copied from interface: Context
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:
_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 final Element addElement(java.lang.String _name,
                                Component _component,
                                char separator)
                         throws JonathanException
Description copied from interface: Context
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:
_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 final Element addElement(java.lang.String name,
                                java.lang.Class type,
                                java.lang.Object value,
                                char separator)
                         throws JonathanException
Description copied from interface: Context
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(java.lang.String name,
                                java.lang.Class type,
                                int value,
                                char separator)
                         throws JonathanException
Description copied from interface: Context
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).

addOrGetContext

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

addOrGetContext

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

getElements

public java.util.Enumeration getElements()
Description copied from interface: Context
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.

getScope

public Context getScope()
Description copied from interface: Context
Returns the scope of the target context;

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

internalFork

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

setScope

public Context setScope(Context scope)
Description copied from interface: Context
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;

reset

public void reset()
needs to be synchronized.

Specified by:
reset in interface Context
Overrides:
reset in class JComponent

acquire

public void acquire()
Description copied from interface: Context
Acquires the target context.

Specified by:
acquire in interface Context

release

public void release()
Description copied from interface: Context
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

duplicate

public Component duplicate()
Overrides:
duplicate in class JComponent

toString

public java.lang.String toString()
Overrides:
toString in class JComponent

recycle

protected void recycle()

getElement

protected Element getElement(java.lang.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.

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:
name - the name of the new Element.
type - the declared type of the new Element.
value - the value of the Element to be inserted.
Returns:
the Element already present in the Context with the same name, null if none existed.
Throws:
JonathanException

newContextElement

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

Returns:
a new context element.

newContextElement

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

Parameters:
name - a name;
type - a type;
value - an object reference value;
int_value - an integer value;
Returns:
a new context element, initialized using the provided parameters

newComponent

protected Component newComponent(java.lang.Class type,
                                 java.lang.Object value)

newComponent

protected Component newComponent(java.lang.Class type,
                                 int value)

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

addOrGetLocalContext

protected JContextFactory.JContext addOrGetLocalContext(java.lang.String _id)
                                                 throws JonathanException
Throws:
JonathanException

handleScopeElement

protected Element handleScopeElement(Element element)