jfun.yan.xml.nut
Class Nut

java.lang.Object
  extended by jfun.yan.xml.nut.Nut
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AbstractRegisterNut, Args, BinderCase, BinderDefault, BinderNut, ComponentNut, DeserializerNut, FunctionCallNut, LiteralNut, RefServiceNut, ValueNut

public abstract class Nut
extends java.lang.Object
implements java.io.Serializable

The super class of all Nut classes.

Nut stands for Name based User defineable Tag. A method whose name and signature is of a certain pre-defined pattern is called when a sub-element with corresponding name is interpreted inside the xml tag.

For example, for the following tag:

 <ctor class="A">
   <arg ind="0" val="1">
 </ctor> 
 

Method setClass is called for the "class" attribute, which is of course same as the standard Java Bean convention. In fact, a Nut class is always a Java Bean because it has to have a default public constructor and some setters to set attributes.

Method addArg is called for each sub-element. And the parameter type of addArg should be another Nut class to support further "tagging".

For tags simply with a list of sub-elements whose names are irrelevant, the set method with an array parameter is called.
For example:

 <array>
   <return val="1">
   <ctor class="B">
   <method class="C" name="f">
 </array>
 

Finally, a Nut class can optionally have a method named "eval". If this method exist, it is invoked when the tag is evaluated. If the return type is void or the "eval" method does not exist, the Nut object itself is used as the evaluation result. Otherwise, the return value of the "eval" method is used.

Author:
Ben Yu Nov 9, 2005 10:08:11 PM
See Also:
Serialized Form

Constructor Summary
Nut()
           
 
Method Summary
 Component cast(java.lang.Class target_type, Component c)
          Transforms a Component so that the instantiated instance is converted to the target type.
protected  void checkDuplicate(java.lang.String attrname, java.lang.Object v)
          Makes sure that a certain attribute is not set yet to avoid duplicate setting.
protected  void checkMandatory(java.lang.String attrname, java.lang.Object v)
          Make sure an object is not null.
protected  void checkMandatory(java.lang.String name1, java.lang.Object v1, java.lang.String name2, java.lang.Object v2)
          Make sure at least one of two attributes is present.
 java.lang.Object convert(java.lang.Class target_type, java.lang.Object v)
          Convert an object to a target type.
 java.lang.ClassLoader getComponentClassLoader()
          Get the class loader used to load the component classes.
 java.lang.String getId()
          Get the id of this tag.
 java.lang.ClassLoader getNutClassLoader(java.lang.String classpath)
          Get a ClassLoader object that uses the current ClassLoader as parent, and tries an alternative classpath if the resource or class is not found.
 NutEnvironment getNutEnvironment()
          Get the environment that the Nut object is running in.
 ParameterBinder getParameterWiring(java.lang.String mode)
          To get the ParameterBinder object that encapsulates the auto-wiring strategy for a autowire mode specified by the mode name.
 PropertyBinder getPropertyWiring(java.lang.String mode)
          To get the PropertyBinder object that encapsulates the auto-wiring strategy for a autowire mode specified by the mode name.
 int getSequenceNumber()
          Get the sequence number starting from 0.
 Location getTagLocation()
          Get this tag's location within the configuration file.
 java.lang.String getTagName()
          Get the tag name.
 void initGloballyDefined(boolean gd)
          To set whether the tag is defined globally.
 void initNutEnvironment(NutEnvironment env)
          The framework calls this method to set the environment.
 void initSequenceNumber(int seq)
          To set the sequence number of the tag in the enclosing scope.
 void initTagLocation(Location loc)
          The framework calls this method to set the location.
 void initTagName(java.lang.String name)
          The framework calls this method to set the tag name.
 boolean isGloballyDefined()
          Is this tag defined globally?
 ConfigurationException raise(java.lang.String msg)
          Throws a ConfigurationException with the current tag name and location information.
 ConfigurationException raise(java.lang.Throwable e)
          Throws a ConfigurationException with the current tag name and location information.
 void register(java.lang.Object key, java.lang.Object val, boolean overridable, boolean overriding)
          Dynamically register an object.
 void registerEagerInstantiation(Component c)
          Register a Component to be eagerly instantiated using the current tag's id.
 void setId(java.lang.String id)
          Set the id of the tag.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Nut

public Nut()
Method Detail

isGloballyDefined

public boolean isGloballyDefined()
Is this tag defined globally?


register

public void register(java.lang.Object key,
                     java.lang.Object val,
                     boolean overridable,
                     boolean overriding)
Dynamically register an object.

