Replaced the <annotation-driven/> element with "enable-annotations" on the <message-bus/> element (INT-401).

This commit is contained in:
Mark Fisher
2008-10-08 00:52:16 +00:00
parent 759bf68b91
commit 221f6167a5
10 changed files with 46 additions and 114 deletions

View File

@@ -17,7 +17,6 @@
package org.springframework.integration.config;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
import org.springframework.integration.config.annotation.AnnotationDrivenParser;
import org.springframework.integration.gateway.config.GatewayParser;
/**
@@ -30,7 +29,6 @@ public class IntegrationNamespaceHandler extends NamespaceHandlerSupport {
public void init() {
registerBeanDefinitionParser("message-bus", new MessageBusParser());
registerBeanDefinitionParser("annotation-driven", new AnnotationDrivenParser());
registerBeanDefinitionParser("channel", new PointToPointChannelParser());
registerBeanDefinitionParser("thread-local-channel", new ThreadLocalChannelParser());
registerBeanDefinitionParser("publish-subscribe-channel", new PublishSubscribeChannelParser());

View File

@@ -23,14 +23,18 @@ import org.w3c.dom.NodeList;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.bus.DefaultMessageBus;
import org.springframework.integration.bus.MessageBus;
import org.springframework.integration.bus.MessageBusAwareBeanPostProcessor;
import org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor;
import org.springframework.integration.config.annotation.PublisherAnnotationPostProcessor;
import org.springframework.util.Assert;
/**
@@ -43,17 +47,14 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
public static final String MESSAGE_BUS_BEAN_NAME = "internal.MessageBus";
public static final String MESSAGE_BUS_AWARE_POST_PROCESSOR_BEAN_NAME = "internal.MessageBusAwareBeanPostProcessor";
public static final String MESSAGE_BUS_AWARE_POST_PROCESSOR_BEAN_NAME =
"internal.MessageBusAwareBeanPostProcessor";
private static final String TASK_SCHEDULER_ATTRIBUTE = "task-scheduler";
private static final String PUBLISHER_ANNOTATION_POST_PROCESSOR_BEAN_NAME =
"internal.PublisherAnnotationPostProcessor";
private static final String CHANNEL_FACTORY_ATTRIBUTE = "channel-factory";
private static final String INTERCEPTOR_ELEMENT = "interceptor";
private static final String REFERENCE_ATTRIBUTE = "ref";
private static final String INTERCEPTORS_PROPERTY = "interceptors";
private static final String MESSAGING_ANNOTATION_POST_PROCESSOR_BEAN_NAME =
"internal.MessagingAnnotationPostProcessor";
@Override
@@ -71,15 +72,14 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
@Override
protected boolean isEligibleAttribute(String attributeName) {
return !TASK_SCHEDULER_ATTRIBUTE.equals(attributeName) &&
!CHANNEL_FACTORY_ATTRIBUTE.equals(attributeName) &&
return !"task-scheduler".equals(attributeName) &&
!"enable-annotations".equals(attributeName) &&
super.isEligibleAttribute(attributeName);
}
@Override
protected void postProcess(BeanDefinitionBuilder builder, Element element) {
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, TASK_SCHEDULER_ATTRIBUTE);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, CHANNEL_FACTORY_ATTRIBUTE);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "task-scheduler");
this.processChildElements(builder, element);
}
@@ -90,28 +90,31 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
for (int i = 0; i < childNodes.getLength(); i++) {
Node child = childNodes.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
String localName = child.getLocalName();
if (INTERCEPTOR_ELEMENT.equals(localName)) {
interceptors.add(new RuntimeBeanReference(((Element)child).getAttribute(REFERENCE_ATTRIBUTE)));
if ("interceptor".equals(child.getLocalName())) {
interceptors.add(new RuntimeBeanReference(((Element)child).getAttribute("ref")));
}
}
}
if (interceptors.size() > 0) {
builder.addPropertyValue(INTERCEPTORS_PROPERTY, interceptors);
builder.addPropertyValue("interceptors", interceptors);
}
}
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
super.doParse(element, parserContext, builder);
this.addPostProcessors(parserContext);
this.addPostProcessors(element, parserContext);
}
/**
* Adds extra post-processors to the context, to inject the objects configured by the MessageBus
*/
private void addPostProcessors(ParserContext parserContext) {
private void addPostProcessors(Element element, ParserContext parserContext) {
this.registerMessageBusAwarePostProcessor(parserContext);
if ("true".equals(element.getAttribute("enable-annotations").toLowerCase())) {
this.registerPublisherPostProcessor(parserContext);
this.registerMessagingAnnotationPostProcessor(parserContext);
}
}
private void registerMessageBusAwarePostProcessor(ParserContext parserContext) {
@@ -121,4 +124,20 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
parserContext.getRegistry().registerBeanDefinition(MESSAGE_BUS_AWARE_POST_PROCESSOR_BEAN_NAME, builder.getBeanDefinition());
}
private void registerPublisherPostProcessor(ParserContext parserContext) {
BeanDefinition bd = new RootBeanDefinition(PublisherAnnotationPostProcessor.class);
bd.getPropertyValues().addPropertyValue("channelRegistry",
new RuntimeBeanReference(MessageBusParser.MESSAGE_BUS_BEAN_NAME));
BeanComponentDefinition bcd = new BeanComponentDefinition(
bd, PUBLISHER_ANNOTATION_POST_PROCESSOR_BEAN_NAME);
parserContext.registerBeanComponent(bcd);
}
private void registerMessagingAnnotationPostProcessor(ParserContext parserContext) {
BeanDefinition bd = new RootBeanDefinition(MessagingAnnotationPostProcessor.class);
BeanComponentDefinition bcd = new BeanComponentDefinition(
bd, MESSAGING_ANNOTATION_POST_PROCESSOR_BEAN_NAME);
parserContext.registerBeanComponent(bcd);
}
}

