|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.beans.factory.xml.AbstractBeanDefinitionParser oranjestad.spring.beanutils.messaging.xml.OrjParser
public class OrjParser
Parser that builds up several objects to perform listener injection.
In addition to defining an AddListenerBeanPostProcessor
, this parser
might also define additional objects (such as mapped dispatchers). The
following section details examples of the namespaced XML and what the equivalent
raw beans that would be defined by this.
100: <orj:add-listener 100: <bean class="oranjestad.spring.beanutils.messaging.AddListenerBeanPostProcessor">
101: channel="someChannel" 101: <property name="channel" value="someChannel" />
102: bean="producerBean" 102: <property name="producerName" value="producerBean" />
103: ref="listenerBean"/> 103: <property name="args">
104: <list>
105: <bean ref="listenerBean" />
106: </list>
107: </property>
108: <bean>
The above is the most basic example, where the add-listener
simplifies a basic definition of AddListenerBeanPostProcessor
.
100: <orj:add-listener 100: <bean class="oranjestad.spring.beanutils.messaging.AddListenerBeanPostProcessor">
101: channel="someChannel" 101: <property name="channel" value="someChannel" />
102: bean="producerBean"> 102: <property name="producerName" value="producerBean" />
103: <orj:add-listener-arg> 103: <property name="args">
104: <orj:value>val1</orj:value> 104: <list>
105: </orj:add-listener-arg> 105: <value>val1</value>
106: <orj:add-listener-arg> 106: <null />
107: <orj:null /> 107: <bean ref="listenerBean" />
108: </orj:add-listener-arg> 108: </list>
109: <orj:add-listener-arg 109: </property>
110: listener-obj="true"> 110: <property name="listenerIndex" value="2" />
111: <orj:ref 111: <bean>
112: bean="listenerBean"/>
113: </orj:add-listener-arg>
114: </orj:add-listener>
This example shows how a multi argument add listener method is called and how
this relates back to the underlying AddListenerBeanPostProcessor
.
Notice the importances of the listener-obj
attribute of the third
add-listener
tag. This allows the listener index to be determined.
100: <orj:add-listener 100: <bean class="oranjestad.spring.beanutils.messaging.AddListenerBeanPostProcessor">
101: channel="someChannel" 101: <property name="channel" value="someChannel" />
102: bean="producerBean" 102: <property name="producerName" value="producerBean" />
103: ref="listenerBean"> 103: <property name="args">
104: <orj:map-method 104: <list>
105: method="originalMethod1" 105: <bean ref="dispatcher" />
106: to-method="newMethod1"> 106: </list>
107: <orj:nested-arg /> 107: </property>
108: <orj:nested-arg 108: <property name="holder">
109: value="arguments[0].someProp" /> 109: <bean id="dispatcher"
110: <orj:nested-arg 110: class="oranjestad.spring.beanutils.messaging.dispatching.SpringMappedMethodAndArgumentsDispatcher">
111: value="beanFactory(someBean)" /> 111: <property name="target" ref="listenerBean" />
112: </orj:map-method> 112: <property name="mappings">
113: </orj:add-listener> 113: <map>
114: <entry>
115: <key><value>originalMethod1</value><key>
116: <bean class="oranjestad.commons.beanutils.messaging.dispatching.MappedNameAndArgumentsMethod">
117: <property name="targetMethodName" value="newMethod1" />
118: <property name="argumentTransforms">
119: <list>
120: <null />
121: <value>arguments[0].someProp</value>
122: <value>beanFactory(someBean)</value>
123: </list>
124: </property>
125: </bean>
126: <entry>
127: </map>
128: </property>
129: </bean>
130: </property>
131: </bean>
This example really highlights the flexibility of the extended XML. The
underlying objects created are the standard AddListenerBeanPostProcessor
but instead of directly adding the listener bean, a SpringMappedMethodAndArgumentsDispatcher
is added instead (Oranjestad-commons messaging introspection allows instances
of GenericMessageListener
to be added to any channel).
The dispatching bean handles mapping method invocations to the target object. The list of argument transforms, uses Jakarta commons beanutils nested property references to map arguments in the method call.
In the above example, calls to the method originalMethod
are mapped to the new method newMethod
which has three parameters.
The first parameter passed in will always be null. The second pulls out the
property someProp from the first argument passed into the original
method, while the third property will be the spring bean named someBean.
See SpringMappedMethodAndArgumentsDispatcher
for more information
on mapping properties.
Field Summary |
---|
Fields inherited from class org.springframework.beans.factory.xml.AbstractBeanDefinitionParser |
---|
ID_ATTRIBUTE |
Constructor Summary | |
---|---|
OrjParser()
|
Method Summary | |
---|---|
protected int |
parseAddListenerArg(org.w3c.dom.Element element,
org.springframework.beans.factory.xml.ParserContext parserContext,
org.springframework.beans.factory.parsing.ParseState parseState,
org.springframework.beans.factory.support.ManagedList args)
Internal method that parses the add-listener-arg tags. |
protected org.springframework.beans.factory.support.AbstractBeanDefinition |
parseInternal(org.w3c.dom.Element element,
org.springframework.beans.factory.xml.ParserContext parserContext)
|
protected org.springframework.beans.factory.support.BeanDefinitionBuilder |
parseMappings(org.w3c.dom.Element element,
org.springframework.beans.factory.xml.ParserContext parserContext,
org.springframework.beans.factory.parsing.ParseState parseState)
Internal method that parses the map-method tags. |
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 |
---|
public OrjParser()
Method Detail |
---|
protected org.springframework.beans.factory.support.AbstractBeanDefinition parseInternal(org.w3c.dom.Element element, org.springframework.beans.factory.xml.ParserContext parserContext)
parseInternal
in class org.springframework.beans.factory.xml.AbstractBeanDefinitionParser
protected int parseAddListenerArg(org.w3c.dom.Element element, org.springframework.beans.factory.xml.ParserContext parserContext, org.springframework.beans.factory.parsing.ParseState parseState, org.springframework.beans.factory.support.ManagedList args)
add-listener-arg
tags.
element
- The root add-listener
element.parserContext
- The context passed in by Spring.parseState
- The stack defining which tag we are on.args
- The argument list to populate.
-1
if it
cannot be inferred.protected org.springframework.beans.factory.support.BeanDefinitionBuilder parseMappings(org.w3c.dom.Element element, org.springframework.beans.factory.xml.ParserContext parserContext, org.springframework.beans.factory.parsing.ParseState parseState)
map-method
tags.
element
- The root add-listener
element.parserContext
- The context passed in by Spring.parseState
- The stack defining which tag we are on.
SpringMappedMethodAndArgumentsDispatcher
if any mapped methods are required. This object must be set into the
hanger property of the add listener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |