Minimizing class loading in parsers and using the parser context error handling capabilities rather than throwing Exceptions or using assertions. This facilitates proper tooling support (INT-114).

This commit is contained in:
Mark Fisher
2008-12-11 19:18:40 +00:00
parent 20f9cbff65
commit c296b1af1b
5 changed files with 34 additions and 30 deletions

View File

@@ -23,7 +23,6 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractConsumerEndpointParser;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
@@ -33,7 +32,7 @@ import org.springframework.util.StringUtils;
*/
public abstract class AbstractRemotingOutboundGatewayParser extends AbstractConsumerEndpointParser {
protected abstract Class<?> getGatewayClass(Element element);
protected abstract String getGatewayClassName(Element element);
@Override
protected String getInputChannelAttributeName() {
@@ -55,27 +54,29 @@ public abstract class AbstractRemotingOutboundGatewayParser extends AbstractCons
@Override
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(this.getGatewayClass(element));
String url = this.parseUrl(element);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(this.getGatewayClassName(element));
String url = this.parseUrl(element, parserContext);
builder.addConstructorArgValue(url);
String replyChannel = element.getAttribute("reply-channel");
if (StringUtils.hasText(replyChannel)) {
builder.addPropertyReference("replyChannel", replyChannel);
}
this.postProcessGateway(builder, element);
this.postProcessGateway(builder, element, parserContext);
return builder;
}
protected String parseUrl(Element element) {
protected String parseUrl(Element element, ParserContext parserContext) {
String url = element.getAttribute("url");
Assert.hasText(url, "The 'url' attribute is required.");
if (!StringUtils.hasText(url)) {
parserContext.getReaderContext().error("The 'url' attribute is required.", element);
}
return url;
}
/**
* Subclasses may override this method for additional configuration.
*/
protected void postProcessGateway(BeanDefinitionBuilder builder, Element element) {
protected void postProcessGateway(BeanDefinitionBuilder builder, Element element, ParserContext parserContext) {
}
}

View File

@@ -19,7 +19,6 @@ package org.springframework.integration.httpinvoker.config;
import org.w3c.dom.Element;
import org.springframework.integration.adapter.config.AbstractRemotingOutboundGatewayParser;
import org.springframework.integration.httpinvoker.HttpInvokerOutboundGateway;
/**
* Parser for the &lt;outbound-gateway/&gt; element of the 'httpinvoker' namespace.
@@ -29,8 +28,8 @@ import org.springframework.integration.httpinvoker.HttpInvokerOutboundGateway;
public class HttpInvokerOutboundGatewayParser extends AbstractRemotingOutboundGatewayParser {
@Override
protected Class<?> getGatewayClass(Element element) {
return HttpInvokerOutboundGateway.class;
protected String getGatewayClassName(Element element) {
return "org.springframework.integration.httpinvoker.HttpInvokerOutboundGateway";
}
}

View File

@@ -35,7 +35,7 @@ import org.springframework.util.StringUtils;
*/
public class RmiInboundGateway extends RemotingInboundGatewaySupport implements InitializingBean {
public static final String SERVICE_NAME_PREFIX = "org.springframewok.integration.rmiGateway.";
public static final String SERVICE_NAME_PREFIX = "org.springframework.integration.rmiGateway.";
private volatile String requestChannelName;

View File

@@ -20,10 +20,9 @@ import java.rmi.registry.Registry;
import org.w3c.dom.Element;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.adapter.config.AbstractRemotingOutboundGatewayParser;
import org.springframework.integration.rmi.RmiInboundGateway;
import org.springframework.integration.rmi.RmiOutboundGateway;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
@@ -34,16 +33,18 @@ import org.springframework.util.StringUtils;
public class RmiOutboundGatewayParser extends AbstractRemotingOutboundGatewayParser {
@Override
protected Class<?> getGatewayClass(Element element) {
return RmiOutboundGateway.class;
protected String getGatewayClassName(Element element) {
return "org.springframework.integration.rmi.RmiOutboundGateway";
}
@Override
protected String parseUrl(Element element) {
protected String parseUrl(Element element, ParserContext parserContext) {
String host = element.getAttribute("host");
String remoteChannel = element.getAttribute("remote-channel");
Assert.isTrue(StringUtils.hasText(host) && StringUtils.hasText(remoteChannel),
"The 'host' and 'remote-channel' attributes are both required");
if (!StringUtils.hasText(host) || !StringUtils.hasText(remoteChannel)) {
parserContext.getReaderContext().error(
"The 'host' and 'remote-channel' attributes are both required", element);
}
String portAttribute = element.getAttribute("port");
String port = StringUtils.hasText(portAttribute) ? portAttribute : "" + Registry.REGISTRY_PORT;
return "rmi://" + host + ":" + port + "/" + RmiInboundGateway.SERVICE_NAME_PREFIX + remoteChannel;

View File

@@ -19,10 +19,8 @@ package org.springframework.integration.ws.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.adapter.config.AbstractRemotingOutboundGatewayParser;
import org.springframework.integration.ws.MarshallingWebServiceOutboundGateway;
import org.springframework.integration.ws.SimpleWebServiceOutboundGateway;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
@@ -33,20 +31,23 @@ import org.springframework.util.StringUtils;
public class WebServiceOutboundGatewayParser extends AbstractRemotingOutboundGatewayParser {
@Override
protected Class<?> getGatewayClass(Element element) {
return (StringUtils.hasText(element.getAttribute("marshaller"))) ?
MarshallingWebServiceOutboundGateway.class : SimpleWebServiceOutboundGateway.class;
protected String getGatewayClassName(Element element) {
String simpleClassName = (StringUtils.hasText(element.getAttribute("marshaller"))) ?
"MarshallingWebServiceOutboundGateway" : "SimpleWebServiceOutboundGateway";
return "org.springframework.integration.ws." + simpleClassName;
}
@Override
protected String parseUrl(Element element) {
protected String parseUrl(Element element, ParserContext parserContext) {
String uri = element.getAttribute("uri");
Assert.hasText(uri, "The 'uri' attribute is required.");
if (!StringUtils.hasText(uri)) {
parserContext.getReaderContext().error("The 'uri' attribute is required.", element);
}
return uri;
}
@Override
protected void postProcessGateway(BeanDefinitionBuilder builder, Element element) {
protected void postProcessGateway(BeanDefinitionBuilder builder, Element element, ParserContext parserContext) {
String marshallerRef = element.getAttribute("marshaller");
if (StringUtils.hasText(marshallerRef)) {
builder.addConstructorArgReference(marshallerRef);
@@ -78,8 +79,10 @@ public class WebServiceOutboundGatewayParser extends AbstractRemotingOutboundGat
}
String messageSenderRef = element.getAttribute("message-sender");
String messageSenderListRef = element.getAttribute("message-senders");
Assert.isTrue(!(StringUtils.hasText(messageSenderRef) && StringUtils.hasText(messageSenderListRef)),
"Only one of message-sender or message-senders should be specified");
if (StringUtils.hasText(messageSenderRef) && StringUtils.hasText(messageSenderListRef)) {
parserContext.getReaderContext().error(
"Only one of message-sender or message-senders should be specified", element);
}
if (StringUtils.hasText(messageSenderRef)) {
builder.addPropertyReference("messageSender", messageSenderRef);
}