View File

@@ -1,66 +0,0 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.config.annotation;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.MessageBusParser;
/**
* Parser for the <em>annotation-driven</em> element of the integration
* namespace. Registers the annotation-driven post-processors.
*
* @author Mark Fisher
*/
public class AnnotationDrivenParser implements BeanDefinitionParser {
private static final String PUBLISHER_ANNOTATION_POST_PROCESSOR_BEAN_NAME =
"internal.PublisherAnnotationPostProcessor";
private static final String MESSAGING_ANNOTATION_POST_PROCESSOR_BEAN_NAME =
"internal.MessagingAnnotationPostProcessor";
public BeanDefinition parse(Element element, ParserContext parserContext) {
this.registerPublisherPostProcessor(parserContext);
this.registerMessagingAnnotationPostProcessor(parserContext);
return null;
}
private void registerPublisherPostProcessor(ParserContext parserContext) {
BeanDefinition bd = new RootBeanDefinition(PublisherAnnotationPostProcessor.class);
bd.getPropertyValues().addPropertyValue("channelRegistry",
new RuntimeBeanReference(MessageBusParser.MESSAGE_BUS_BEAN_NAME));
BeanComponentDefinition bcd = new BeanComponentDefinition(
bd, PUBLISHER_ANNOTATION_POST_PROCESSOR_BEAN_NAME);
parserContext.registerBeanComponent(bcd);
}
private void registerMessagingAnnotationPostProcessor(ParserContext parserContext) {
BeanDefinition bd = new RootBeanDefinition(MessagingAnnotationPostProcessor.class);
BeanComponentDefinition bcd = new BeanComponentDefinition(
bd, MESSAGING_ANNOTATION_POST_PROCESSOR_BEAN_NAME);
parserContext.registerBeanComponent(bcd);
}
}

View File

@@ -30,22 +30,13 @@
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="auto-startup" type="xsd:boolean"/>
<xsd:attribute name="enable-annotations" type="xsd:boolean"/>
<xsd:attribute name="task-scheduler" type="xsd:string"/>
<xsd:attribute name="auto-startup" type="xsd:boolean"/>
<xsd:attribute name="configure-async-event-multicaster" type="xsd:boolean"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="annotation-driven">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
Enables the annotation-driven post-processors.
</xsd:documentation>
</xsd:annotation>
</xsd:complexType>
</xsd:element>
<xsd:element name="channel">
<xsd:annotation>
<xsd:documentation>

View File

@@ -7,9 +7,7 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<integration:message-bus/>
<integration:annotation-driven/>
<integration:message-bus enable-annotations="true"/>
<integration:channel id="inputChannel"/>

View File

@@ -7,8 +7,7 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<message-bus/>
<annotation-driven/>
<message-bus enable-annotations="true"/>
<channel id="inputChannel"/>

View File

@@ -7,9 +7,7 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<integration:message-bus/>
<integration:annotation-driven/>
<integration:message-bus enable-annotations="true"/>
<integration:channel id="inputChannel"/>

View File

@@ -9,9 +9,7 @@
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<message-bus/>
<annotation-driven/>
<message-bus enable-annotations="true"/>
<channel id="inputChannel"/>

View File

@@ -7,9 +7,7 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<integration:message-bus/>
<integration:annotation-driven/>
<integration:message-bus enable-annotations="true"/>
<integration:channel id="inputChannel"/>

View File

@@ -6,8 +6,7 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<message-bus />
<annotation-driven />
<message-bus enable-annotations="true"/>
<channel id="inAnnotated" />
<channel id="inDefault" />