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

java.lang.Object
  |
  +--org.objectweb.jonathan.libs.kernel.JContextFactory.JContext
All Implemented Interfaces:
Context
Direct Known Subclasses:
TreeContextFactory.TreeContext
Enclosing class:
JContextFactory

protected class JContextFactory.JContext
extends Object
implements Context

Implementation of Context.


Inner Class Summary
protected  class JContextFactory.JContext.InnerEnumeration
           
 
Inner classes inherited from class 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 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(Element _element)
          Adds an element to the target context.
 Element addElement(Name _name, Class _type, int _value)
          Adds an element to the target context.
 Element addElement(Name _name, Class _type, Object _value)
          Adds an element in the target context.
 Element addElement(String name, Class type, int value, char separator)
          Adds an element to the target context.
 Element addElement(String name, Class type, Object value, 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.
protected  JContextFactory.JContext addOrGetContext(Name _name)
           
protected  JContextFactory.JContext addOrGetLocalContext(String _id)
           
protected  void finalize()
           
 Element getElement(Name _name)
          may need to be synchronized
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.
 Enumeration getElements()
          Returns an enumeration of the elements found in the target context.
 int getIntValue(Name _name)
          Returns the value of the element registered in the target context under the name name.
 int getIntValue(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;
 Object getValue(Name _name)
          Returns the value of the element registered in the target context under the name name.
 Object getValue(String name, char separator)
          Returns the value of the element registered in the target context under the name name.
protected  JContextFactory.ContextElement newContextElement()
          Creates a new empty context element.
protected  JContextFactory.ContextElement newContextElement(String name, Class type, Object value, int int_value)
          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;
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 Element getElement(Name _name)
may need to be synchronized
Specified by:
getElement in interface Context
Parameters:
_name -  
Returns:
the element corresponding to _name, if any.

getValue

public Object getValue(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 getValue(name) is equivalent to getElement(name).getValue() if the provided name actually corresponds to an element. If it is not the case, NO_VALUE is returned.
Specified by:
getValue in interface Context
Following copied from interface: org.objectweb.jonathan.apis.kernel.Context
Parameters:
name - the name of the element whose value is seeked;
Returns:
the corresponding value, or NO_VALUE.

getIntValue

public 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
Following copied from interface: org.objectweb.jonathan.apis.kernel.Context
Parameters:
name - the name of the element whose value is seeked;
Returns:
the corresponding value, or Integer.MAX_VALUE

getElement

public Element getElement(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
Following copied from interface: org.objectweb.jonathan.apis.kernel.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.

getValue

public Object getValue(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
Following copied from interface: org.objectweb.jonathan.apis.kernel.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 int getIntValue(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
Following copied from interface: org.objectweb.jonathan.apis.kernel.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 Element addElement(Name _name,
                          Class _type,
                          Object _value)
                   throws JonathanException
Description copied from interface: Context
Adds an element in the target context.
Specified by:
addElement in interface Context
Following copied from interface: org.objectweb.jonathan.apis.kernel.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
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
Following copied from interface: org.objectweb.jonathan.apis.kernel.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 Element addElement(Element _element)
                   throws JonathanException
Description copied from interface: Context
Adds an element to the target context.
Specified by:
addElement in interface Context
Following copied from interface: org.objectweb.jonathan.apis.kernel.Context
Parameters:
element - 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(String name,
                          Class type,
                          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
Following copied from interface: org.objectweb.jonathan.apis.kernel.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
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
Following copied from interface: org.objectweb.jonathan.apis.kernel.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).

getElements

public Enumeration getElements()
Description copied from interface: Context
Returns an enumeration of the elements found in the target context.
Specified by:
getElements in interface Context
Following copied from interface: org.objectweb.jonathan.apis.kernel.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
Following copied from interface: org.objectweb.jonathan.apis.kernel.Context
Returns:
the scope of the target context;

setScope

public Context setScope(Context scope)
Description copied from interface: Context
Sets the scope of the target context;
Specified by:
setScope in interface Context
Following copied from interface: org.objectweb.jonathan.apis.kernel.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

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

recycle

protected void recycle()

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.

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()
Creates a new empty context element.
Returns:
a new context element.

newContextElement

protected JContextFactory.ContextElement newContextElement(String name,
                                                           Class type,
                                                           Object value,
                                                           int int_value)
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

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object

addOrGetContext

protected JContextFactory.JContext addOrGetContext(Name _name)
                                            throws JonathanException

addOrGetLocalContext

protected JContextFactory.JContext addOrGetLocalContext(String _id)
                                                 throws JonathanException