org.apache.commons.betwixt.io
Class BeanCreateRule

java.lang.Object
  extended byorg.apache.commons.digester.Rule
      extended byorg.apache.commons.betwixt.io.BeanCreateRule

public class BeanCreateRule
extends Rule

BeanCreateRule is a Digester Rule for creating beans from the betwixt XML metadata.

Version:
$Revision: 1.17.2.1 $
Author:
James Strachan, Martin van den Bemt

Field Summary
private  boolean addedChildren
          Have we added our child rules to the digester?
private  java.lang.Class beanClass
          The type of the bean to create
private  Context context
          The Context used when evaluating Updaters
private  boolean createdBean
          In this begin-end loop did we actually create a new bean
private  ElementDescriptor descriptor
          The descriptor of this element
private static org.apache.commons.logging.Log log
          Logger
private  boolean matchIDs
          Use id's to match beans?
private  java.lang.String pathPrefix
          The prefix added to digester rules
 
Fields inherited from class org.apache.commons.digester.Rule
digester, namespaceURI
 
Constructor Summary
  BeanCreateRule(ElementDescriptor descriptor, java.lang.Class beanClass)
          Convenience constructor which uses ID's for matching.
  BeanCreateRule(ElementDescriptor descriptor, java.lang.Class beanClass, boolean matchIDs)
          Constructor uses standard qualified name.
private BeanCreateRule(ElementDescriptor descriptor, java.lang.Class beanClass, Context context, java.lang.String pathPrefix, boolean matchIDs)
          Base constructor (used by other constructors).
  BeanCreateRule(ElementDescriptor descriptor, java.lang.Class beanClass, java.lang.String pathPrefix)
          Convenience constructor which uses ID's for matching.
  BeanCreateRule(ElementDescriptor descriptor, java.lang.Class beanClass, java.lang.String pathPrefix, boolean matchIDs)
          Constructor taking a class.
  BeanCreateRule(ElementDescriptor descriptor, Context context, java.lang.String pathPrefix)
          Convenience constructor which uses ID's for match.
  BeanCreateRule(ElementDescriptor descriptor, Context context, java.lang.String pathPrefix, boolean matchIDs)
          Constructor taking a context.
 
Method Summary
protected  void addChildRules()
          Adds the rules to the digester for all child elements
protected  void addChildRules(java.lang.String prefix, ElementDescriptor currentDescriptor)
          Add child rules for given descriptor at given prefix
protected  void addPrimitiveTypeRule(java.lang.String path, ElementDescriptor childDescriptor)
          Adds a new Digester rule to process the text as a primitive type
protected  void addRule(java.lang.String path, Rule rule)
          Safely add a rule with given path.
 void begin(org.xml.sax.Attributes attributes)
          Process the beginning of this element.
protected  java.lang.Object createBean(org.xml.sax.Attributes attributes)
          Factory method to create new bean instances
 void end()
          Process the end of this element.
 void finish()
          Tidy up.
protected  BeanReader getBeanReader()
          Get the associated bean reader.
protected  java.util.Map getBeansById()
          Get the map used to index beans (previously read in) by id.
protected  ElementDescriptor getElementDescriptor(ElementDescriptor propertyDescriptor)
          Allows the navigation from a reference to a property object to the descriptor defining what the property is.
static void setLog(org.apache.commons.logging.Log aLog)
          Set log to be used by BeanCreateRule instances
 java.lang.String toString()
          Return something meaningful for logging.
 
Methods inherited from class org.apache.commons.digester.Rule
begin, body, body, end, getDigester, getNamespaceURI, setDigester, setNamespaceURI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Logger


descriptor

private ElementDescriptor descriptor
The descriptor of this element


context

private Context context
The Context used when evaluating Updaters


addedChildren

private boolean addedChildren
Have we added our child rules to the digester?


createdBean

private boolean createdBean
In this begin-end loop did we actually create a new bean


beanClass

private java.lang.Class beanClass
The type of the bean to create


pathPrefix

private java.lang.String pathPrefix
The prefix added to digester rules


matchIDs

private boolean matchIDs
Use id's to match beans?

Constructor Detail

BeanCreateRule

public BeanCreateRule(ElementDescriptor descriptor,
                      java.lang.Class beanClass,
                      java.lang.String pathPrefix)
Convenience constructor which uses ID's for matching.

Parameters:
descriptor - the ElementDescriptor describing the element mapped
beanClass - the Class to be created
pathPrefix - the digester style path

BeanCreateRule

