net.sf.doolin.context.spring
Class SimpleDefinitionParser<C>

java.lang.Object
  extended by org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
      extended by org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser
          extended by net.sf.doolin.context.spring.AbstractDefinitionParser
              extended by net.sf.doolin.context.spring.SimpleDefinitionParser<C>
Type Parameters:
C - Type of bean which is created by this parser.
All Implemented Interfaces:
org.springframework.beans.factory.xml.BeanDefinitionDecorator, org.springframework.beans.factory.xml.BeanDefinitionParser
Direct Known Subclasses:
AbstractFieldTypeParser, ColumnDateDecorator, ColumnEnumDecorator, ColumnExpressionDecorator, ColumnParser, ColumnsParser, PropertyIconServiceParser, ToolBarDecorator, TreeChildrenParser, TreeNodeParser, WindowTypeParser

public class SimpleDefinitionParser<C>
extends AbstractDefinitionParser
implements org.springframework.beans.factory.xml.BeanDefinitionDecorator

Customisable parser for custom elements. It can be used both as parser or as a decorator.

Author:
Damien Coraboeuf

Field Summary
 
Fields inherited from class org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
ID_ATTRIBUTE
 
Constructor Summary
SimpleDefinitionParser(Class<C> beanClass)
          Constructor
 
Method Summary
 SimpleDefinitionParser<C> addAttributeRef(String attributeName)
          Uses the value of an attribute as a reference to a bean.
 SimpleDefinitionParser<C> addAttributeRef(String attributeName, String propertyName)
          Uses the value of an attribute as a reference to a bean.
 SimpleDefinitionParser<C> addCustomBeanAs(String customBeanName, String propertyName)
          Registers a child element which must be parsed as a custom element.
 SimpleDefinitionParser<C> addFactoryFromAttribute(String attributeName, String propertyName, SimpleBeanFactory beanFactory)
          Specifies that the value of an attribute must be used to create an object that will be used as a property value.
 SimpleDefinitionParser<C> addPropertyValue(String propertyName, String propertyValue)
          Specifies the value for a property
 SimpleDefinitionParser<C> addSimpleAttribute(String attributeName)
          Specifies that the value of the given attribute must be used as the value for the property that has the same name
 SimpleDefinitionParser<C> addSimpleAttribute(String attributeName, String propertyName)
          Specifies that the value of the given attribute must be used as the value of a property.
 org.springframework.beans.factory.config.BeanDefinitionHolder decorate(Node node, org.springframework.beans.factory.config.BeanDefinitionHolder holder, org.springframework.beans.factory.xml.ParserContext parserContext)
           
 void doParse(Element element, org.springframework.beans.factory.xml.ParserContext parserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder builder)
          Changes scope to public.
protected  Class<C> getBeanClass(Element element)
           
static
<T> SimpleDefinitionParser<T>
getInstance(Class<T> beanClass)
          Creates an instance of a parser for the given bean class
 SimpleDefinitionParser<C> setContainerProperty(String property)
          Specifies that the parsed bean must be used as a property in the containing bean.
 SimpleDefinitionParser<C> setDefaultID(String defaultID)
          Sets the default ID to use when none is provided
 SimpleDefinitionParser<C> setList(String childName, String propertyName)
          The child element defined by childName defines a list of objects which will be put in the propertyName property of the parsed bean.
 SimpleDefinitionParser<C> setListString(String childName, String propertyName)
          The child element defined by childName defines a list of Strings which will be put in the propertyName property of the parsed bean.
 SimpleDefinitionParser<C> setMap(String childName, String propertyName)
          The child element defined by childName is a map (containing <entry>s elements) that will be stored in the propertyName property of the parsed bean.
 
Methods inherited from class net.sf.doolin.context.spring.AbstractDefinitionParser
delegate, setAttributeAsProperty, setAttributeAsProperty, setAttributeAsReference, setChildrenAsListProperty, setElementAsProperty, setElementAsProperty, setListAsProperty, setListStringAsProperty, setMapAsProperty, setPropertyValue
 
Methods inherited from class org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser
doParse, getBeanClassName, getParentName, parseInternal
 
Methods inherited from class org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
parse, postProcessComponentDefinition, registerBeanDefinition, resolveId, shouldFireEvents, shouldGenerateId, shouldGenerateIdAsFallback
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleDefinitionParser

public SimpleDefinitionParser(Class<C> beanClass)
Constructor

Parameters:
beanClass - Class of the object to create
Method Detail

getInstance

public static <T> SimpleDefinitionParser<T> getInstance(Class<T> beanClass)
Creates an instance of a parser for the given bean class

