org.mule.config.spring.parsers
Class AbstractMuleBeanDefinitionParser

java.lang.Object
  extended by org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
      extended by org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser
All Implemented Interfaces:
MuleDefinitionParser, MuleDefinitionParserConfiguration, org.springframework.beans.factory.xml.BeanDefinitionParser
Direct Known Subclasses:
AbstractFlowConstructDefinitionParser, AbstractHierarchicalDefinitionParser, JmxAgentDefinitionParser, OrphanDefinitionParser, OrphanMapDefinitionParser

public abstract class AbstractMuleBeanDefinitionParser
extends org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
implements MuleDefinitionParser

This parser extends the Spring provided AbstractBeanDefinitionParser to provide additional features for consistently customising bean representations for Mule bean definition parsers. Most custom bean definition parsers in Mule will use this base class. The following enhancements are made -

  1. A property name which ends with the suffix "-ref" is assumed to be a reference to another bean. Alternatively, a property can be explicitly registered as a bean reference via registerBeanReference()

    For example, <bpm:connector bpms-ref="testBpms"/> will automatically set a property "bpms" on the connector to reference a bean named "testBpms"

  2. Attribute mappings can be registered to control how an attribute name in Mule Xml maps to the bean name in the object being created.

    For example - addAlias("poolExhaustedAction", "poolExhaustedActionString"); Maps the 'poolExhaustedAction' to the 'poolExhaustedActionString' property on the bean being created.

  3. Value Mappings can be used to map key value pairs from selection lists in the XML schema to property values on the bean being created. These are a comma-separated list of key=value pairs.

    For example - addMapping("action", "NONE=0,ALWAYS_BEGIN=1,BEGIN_OR_JOIN=2,JOIN_IF_POSSIBLE=3"); The first argument is the bean name to set, the second argument is the set of possible key=value pairs

  4. Provides an automatic way of setting the 'init-method' and 'destroy-method' for this object. This will then automatically wire the bean into the lifecycle of the Application context.
  5. The 'singleton' property provides a fixed way to make sure the bean is always a singleton or not.
  6. Collections will be automatically created and extended if the setter matches "property+s".

Note that this class is not multi-thread safe. The internal state is reset before each "use" by preProcess(org.w3c.dom.Element) which assumes sequential access.

See Also:
AbstractBeanDefinitionParser

Field Summary
static String ATTRIBUTE_CLASS
           
static String ATTRIBUTE_ID
           
static String ATTRIBUTE_NAME
           
static String ATTRIBUTE_REF
           
static String ATTRIBUTE_REF_SUFFIX
           
static String ATTRIBUTE_REFS
           
static String ATTRIBUTE_REFS_SUFFIX
           
protected  ReusablePropertyConfiguration beanPropertyConfiguration
           
static String DOMAIN_ROOT_ELEMENT
           
protected  Log logger
          logger used by this class
static String ROOT_ELEMENT
           
protected  boolean singleton
           
 
Fields inherited from class org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
ID_ATTRIBUTE, NAME_ATTRIBUTE
 
Constructor Summary
AbstractMuleBeanDefinitionParser()
           
 
Method Summary
 MuleDefinitionParserConfiguration addAlias(String alias, String propertyName)
           
 MuleDefinitionParserConfiguration addBeanFlag(String flag)
           
 MuleDefinitionParserConfiguration addCollection(String propertyName)
           
 MuleDefinitionParserConfiguration addIgnored(String propertyName)
           
 MuleDefinitionParserConfiguration addMapping(String propertyName, Map mappings)
           
 MuleDefinitionParserConfiguration addMapping(String propertyName, String mappings)
           
 MuleDefinitionParserConfiguration addMapping(String propertyName, ValueMap mappings)
           
 MuleDefinitionParserConfiguration addReference(String propertyName)
           
protected  void checkElementNameUnique(Element element)
           
protected  org.springframework.beans.factory.support.BeanDefinitionBuilder createBeanDefinitionBuilder(Element element, Class<?> beanClass)
           
protected  void doParse(Element element, org.springframework.beans.factory.xml.ParserContext context, org.springframework.beans.factory.support.BeanDefinitionBuilder builder)
          Parse the supplied Element and populate the supplied BeanDefinitionBuilder as required.
protected  BeanAssembler getBeanAssembler(Element element, org.springframework.beans.factory.support.BeanDefinitionBuilder bean)
          Restricted use - does not include a target.
 BeanAssemblerFactory getBeanAssemblerFactory()
           
protected abstract  Class<?> getBeanClass(Element element)
          Determine the bean class corresponding to the supplied Element.
protected  Class<?> getBeanClassFromAttribute(Element element)
          Determine the bean class corresponding to the supplied Element based on an explicit "class" attribute.
 String getBeanName(Element element)
           
protected  Class<?> getClassConstraint()
           
protected  Class<?> getClassInternal(Element element)
           
protected  org.springframework.beans.factory.xml.ParserContext getParserContext()
           
protected  org.springframework.beans.factory.support.BeanDefinitionRegistry getRegistry()
           
protected  boolean isAllowClassAttribute()
           
protected  boolean isSingleton()
           
protected  boolean isTopLevel(Element element)
           
 org.springframework.beans.factory.support.AbstractBeanDefinition muleParse(Element element, org.springframework.beans.factory.xml.ParserContext context)
           
protected  org.springframework.beans.factory.support.AbstractBeanDefinition parseInternal(Element element, org.springframework.beans.factory.xml.ParserContext context)
          Creates a BeanDefinitionBuilder instance for the bean Class and passes it to the doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder) strategy method.
protected  void postProcess(org.springframework.beans.factory.xml.ParserContext context, BeanAssembler assembler, Element element)
          Hook method that derived classes can implement to inspect/change a bean definition after parsing is complete.
protected  void preProcess(Element element)
          Hook method that derived classes can implement to modify internal state before processing.
protected  void processProperty(Attr attribute, BeanAssembler assembler)
           
 MuleDefinitionParserConfiguration registerPostProcessor(PostProcessor postProcessor)
          These are appended to existing processors
 MuleDefinitionParserConfiguration registerPreProcessor(PreProcessor preProcessor)
          These are prepended to existing processors
 MuleDefinitionParserConfiguration removeIgnored(String propertyName)
           
protected  String resolveId(Element element, org.springframework.beans.factory.support.AbstractBeanDefinition definition, org.springframework.beans.factory.xml.ParserContext context)
           
protected  void setAllowClassAttribute(boolean allowClassAttribute)
           
 void setBeanAssemblerFactory(BeanAssemblerFactory beanAssemblerFactory)
           
protected  void setClassConstraint(Class<?> classConstraint)
           
 void setDeprecationWarning(String deprecationWarning)
           
 MuleDefinitionParserConfiguration setIgnoredDefault(boolean ignoreAll)
           
protected  void setParserContext(org.springframework.beans.factory.xml.ParserContext parserContext)
           
protected  void setRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
           
 
Methods inherited from class org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
parse, postProcessComponentDefinition, registerBeanDefinition, shouldFireEvents, shouldGenerateId, shouldGenerateIdAsFallback
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.beans.factory.xml.BeanDefinitionParser
parse
 

Field Detail

ROOT_ELEMENT

public static final String ROOT_ELEMENT
See Also:
Constant Field Values

DOMAIN_ROOT_ELEMENT

public static final String DOMAIN_ROOT_ELEMENT
See Also:
Constant Field Values

ATTRIBUTE_ID

public static final String ATTRIBUTE_ID
See Also:
Constant Field Values

ATTRIBUTE_NAME

public static final String ATTRIBUTE_NAME
See Also:
Constant Field Values

ATTRIBUTE_CLASS

public static final String ATTRIBUTE_CLASS
See Also:
Constant Field Values

ATTRIBUTE_REF

public static final String ATTRIBUTE_REF
See Also:
Constant Field Values

ATTRIBUTE_REFS

public static final String ATTRIBUTE_REFS
See Also:
Constant Field Values

ATTRIBUTE_REF_SUFFIX

public static final String ATTRIBUTE_REF_SUFFIX
See Also:
Constant Field Values

ATTRIBUTE_REFS_SUFFIX

public static final String ATTRIBUTE_REFS_SUFFIX
See Also:
Constant Field Values

