The <splitter/> element now creates a DefaultSplitter when no "ref" attribute is defined (INT-354).

This commit is contained in:
Mark Fisher
2008-09-28 18:56:34 +00:00
parent 98fc463155
commit 9afcda0a68
4 changed files with 17 additions and 5 deletions

View File

@@ -56,12 +56,13 @@ public abstract class AbstractEndpointParser extends AbstractSingleBeanDefinitio
/**
* Subclasses may override this method to specify whether the endpoint type
* expects a "ref" (and possibly a "method") in order to adapt an Object.
* Subclasses may override this method to determine whether the endpoint
* type should create an adapter. If so, the "ref" attribute will be
* required, and the "method" attribute will typically be used as well.
*
* <p>The default is <em>true</em>.
*/
protected boolean requiresBeanReference() {
protected boolean shouldCreateAdapter(Element element) {
return true;
}
@@ -82,7 +83,7 @@ public abstract class AbstractEndpointParser extends AbstractSingleBeanDefinitio
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
if (this.requiresBeanReference()) {
if (this.shouldCreateAdapter(element)) {
String ref = element.getAttribute(REF_ATTRIBUTE);
if (!StringUtils.hasText(ref)) {
throw new ConfigurationException("The '" + REF_ATTRIBUTE + "' attribute is required.");

View File

@@ -16,6 +16,8 @@
package org.springframework.integration.config;
import org.w3c.dom.Element;
import org.springframework.integration.endpoint.MessageEndpoint;
import org.springframework.integration.splitter.MethodInvokingSplitter;
import org.springframework.integration.splitter.SplitterEndpoint;
@@ -27,6 +29,11 @@ import org.springframework.integration.splitter.SplitterEndpoint;
*/
public class SplitterParser extends AbstractEndpointParser {
@Override
protected boolean shouldCreateAdapter(Element element) {
return element.hasAttribute("ref");
}
@Override
protected Class<? extends MessageEndpoint> getEndpointClass() {
return SplitterEndpoint.class;

View File

@@ -31,6 +31,10 @@ public class SplitterEndpoint extends AbstractMessageHandlingEndpoint {
private final Splitter splitter;
public SplitterEndpoint() {
this(new DefaultSplitter());
}
public SplitterEndpoint(Splitter splitter) {
Assert.notNull(splitter, "splitter must not be null");
this.splitter = splitter;

View File

@@ -32,7 +32,7 @@ import org.springframework.integration.transformer.TransformerEndpoint;
public abstract class AbstractTransformerParser extends AbstractEndpointParser {
@Override
protected boolean requiresBeanReference() {
protected boolean shouldCreateAdapter(Element element) {
return false;
}