org.riotfamily.common.beans.xml
Class AbstractGenericBeanDefinitionParser

java.lang.Object
  extended by org.riotfamily.common.beans.xml.AbstractGenericBeanDefinitionParser
All Implemented Interfaces:
BeanDefinitionParser
Direct Known Subclasses:
GenericBeanDefinitionParser

public abstract class AbstractGenericBeanDefinitionParser
extends Object
implements BeanDefinitionParser

Class similar to Spring's AbstractSingleBeanDefinitionParser. Supports registering aliased beans and decoration of nested beans.

Since:
6.5
Author:
Carsten Woelk [cwoelk at neteye dot de], Felix Gnass [fgnass at neteye dot de]

Field Summary
static String ID_ATTRIBUTE
          Constant for the id attribute
 
Constructor Summary
AbstractGenericBeanDefinitionParser(Class<?> beanClass)
           
AbstractGenericBeanDefinitionParser(String className)
           
 
Method Summary
protected  void doParse(Element element, BeanDefinitionBuilder builder)
          Parse the supplied Element and populate the supplied BeanDefinitionBuilder as required.
protected  void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
          Parse the supplied Element and populate the supplied BeanDefinitionBuilder as required.
 BeanDefinition parse(Element element, ParserContext parserContext)
           
protected  AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext)
          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 postProcessComponentDefinition(BeanComponentDefinition componentDefinition)
          Hook method called after the primary parsing of a BeanComponentDefinition but before the BeanComponentDefinition has been registered with a BeanDefinitionRegistry.
protected  void registerBeanDefinition(BeanDefinitionHolder definition, BeanDefinitionRegistry registry)
          Register the supplied bean with the supplied registry.
protected  String resolveAlias(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
          Resolve the alias for the supplied BeanDefinition.
protected  String[] resolveAliases(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
          Resolve the aliases for the supplied BeanDefinition.
protected  String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
          Resolve the ID for the supplied BeanDefinition.
 void setDecorate(boolean decorate)
          Sets whether the bean should be decorated.
protected  boolean shouldFireEvents()
          Controls whether this parser is supposed to fire a BeanComponentDefinition event after parsing the bean definition.
protected  boolean shouldGenerateId()
          Should an ID be generated instead of read from the passed in Element?
protected  boolean shouldGenerateIdAsFallback()
          Should an ID be generated instead if the passed in Element does not specify an "id" attribute explicitly?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID_ATTRIBUTE

public static final String ID_ATTRIBUTE
Constant for the id attribute

See Also:
Constant Field Values
Constructor Detail

AbstractGenericBeanDefinitionParser

public AbstractGenericBeanDefinitionParser(Class<?> beanClass)

AbstractGenericBeanDefinitionParser

public AbstractGenericBeanDefinitionParser(String className)
Method Detail

setDecorate

public void setDecorate(boolean decorate)
Sets whether the bean should be decorated. Default is true.


parse

public final BeanDefinition parse(Element element,
                                  ParserContext parserContext)
Specified by:
parse in interface BeanDefinitionParser

parseInternal

protected final AbstractBeanDefinition parseInternal(Element element,
                                                     ParserContext parserContext)
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.

Parameters:
element - the element that is to be parsed into a single BeanDefinition
parserContext - 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)

resolveId

protected String resolveId(Element element,
                           AbstractBeanDefinition definition,
                           ParserContext parserContext)
                    throws BeanDefinitionStoreException
Resolve the ID for the supplied BeanDefinition.

When using generation, a name is generated automatically. Otherwise, the ID is extracted from the "id" attribute, potentially with a fallback to a generated id.

Parameters:
element - the element that the bean definition has been built from
definition - the bean definition to be registered
parserContext - the object encapsulating the current state of the parsing process; provides access to a BeanDefinitionRegistry
Returns:
the resolved id
Throws:
BeanDefinitionStoreException - if no unique name could be generated for the given bean definition

resolveAliases

protected String[] resolveAliases(Element element,
                                  AbstractBeanDefinition definition,
                                  ParserContext parserContext)
Resolve the aliases for the supplied BeanDefinition. The default implementation delegates the call to resolveAlias(Element, AbstractBeanDefinition, ParserContext) and tokenizes the returned String.


resolveAlias

protected String resolveAlias(Element element,
                              AbstractBeanDefinition definition,
                              ParserContext parserContext)
Resolve the alias for the supplied BeanDefinition. The returned String may contain multiple bean-names separated by commas, semicolons or spaces. The default implementation returns null


registerBeanDefinition

protected void registerBeanDefinition(BeanDefinitionHolder definition,
                                      BeanDefinitionRegistry registry)
Register the supplied bean with the supplied registry.

Subclasses can override this method to control whether or not the supplied bean is actually even registered, or to register even more beans.

The default implementation registers the supplied bean with the supplied registry only if the isNested parameter is false, because one typically does not want inner beans to be registered as top level beans.

Parameters:
definition - the bean definition to be registered
registry - the registry that the bean is to be registered with
See Also:
BeanDefinitionReaderUtils.registerBeanDefinition(BeanDefinitionHolder, BeanDefinitionRegistry)

shouldGenerateId

protected boolean shouldGenerateId()
Should an ID be generated instead of read from the passed in Element?

Disabled by default; subclasses can override this to enable ID generation. Note that this flag is about always generating an ID; the parser won't even check for an "id" attribute in this case.

Returns:
whether the parser should always generate an id

shouldGenerateIdAsFallback

protected boolean shouldGenerateIdAsFallback()
Should an ID be generated instead if the passed in Element does not specify an "id" attribute explicitly?

Disabled by default; subclasses can override this to enable ID generation as fallback: The parser will first check for an "id" attribute in this case, only falling back to a generated ID if no value was specified.

Returns:
whether the parser should generate an id if no id was specified

shouldFireEvents

protected boolean shouldFireEvents()
Controls whether this parser is supposed to fire a BeanComponentDefinition event after parsing the bean definition.

This implementation returns true by default; that is, an event will be fired when a bean definition has been completely parsed. Override this to return false in order to suppress the event.

Returns:
true in order to fire a component registration event after parsing the bean definition; false to suppress the event
See Also:
postProcessComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition), ReaderContext.fireComponentRegistered(org.springframework.beans.factory.parsing.ComponentDefinition)

postProcessComponentDefinition

protected void postProcessComponentDefinition(BeanComponentDefinition componentDefinition)
Hook method called after the primary parsing of a BeanComponentDefinition but before the BeanComponentDefinition has been registered with a BeanDefinitionRegistry.

Derived classes can override this method to supply any custom logic that is to be executed after all the parsing is finished.

The default implementation is a no-op.

Parameters:
componentDefinition - the BeanComponentDefinition that is to be processed

doParse

protected void doParse(Element element,
                       ParserContext parserContext,
                       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
parserContext - the object encapsulating the current state of the parsing process
builder - used to define the BeanDefinition
See Also:
doParse(Element, BeanDefinitionBuilder)

doParse

protected void doParse(Element element,
                       BeanDefinitionBuilder builder)
Parse the supplied Element and populate the supplied BeanDefinitionBuilder as required.

The default implementation does nothing.

Parameters:
element - the XML element being parsed
builder - used to define the BeanDefinition