org.objectweb.jonathan.libs.kernel
Class JComponent

java.lang.Object
  extended byorg.objectweb.jonathan.libs.kernel.JComponent
All Implemented Interfaces:
Component, Forkable
Direct Known Subclasses:
JContextFactory.JContext, JImplicitFactory, LazyComponent

public class JComponent
extends java.lang.Object
implements Forkable

Basic implementation of a runtime component. Its behaviour is a property component's. Must be subtyped to behave differently.


Field Summary
protected  int int_value
          the integer value
protected  Element reference
          The element referencing this component
protected  java.lang.Class type
          the type
protected  java.lang.Object value
          the object reference value
 
Constructor Summary
JComponent()
          Constructs a JComponent.
JComponent(java.lang.Class _type, int _int_value)
           
JComponent(java.lang.Class _type, java.lang.Object _value)
           
JComponent(java.lang.Class _type, java.lang.Object _value, int _int_value)
           
JComponent(java.lang.Class _type, java.lang.Object _value, int _int_value, Element _reference)
           
 
Method Summary
protected  Component duplicate()
           
 Component fork()
          "Forks" a copy of the target component.
 Component getComponent(Name _name)
          Returns the component contained in the element registered in the target component under the name name.
 Element getElement(Name name)
          Returns the element in the target component identified by name, null if no element exists under name name.
 java.lang.Object getFactoryValue()
           
 int getIntValue()
          Returns the value of the target component, if its class is an integer class.
 Element getReference()
          Returns a distinguished element referencing the target component, if any, null otherwise.
 java.lang.Class getType()
          Returns the type of the target component, as a Class.
 java.lang.Object getValue()
          Returns the value of the target component, if its type is an object reference type.
 java.lang.Object getValue(Name _name)
          Returns the value of the element registered in the target context under the name name.
 Component internalFork()
           
protected  void reset()
           
 Element setReference(Element _reference)
          Sets an element containing the target component.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

protected java.lang.Class type
the type


value

protected java.lang.Object value
the object reference value


int_value

protected int int_value
the integer value


reference

protected Element reference
The element referencing this component

Constructor Detail

JComponent

public JComponent()
Constructs a JComponent.


JComponent

public JComponent(java.lang.Class _type,
                  int _int_value)

JComponent

public JComponent(java.lang.Class _type,
                  java.lang.Object _value)

JComponent

public JComponent(java.lang.Class _type,
                  java.lang.Object _value,
                  int _int_value)

JComponent

public JComponent(java.lang.Class _type,
                  java.lang.Object _value,
                  int _int_value,
                  Element _reference)
Method Detail

getType

public java.lang.Class getType()
Description copied from interface: Component
Returns the type of the target component, as a Class.

Specified by:
getType in interface Component
Returns:
the type of the target component, as a Class.

getValue

public java.lang.Object getValue()
Description copied from interface: Component
Returns the value of the target component, if its type is an object reference type.

If the target component is of an integral type, NO_VALUE} is returned.

Specified by:
getValue in interface Component
Returns:
the value of the target component.

getIntValue

public int getIntValue()
Description copied from interface: Component
Returns the value of the target component, if its class is an integer class.

If the target component has an object reference type, Integer.MAX_VALUE is returned.

Specified by:
getIntValue in interface Component
Returns:
the value of the target component.

getFactoryValue

public java.lang.Object getFactoryValue()
                                 throws JonathanException
Specified by:
getFactoryValue in interface Component
Throws:
JonathanException

getReference

public Element getReference()
Description copied from interface: Component
Returns a distinguished element referencing the target component, if any, null otherwise. Implementations are not required to keep information about a given containing element. It is always legal to return null.

Specified by:
getReference in interface Component
Returns:
an element containing the target component, if any, null otherwise.

setReference

public Element setReference(Element _reference)
Description copied from interface: Component
Sets an element containing the target component. The provided element should already be initialized as a container of the component. The returned element is the former container, if any. This method MUST be called when a component is referred to by an element.

Specified by:
setReference in interface Component
Parameters:
_reference - the new element referencing the target component.
Returns:
the former element referencing the target component, if any, null otherwise.

toString

public java.lang.String toString()

duplicate

protected Component duplicate()

fork

public Component fork()
Description copied from interface: Component
"Forks" a copy of the target component. The returned component is a copy of the target component, sharing the same reference, but *NOT* referred to by this reference.

For basic components, this operation simply duplicates the component structure, but the value is still shared.

In the configuration framework, components contain a specification of their value (in the form of an assemblage, atom, alias... description). The fork() method is used to duplicate the specification, but not the value. It may thus be used to obtain several instances of a component, using getValue() on the returned component.

When the target component is a context, the returned component is a new context, roughly containing the forked versions of the target context's components.

If the target context contains an alias, and if the target T of this alias is in the scope of the context, then the target of the forked alias is a forked instance of T. But if the target is outside the scope of the context, then the target of the forked alias is T itself. The context thus defines a set of components that will be actually duplicated, all links outside the context being preserved.

The same rule applies for assemblages, and other "container" components. For instance, consider an assemblage 'A' made of factory 'F' and configuration 'C', 'C' containing an atom 'At', an alias 'In' to At, and an alias 'Out' to a component 'K' outside 'A'. Then the forked version of 'A' is a new assemblage made of a copy of 'F' and a new configuration containing a copy 'At2' of 'At', an alias 'In2' to 'At2', and an alias 'Out2' to 'K'.

Aliases are treated specifically. Calling the fork() method on an alias is like calling the same method on its target.

Specified by:
fork in interface Component
Returns:
a forked instance of the target component.

internalFork

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

getElement

public Element getElement(Name name)
Description copied from interface: Component
Returns the element in the target component identified by name, null if no element exists under name name.

Specified by:
getElement in interface Component
Parameters:
name - the name of the element to be retrieved;
Returns:
the corresponding element, if any; null otherwise.

getComponent

public final Component getComponent(Name _name)
Description copied from interface: Component
Returns the component contained in the element registered in the target component under the name name. A call to getComponent(name) is equivalent to getElement(name).getComponent() if the provided name actually corresponds to an element. If it is not the case, null is returned.

Specified by:
getComponent in interface Component
Parameters:
_name - the name of the element whose component is seeked;
Returns:
the corresponding component, or null.

getValue

public final java.lang.Object getValue(Name _name)
Description copied from interface: Component
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 Component
Parameters:
_name - the name of the element whose value is seeked;
Returns:
the corresponding value, or NO_VALUE.

reset

protected void reset()