Removed ConfigurationException.

This commit is contained in:
Mark Fisher
2008-10-10 01:52:35 +00:00
parent b68f7ca17a
commit bdb4a866c8
6 changed files with 23 additions and 72 deletions

View File

@@ -16,17 +16,17 @@
package org.springframework.integration.xml.config;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.xml.router.XPathMultiChannelNameResolver;
import org.springframework.integration.xml.router.XPathSingleChannelNameResolver;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* @author Jonas Partner
@@ -56,11 +56,8 @@ public class XPathRouterParser extends AbstractSingleBeanDefinitionParser {
boolean xPathExpressionChildPresent = xPathExpressionNodes.getLength() == 1;
boolean xPathReferencePresent = StringUtils.hasText(xPathExpressionRef);
if ((xPathExpressionChildPresent && xPathReferencePresent)
|| (!xPathExpressionChildPresent && !xPathReferencePresent)) {
throw new ConfigurationException("Exactly one of 'xpath-expression' or 'xpath-expression-ref' is required.");
}
Assert.isTrue(xPathExpressionChildPresent ^ xPathReferencePresent,
"Exactly one of 'xpath-expression' or 'xpath-expression-ref' is required.");
if (multiChannel) {
builder.getBeanDefinition().setBeanClass(XPathMultiChannelNameResolver.class);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* 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.
@@ -13,29 +13,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.xml.config;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.xml.selector.BooleanTestXPathMessageSelector;
import org.springframework.integration.xml.selector.StringValueTestXPathMessageSelector;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
*
* @author Jonas Partner
*
*/
public class XPathSelectorParser extends AbstractSingleBeanDefinitionParser {
private XPathExpressionParser xpathParser = new XPathExpressionParser();
@Override
protected boolean shouldGenerateId() {
return false;
@@ -48,39 +48,30 @@ public class XPathSelectorParser extends AbstractSingleBeanDefinitionParser {
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
String evaluationType = element.getAttribute("evaluation-result-type");
String xPathExpressionRef = element.getAttribute("xpath-expression-ref");
String stringTestValue = element.getAttribute("string-test-value");
NodeList xPathExpressionNodes = element.getElementsByTagNameNS(element.getNamespaceURI(), "xpath-expression");
Assert.isTrue(xPathExpressionNodes.getLength() < 2, "Only one xpath-expression child can be specified");
boolean xPathExpressionChildPresent = xPathExpressionNodes.getLength() == 1;
boolean xPathReferencePresent = StringUtils.hasText(xPathExpressionRef);
if ((xPathExpressionChildPresent && xPathReferencePresent)
|| (!xPathExpressionChildPresent && !xPathReferencePresent)) {
throw new ConfigurationException("Exactly one of 'xpath-expression' or 'xpath-expression-ref' is required.");
}
Assert.isTrue(xPathExpressionChildPresent ^ xPathReferencePresent,
"Exactly one of 'xpath-expression' or 'xpath-expression-ref' is required.");
if (evaluationType.equals("boolean")) {
builder.getBeanDefinition().setBeanClass(BooleanTestXPathMessageSelector.class);
Assert.state(!StringUtils.hasText(stringTestValue),
"string-test-value should not be specified when evaluation-result-type is boolean");
"'string-test-value' should not be specified when 'evaluation-result-type' is boolean");
}
else if (evaluationType.equals("string")) {
Assert
.hasText(stringTestValue,
"string-test-value must be specified when evaluation-result-type is string");
Assert.hasText(stringTestValue,
"'string-test-value' must be specified when 'evaluation-result-type' is string");
builder.addConstructorArgValue(stringTestValue);
builder.getBeanDefinition().setBeanClass(StringValueTestXPathMessageSelector.class);
}
else {
throw new ConfigurationException("Unrecognised value: " + evaluationType
+ " for evaluation-result-type only boolean or string supported");
throw new IllegalArgumentException("Unsupported value [" + evaluationType
+ "] for 'evaluation-result-type', expected boolean or string.");
}
if (xPathExpressionChildPresent) {
BeanDefinition beanDefinition = xpathParser.parse((Element) xPathExpressionNodes.item(0), parserContext);
builder.addConstructorArgValue(beanDefinition);