updated EndpointInterceptorParser.java
This commit is contained in:
@@ -19,74 +19,17 @@ package org.springframework.integration.config;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.ManagedList;
|
||||
import org.springframework.beans.factory.xml.NamespaceHandler;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A helper class for parsing the sub-elements of an endpoint's
|
||||
* <em>interceptors</em> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class EndpointInterceptorParser {
|
||||
public class EndpointInterceptorParser extends AbstractInterceptorParser {
|
||||
|
||||
private final Map<String, BeanDefinitionRegisteringParser> parsers = new HashMap<String, BeanDefinitionRegisteringParser>();
|
||||
|
||||
public EndpointInterceptorParser() {
|
||||
this.parsers.put("transaction-interceptor", new TransactionInterceptorParser());
|
||||
this.parsers.put("concurrency-interceptor", new ConcurrencyInterceptorParser());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ManagedList parseEndpointInterceptors(Element element, ParserContext parserContext) {
|
||||
ManagedList interceptors = new ManagedList();
|
||||
NodeList childNodes = element.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node child = childNodes.item(i);
|
||||
if (child.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element childElement = (Element) child;
|
||||
String localName = child.getLocalName();
|
||||
if ("bean".equals(localName)) {
|
||||
interceptors.add(new RuntimeBeanReference(
|
||||
IntegrationNamespaceUtils.parseBeanDefinitionElement(childElement, parserContext)));
|
||||
}
|
||||
else if ("ref".equals(localName)) {
|
||||
String ref = childElement.getAttribute("bean");
|
||||
interceptors.add(new RuntimeBeanReference(ref));
|
||||
}
|
||||
else {
|
||||
BeanDefinitionRegisteringParser parser = this.parsers.get(localName);
|
||||
String interceptorBeanName = null;
|
||||
if (parser == null) {
|
||||
interceptorBeanName = handleNonstandardInterceptor(childElement, parserContext);
|
||||
}
|
||||
else {
|
||||
interceptorBeanName = parser.parse(childElement, parserContext);
|
||||
}
|
||||
interceptors.add(new RuntimeBeanReference(interceptorBeanName));
|
||||
}
|
||||
}
|
||||
}
|
||||
return interceptors;
|
||||
}
|
||||
|
||||
protected String handleNonstandardInterceptor(Element childElement, ParserContext parserContext) {
|
||||
NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver()
|
||||
.resolve(childElement.getNamespaceURI());
|
||||
AbstractBeanDefinition interceptorDefinition =
|
||||
((AbstractBeanDefinition) handler.parse(childElement, parserContext));
|
||||
String beanName = (String) interceptorDefinition.getMetadataAttribute("interceptorName").getValue();
|
||||
Assert.hasText("No value for interceptorName provided by namespace handler for element '"
|
||||
+ childElement.getNodeName() + "'");
|
||||
return beanName;
|
||||
@Override
|
||||
protected Map<String, BeanDefinitionRegisteringParser> getParserMap() {
|
||||
Map<String, BeanDefinitionRegisteringParser> parsers = new HashMap<String, BeanDefinitionRegisteringParser>();
|
||||
parsers.put("transaction-interceptor", new TransactionInterceptorParser());
|
||||
parsers.put("concurrency-interceptor", new ConcurrencyInterceptorParser());
|
||||
return parsers;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user