Parameters:
key - the key of the object.
val - the object.
overridable - whether this registration is overridable.
overriding - do we override when the same key is already used by another dynamically registered entry.

getSequenceNumber

public int getSequenceNumber()
Get the sequence number starting from 0. This number is relative to the order the tag is defined within the current scope.


getId

public java.lang.String getId()
Get the id of this tag.

Returns:
the id.

setId

public void setId(java.lang.String id)
Set the id of the tag.

Parameters:
id - the id.

toString

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

getTagLocation

public Location getTagLocation()
Get this tag's location within the configuration file.


initSequenceNumber

public void initSequenceNumber(int seq)
To set the sequence number of the tag in the enclosing scope.

Parameters:
seq - the sequence number.

initGloballyDefined

public void initGloballyDefined(boolean gd)
To set whether the tag is defined globally.

Parameters:
gd - the flag.

initTagLocation

public void initTagLocation(Location loc)
The framework calls this method to set the location.

Parameters:
loc - the location.

initNutEnvironment

public void initNutEnvironment(NutEnvironment env)
The framework calls this method to set the environment.

Parameters:
env - the environment.

getComponentClassLoader

public java.lang.ClassLoader getComponentClassLoader()
Get the class loader used to load the component classes.


getNutClassLoader

public java.lang.ClassLoader getNutClassLoader(java.lang.String classpath)
Get a ClassLoader object that uses the current ClassLoader as parent, and tries an alternative classpath if the resource or class is not found.

Parameters:
classpath - the alternative classpath. null if unspecified.
Returns:
the ClassLoader object.

initTagName

public void initTagName(java.lang.String name)
The framework calls this method to set the tag name.

Parameters:
name - the tag name.

getNutEnvironment

public NutEnvironment getNutEnvironment()
Get the environment that the Nut object is running in.


convert

public java.lang.Object convert(java.lang.Class target_type,
                                java.lang.Object v)
Convert an object to a target type.

Parameters:
target_type - the target type.
v - the object to be converted.
Returns:
the object of the target type.

cast

public Component cast(java.lang.Class target_type,
                      Component c)
Transforms a Component so that the instantiated instance is converted to the target type.

Parameters:
target_type - the target type.
c - the component.
Returns:
the new Component with the conversion in effect.

getTagName

public java.lang.String getTagName()
Get the tag name.


registerEagerInstantiation

public void registerEagerInstantiation(Component c)
Register a Component to be eagerly instantiated using the current tag's id.

Parameters:
c - the Component to be eagerly instantiated.

raise

public ConfigurationException raise(java.lang.String msg)
Throws a ConfigurationException with the current tag name and location information.

Parameters:
msg - the error message.
Returns:
This method never returns. The return type is for callers to get around of the type system so that you can say "throw raise(...)".

raise

public ConfigurationException raise(java.lang.Throwable e)
Throws a ConfigurationException with the current tag name and location information.

Parameters:
e - the nested exception.
Returns:
This method never returns. The return type is for callers to get around of the type system so that you can say "throw raise(...)".

checkMandatory

protected void checkMandatory(java.lang.String attrname,
                              java.lang.Object v)
Make sure an object is not null. Proper error message is reported otherwise.

Parameters:
attrname - the name of the checked attribute.
v - the attribute value.

checkMandatory

protected void checkMandatory(java.lang.String name1,
                              java.lang.Object v1,
                              java.lang.String name2,
                              java.lang.Object v2)
Make sure at least one of two attributes is present.

Parameters:
name1 - the name of the first attribute.
v1 - the value of the first attribute.
name2 - the name of the second attribute.
v2 - the value of the second attribute.

checkDuplicate

protected void checkDuplicate(java.lang.String attrname,
                              java.lang.Object v)
Makes sure that a certain attribute is not set yet to avoid duplicate setting.

Parameters:
attrname - the attribute name.
v - the attribute value.

getParameterWiring

public ParameterBinder getParameterWiring(java.lang.String mode)
To get the ParameterBinder object that encapsulates the auto-wiring strategy for a autowire mode specified by the mode name.

Parameters:
mode - the mode name.
Returns:
the ParameterBinder object for the auto-wiring strategy. null is returned if this indicates a manual-wire.

getPropertyWiring

public PropertyBinder getPropertyWiring(java.lang.String mode)
To get the PropertyBinder object that encapsulates the auto-wiring strategy for a autowire mode specified by the mode name.

Parameters:
mode - the mode name.
Returns:
the PropertyBinder object for the auto-wiring strategy. null is returned if this indicates a manual-wire.