Type Parameters:
T - Type of parser to create
Parameters:
beanClass - Class of the bean to create
Returns:
Parser

addAttributeRef

public SimpleDefinitionParser<C> addAttributeRef(String attributeName)
Uses the value of an attribute as a reference to a bean. The bean is stored in a property that has the same name than the attribute.

Parameters:
attributeName - Attribute name
Returns:
This parser (allows chaining)

addAttributeRef

public SimpleDefinitionParser<C> addAttributeRef(String attributeName,
                                                 String propertyName)
Uses the value of an attribute as a reference to a bean. The bean is stored in a property.

Parameters:
attributeName - Attribute name
propertyName - Property name
Returns:
This parser (allows chaining)

addCustomBeanAs

public SimpleDefinitionParser<C> addCustomBeanAs(String customBeanName,
                                                 String propertyName)
Registers a child element which must be parsed as a custom element.

Parameters:
customBeanName - Name of the custom element.
propertyName - Property that must hold the parsed custom element.
Returns:
This parser (allows chaining)

addFactoryFromAttribute

public SimpleDefinitionParser<C> addFactoryFromAttribute(String attributeName,
                                                         String propertyName,
                                                         SimpleBeanFactory beanFactory)
Specifies that the value of an attribute must be used to create an object that will be used as a property value.

Parameters:
attributeName - Attribute name
propertyName - Property name
beanFactory - Factory that creates an object from the value of the attribute
Returns:
This parser (allows chaining)

addPropertyValue

public SimpleDefinitionParser<C> addPropertyValue(String propertyName,
                                                  String propertyValue)
Specifies the value for a property

Parameters:
propertyName - Property name
propertyValue - Property value
Returns:
This parsing (allows chaining)

addSimpleAttribute

public SimpleDefinitionParser<C> addSimpleAttribute(String attributeName)
Specifies that the value of the given attribute must be used as the value for the property that has the same name

Parameters:
attributeName - Attribute name
Returns:
This parser (allows chaining)

addSimpleAttribute

public SimpleDefinitionParser<C> addSimpleAttribute(String attributeName,
                                                    String propertyName)
Specifies that the value of the given attribute must be used as the value of a property.

Parameters:
attributeName - Attribute name
propertyName - Property name
Returns:
This parser (allows chaining)

decorate

public org.springframework.beans.factory.config.BeanDefinitionHolder decorate(Node node,
                                                                              org.springframework.beans.factory.config.BeanDefinitionHolder holder,
                                                                              org.springframework.beans.factory.xml.ParserContext parserContext)
Specified by:
decorate in interface org.springframework.beans.factory.xml.BeanDefinitionDecorator

doParse

public void doParse(Element element,
                    org.springframework.beans.factory.xml.ParserContext parserContext,
                    org.springframework.beans.factory.support.BeanDefinitionBuilder builder)
Description copied from class: AbstractDefinitionParser
Changes scope to public.

Overrides:
doParse in class AbstractDefinitionParser

getBeanClass

protected Class<C> getBeanClass(Element element)
Overrides:
getBeanClass in class org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser

setContainerProperty

public SimpleDefinitionParser<C> setContainerProperty(String property)
Specifies that the parsed bean must be used as a property in the containing bean.

Parameters:
property - Name of property that must contain the parsed bean in the containing bean
Returns:
This parser (allows chaining)

setDefaultID

public SimpleDefinitionParser<C> setDefaultID(String defaultID)
Sets the default ID to use when none is provided

Parameters:
defaultID - Default ID
Returns:
This instance

setList

public SimpleDefinitionParser<C> setList(String childName,
                                         String propertyName)
The child element defined by childName defines a list of objects which will be put in the propertyName property of the parsed bean.

Parameters:
childName - Name of the children that define the list
propertyName - Property that must hold the list
Returns:
This parser (allows chaining)

setListString

public SimpleDefinitionParser<C> setListString(String childName,
                                               String propertyName)
The child element defined by childName defines a list of Strings which will be put in the propertyName property of the parsed bean.

Parameters:
childName - Name of the children that define the list of Strings
propertyName - Property that must hold the list
Returns:
This parser (allows chaining)

setMap

public SimpleDefinitionParser<C> setMap(String childName,
                                        String propertyName)
The child element defined by childName is a map (containing <entry>s elements) that will be stored in the propertyName property of the parsed bean.

Parameters:
childName - Name of the child that contains the map
propertyName - Property that must hold the map
Returns:
This parser (allows chaining)


Copyright © 2011. All Rights Reserved.