org.springframework.scripting.config
Class ScriptBeanDefinitionParser

java.lang.Object
  extended by org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
      extended by org.springframework.scripting.config.ScriptBeanDefinitionParser
All Implemented Interfaces:
BeanDefinitionParser

 class ScriptBeanDefinitionParser
extends AbstractBeanDefinitionParser

BeanDefinitionParser implementation for the '<lang:groovy/>', '<lang:jruby/>' and '<lang:bsh/>' tags. Allows for objects written using dynamic languages to be easily exposed with the BeanFactory.

The script for each object can be specified either as a reference to the Resource containing it (using the 'script-source' attribute) or inline in the XML configuration itself (using the 'inline-script' attribute.

By default, dynamic objects created with these tags are not refreshable. To enable refreshing, specify the refresh check delay for each object (in milliseconds) using the 'refresh-check-delay' attribute.

Since:
2.0
Author:
Rob Harrop, Rod Johnson, Juergen Hoeller, Mark Fisher

Field Summary
private static java.lang.String AUTOWIRE_ATTRIBUTE
           
private static java.lang.String CUSTOMIZER_REF_ATTRIBUTE
           
private static java.lang.String DEPENDENCY_CHECK_ATTRIBUTE
           
private static java.lang.String DESTROY_METHOD_ATTRIBUTE
           
private static java.lang.String INIT_METHOD_ATTRIBUTE
           
private static java.lang.String INLINE_SCRIPT_ELEMENT
           
private static java.lang.String PROXY_TARGET_CLASS_ATTRIBUTE
           
private static java.lang.String REFRESH_CHECK_DELAY_ATTRIBUTE
           
private static java.lang.String SCOPE_ATTRIBUTE
           
private static java.lang.String SCRIPT_INTERFACES_ATTRIBUTE
           
private static java.lang.String SCRIPT_SOURCE_ATTRIBUTE
           
private  java.lang.String scriptFactoryClassName
          The ScriptFactory class that this parser instance will create bean definitions for.
 
Fields inherited from class org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
ID_ATTRIBUTE, NAME_ATTRIBUTE
 
Constructor Summary
ScriptBeanDefinitionParser(java.lang.String scriptFactoryClassName)
          Create a new instance of this parser, creating bean definitions for the supplied ScriptFactory class.
 
Method Summary
protected  AbstractBeanDefinition parseInternal(org.w3c.dom.Element element, ParserContext parserContext)
          Parses the dynamic object element and returns the resulting bean definition.
private  java.lang.String resolveScriptSource(org.w3c.dom.Element element, XmlReaderContext readerContext)
          Resolves the script source from either the 'script-source' attribute or the 'inline-script' element.
protected  boolean shouldGenerateIdAsFallback()
          Scripted beans may be anonymous as well.
 
Methods inherited from class org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
parse, postProcessComponentDefinition, registerBeanDefinition, resolveId, shouldFireEvents, shouldGenerateId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCRIPT_SOURCE_ATTRIBUTE

private static final java.lang.String SCRIPT_SOURCE_ATTRIBUTE
See Also:
Constant Field Values

INLINE_SCRIPT_ELEMENT

private static final java.lang.String INLINE_SCRIPT_ELEMENT
See Also:
Constant Field Values

SCOPE_ATTRIBUTE

private static final java.lang.String SCOPE_ATTRIBUTE
See Also:
Constant Field Values

AUTOWIRE_ATTRIBUTE

private static final java.lang.String AUTOWIRE_ATTRIBUTE
See Also:
Constant Field Values

DEPENDENCY_CHECK_ATTRIBUTE

private static final java.lang.String DEPENDENCY_CHECK_ATTRIBUTE
See Also:
Constant Field Values

INIT_METHOD_ATTRIBUTE

private static final java.lang.String INIT_METHOD_ATTRIBUTE
See Also:
Constant Field Values

DESTROY_METHOD_ATTRIBUTE

private static final java.lang.String DESTROY_METHOD_ATTRIBUTE
See Also:
Constant Field Values

SCRIPT_INTERFACES_ATTRIBUTE

private static final java.lang.String SCRIPT_INTERFACES_ATTRIBUTE
See Also:
Constant Field Values

REFRESH_CHECK_DELAY_ATTRIBUTE

private static final java.lang.String REFRESH_CHECK_DELAY_ATTRIBUTE
See Also:
Constant Field Values

PROXY_TARGET_CLASS_ATTRIBUTE

private static final java.lang.String PROXY_TARGET_CLASS_ATTRIBUTE
See Also:
Constant Field Values

CUSTOMIZER_REF_ATTRIBUTE

private static final java.lang.String CUSTOMIZER_REF_ATTRIBUTE
See Also:
Constant Field Values

scriptFactoryClassName

private final java.lang.String scriptFactoryClassName
The ScriptFactory class that this parser instance will create bean definitions for.

Constructor Detail

ScriptBeanDefinitionParser

public ScriptBeanDefinitionParser(java.lang.String scriptFactoryClassName)
Create a new instance of this parser, creating bean definitions for the supplied ScriptFactory class.

Parameters:
scriptFactoryClassName - the ScriptFactory class to operate on
Method Detail

parseInternal

protected AbstractBeanDefinition parseInternal(org.w3c.dom.Element element,
                                               ParserContext parserContext)
Parses the dynamic object element and returns the resulting bean definition. Registers a ScriptFactoryPostProcessor if needed.

Specified by:
parseInternal in class AbstractBeanDefinitionParser
Parameters:
element - the element that is to be parsed into one or more BeanDefinitions
parserContext - the object encapsulating the current state of the parsing process; provides access to a BeanDefinitionRegistry
Returns:
the primary BeanDefinition resulting from the parsing of the supplied Element
See Also:
AbstractBeanDefinitionParser.parse(org.w3c.dom.Element, ParserContext), AbstractBeanDefinitionParser.postProcessComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)

resolveScriptSource

private java.lang.String resolveScriptSource(org.w3c.dom.Element element,
                                             XmlReaderContext readerContext)
Resolves the script source from either the 'script-source' attribute or the 'inline-script' element. Logs and ReaderContext.error(java.lang.String, java.lang.Object) and returns null if neither or both of these values are specified.


shouldGenerateIdAsFallback

protected boolean shouldGenerateIdAsFallback()
Scripted beans may be anonymous as well.

Overrides:
shouldGenerateIdAsFallback in class AbstractBeanDefinitionParser
Returns:
whether the parser should generate an id if no id was specified