public BeanCreateRule(ElementDescriptor descriptor,
                      java.lang.Class beanClass,
                      java.lang.String pathPrefix,
                      boolean matchIDs)
Constructor taking a class.

Parameters:
descriptor - the ElementDescriptor describing the element mapped
beanClass - the Class to be created
pathPrefix - the digester style path
matchIDs - should ID/IDREF's be used for matching

BeanCreateRule

public BeanCreateRule(ElementDescriptor descriptor,
                      java.lang.Class beanClass)
Convenience constructor which uses ID's for matching.

Parameters:
descriptor - the ElementDescriptor describing the element mapped
beanClass - the Class to be created

BeanCreateRule

public BeanCreateRule(ElementDescriptor descriptor,
                      java.lang.Class beanClass,
                      boolean matchIDs)
Constructor uses standard qualified name.

Parameters:
descriptor - the ElementDescriptor describing the element mapped
beanClass - the Class to be created
matchIDs - should ID/IDREF's be used for matching

BeanCreateRule

public BeanCreateRule(ElementDescriptor descriptor,
                      Context context,
                      java.lang.String pathPrefix)
Convenience constructor which uses ID's for match.

Parameters:
descriptor - the ElementDescriptor describing the element mapped
context - the Context to be used to evaluate expressions
pathPrefix - the digester path prefix

BeanCreateRule

public BeanCreateRule(ElementDescriptor descriptor,
                      Context context,
                      java.lang.String pathPrefix,
                      boolean matchIDs)
Constructor taking a context.

Parameters:
descriptor - the ElementDescriptor describing the element mapped
context - the Context to be used to evaluate expressions
pathPrefix - the digester path prefix
matchIDs - should ID/IDREF's be used for matching

BeanCreateRule

private BeanCreateRule(ElementDescriptor descriptor,
                       java.lang.Class beanClass,
                       Context context,
                       java.lang.String pathPrefix,
                       boolean matchIDs)
Base constructor (used by other constructors).

Parameters:
descriptor - the ElementDescriptor describing the element mapped
beanClass - the Class of the bean to be created
context - the Context to be used to evaluate expressions
pathPrefix - the digester path prefix
matchIDs - should ID/IDREF's be used for matching
Method Detail

setLog

public static void setLog(org.apache.commons.logging.Log aLog)
Set log to be used by BeanCreateRule instances

Parameters:
aLog - the Log implementation for this class to log to

begin

public void begin(org.xml.sax.Attributes attributes)
Process the beginning of this element.

Parameters:
attributes - The attribute list of this element

end

public void end()
Process the end of this element.


finish

public void finish()
Tidy up.


createBean

protected java.lang.Object createBean(org.xml.sax.Attributes attributes)
Factory method to create new bean instances

Parameters:
attributes - the Attributes used to match ID/IDREF
Returns:
the created bean

addChildRules

protected void addChildRules()
Adds the rules to the digester for all child elements


addChildRules

protected void addChildRules(java.lang.String prefix,
                             ElementDescriptor currentDescriptor)
Add child rules for given descriptor at given prefix

Parameters:
prefix - add child rules at this (digester) path prefix
currentDescriptor - add child rules for this descriptor

getBeanReader

protected BeanReader getBeanReader()
Get the associated bean reader.

Returns:
the BeanReader

getElementDescriptor

protected ElementDescriptor getElementDescriptor(ElementDescriptor propertyDescriptor)
Allows the navigation from a reference to a property object to the descriptor defining what the property is. i.e. doing the join from a reference to a type to lookup its descriptor. This could be done automatically by the NodeDescriptors. Refer to TODO.txt for more info.

Parameters:
propertyDescriptor - find descriptor for property object referenced by this descriptor
Returns:
descriptor for the singular property class type referenced.

addPrimitiveTypeRule

protected void addPrimitiveTypeRule(java.lang.String path,
                                    ElementDescriptor childDescriptor)
Adds a new Digester rule to process the text as a primitive type

Parameters:
path - digester path where this rule will be attached
childDescriptor - update this ElementDescriptor with the body text

addRule

protected void addRule(java.lang.String path,
                       Rule rule)
Safely add a rule with given path.

Parameters:
path - the digester path to add rule at
rule - the Rule to add

getBeansById

protected java.util.Map getBeansById()
Get the map used to index beans (previously read in) by id. This is stored in the evaluation context.

Returns:
map indexing beans created by id

toString

public java.lang.String toString()
Return something meaningful for logging.

Returns:
something useful for logging