logger

protected transient Log logger
logger used by this class


beanPropertyConfiguration

protected ReusablePropertyConfiguration beanPropertyConfiguration

singleton

protected boolean singleton
Constructor Detail

AbstractMuleBeanDefinitionParser

public AbstractMuleBeanDefinitionParser()
Method Detail

addReference

public MuleDefinitionParserConfiguration addReference(String propertyName)
Specified by:
addReference in interface MuleDefinitionParserConfiguration

addMapping

public MuleDefinitionParserConfiguration addMapping(String propertyName,
                                                    Map mappings)
Specified by:
addMapping in interface MuleDefinitionParserConfiguration

addMapping

public MuleDefinitionParserConfiguration addMapping(String propertyName,
                                                    String mappings)
Specified by:
addMapping in interface MuleDefinitionParserConfiguration

addMapping

public MuleDefinitionParserConfiguration addMapping(String propertyName,
                                                    ValueMap mappings)
Specified by:
addMapping in interface MuleDefinitionParserConfiguration

addAlias

public MuleDefinitionParserConfiguration addAlias(String alias,
                                                  String propertyName)
Specified by:
addAlias in interface MuleDefinitionParserConfiguration
Parameters:
alias - The attribute name
propertyName - The bean property name
Returns:
This instance, allowing chaining during use, avoiding subclasses

addCollection

public MuleDefinitionParserConfiguration addCollection(String propertyName)
Specified by:
addCollection in interface MuleDefinitionParserConfiguration
Parameters:
propertyName - Property that is a collection
Returns:
This instance, allowing chaining during use, avoiding subclasses

addIgnored

public MuleDefinitionParserConfiguration addIgnored(String propertyName)
Specified by:
addIgnored in interface MuleDefinitionParserConfiguration
Parameters:
propertyName - Property that is to be ignored
Returns:
This instance, allowing chaining during use, avoiding subclasses

removeIgnored

public MuleDefinitionParserConfiguration removeIgnored(String propertyName)
Specified by:
removeIgnored in interface MuleDefinitionParserConfiguration

setIgnoredDefault

public MuleDefinitionParserConfiguration setIgnoredDefault(boolean ignoreAll)
Specified by:
setIgnoredDefault in interface MuleDefinitionParserConfiguration

processProperty

protected void processProperty(Attr attribute,
                               BeanAssembler assembler)

postProcess

protected void postProcess(org.springframework.beans.factory.xml.ParserContext context,
                           BeanAssembler assembler,
                           Element element)
Hook method that derived classes can implement to inspect/change a bean definition after parsing is complete.

Parameters:
assembler - the parsed (and probably totally defined) bean definition being built
element - the XML element that was the source of the bean definition's metadata

preProcess

protected void preProcess(Element element)
Hook method that derived classes can implement to modify internal state before processing. Here we make sure that the internal property configuration state is reset to the initial configuration for each element (it may be modified by the BeanAssembler) and that other mutable instance variables are cleared.


parseInternal

protected org.springframework.beans.factory.support.AbstractBeanDefinition parseInternal(Element element,
                                                                                         org.springframework.beans.factory.xml.ParserContext context)
Creates a BeanDefinitionBuilder instance for the bean Class and passes it to the doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder) strategy method.

Specified by:
parseInternal in class org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
Parameters:
element - the element that is to be parsed into a single BeanDefinition
context - the object encapsulating the current state of the parsing process
Returns:
the BeanDefinition resulting from the parsing of the supplied Element
Throws:
IllegalStateException - if the bean Class returned from getBeanClass(org.w3c.dom.Element) is null
See Also:
doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder)

setRegistry

protected void setRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)

getRegistry

protected org.springframework.beans.factory.support.BeanDefinitionRegistry getRegistry()

checkElementNameUnique

protected void checkElementNameUnique(Element element)

createBeanDefinitionBuilder

protected org.springframework.beans.factory.support.BeanDefinitionBuilder createBeanDefinitionBuilder(Element element,
                                                                                                      Class<?> beanClass)

getClassInternal

protected Class<?> getClassInternal(Element element)

getBeanClassFromAttribute

protected Class<?> getBeanClassFromAttribute(Element element)
Determine the bean class corresponding to the supplied Element based on an explicit "class" attribute.

Parameters:
element - the Element that is being parsed
Returns:
the Class of the bean that is being defined via parsing the supplied Element (must not be null)
See Also:
parseInternal(org.w3c.dom.Element,ParserContext)

getBeanClass

protected abstract Class<?> getBeanClass(Element element)
Determine the bean class corresponding to the supplied Element.

Parameters:
element - the Element that is being parsed
Returns:
the Class of the bean that is being defined via parsing the supplied Element (must not be null)
See Also:
parseInternal(org.w3c.dom.Element,ParserContext)

doParse

protected void doParse(Element element,
                       org.springframework.beans.factory.xml.ParserContext context,
                       org.springframework.beans.factory.support.BeanDefinitionBuilder builder)
Parse the supplied Element and populate the supplied BeanDefinitionBuilder as required.

The default implementation delegates to the doParse version without ParserContext argument.

Parameters:
element - the XML element being parsed
context - the object encapsulating the current state of the parsing process
builder - used to define the BeanDefinition

resolveId

protected String resolveId(Element element,
                           org.springframework.beans.factory.support.AbstractBeanDefinition definition,
                           org.springframework.beans.factory.xml.ParserContext context)
                    throws org.springframework.beans.factory.BeanDefinitionStoreException
Overrides:
resolveId in class org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
Throws:
org.springframework.beans.factory.BeanDefinitionStoreException

isSingleton

protected boolean isSingleton()

getBeanAssembler

protected BeanAssembler getBeanAssembler(Element element,
                                         org.springframework.beans.factory.support.BeanDefinitionBuilder bean)
Restricted use - does not include a target. If possible, use AbstractHierarchicalDefinitionParser.getBeanAssembler(org.w3c.dom.Element, org.springframework.beans.factory.support.BeanDefinitionBuilder)

Parameters:
bean - The bean being constructed
Returns:
An assembler that automates Mule-specific logic for bean construction

isAllowClassAttribute

protected boolean isAllowClassAttribute()

setAllowClassAttribute

protected void setAllowClassAttribute(boolean allowClassAttribute)

getClassConstraint

protected Class<?> getClassConstraint()

setClassConstraint

protected void setClassConstraint(Class<?> classConstraint)

getParserContext

protected org.springframework.beans.factory.xml.ParserContext getParserContext()

setParserContext

protected void setParserContext(org.springframework.beans.factory.xml.ParserContext parserContext)

isTopLevel

protected boolean isTopLevel(Element element)
Parameters:
element - The element to test
Returns:
true if the element's parent is or similar

muleParse

public org.springframework.beans.factory.support.AbstractBeanDefinition muleParse(Element element,
                                                                                  org.springframework.beans.factory.xml.ParserContext context)
Specified by:
muleParse in interface MuleDefinitionParser

registerPreProcessor

public MuleDefinitionParserConfiguration registerPreProcessor(PreProcessor preProcessor)
Description copied from interface: MuleDefinitionParserConfiguration
These are prepended to existing processors

Specified by:
registerPreProcessor in interface MuleDefinitionParserConfiguration

registerPostProcessor

public MuleDefinitionParserConfiguration registerPostProcessor(PostProcessor postProcessor)
Description copied from interface: MuleDefinitionParserConfiguration
These are appended to existing processors

Specified by:
registerPostProcessor in interface MuleDefinitionParserConfiguration

getBeanAssemblerFactory

public BeanAssemblerFactory getBeanAssemblerFactory()

setBeanAssemblerFactory

public void setBeanAssemblerFactory(BeanAssemblerFactory beanAssemblerFactory)

getBeanName

public String getBeanName(Element element)
Specified by:
getBeanName in interface MuleDefinitionParser

addBeanFlag

public MuleDefinitionParserConfiguration addBeanFlag(String flag)
Specified by:
addBeanFlag in interface MuleDefinitionParserConfiguration

setDeprecationWarning

public void setDeprecationWarning(String deprecationWarning)
Specified by:
setDeprecationWarning in interface MuleDefinitionParser


Copyright © 2003-2014 MuleSoft, Inc.. All Rights Reserved.