formatting

This commit is contained in:
Mark Fisher
2010-11-01 14:36:07 -04:00
parent 4e4c4f69ff
commit 36dad9371c
9 changed files with 69 additions and 82 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 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.
@@ -58,24 +58,19 @@ public class XPathExpressionParser extends AbstractSingleBeanDefinitionParser {
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
String expression = element.getAttribute("expression");
Assert.hasText(expression, "The 'expression' attribute is required.");
String nsPrefix = element.getAttribute("ns-prefix");
String nsUri = element.getAttribute("ns-uri");
String namespaceMapRef = element.getAttribute("namespace-map");
boolean prefixProvided = StringUtils.hasText(nsPrefix);
boolean namespaceProvided = StringUtils.hasText(nsUri);
boolean namespaceMapProvided = StringUtils.hasText(namespaceMapRef);
if (prefixProvided || namespaceProvided) {
Assert.isTrue(prefixProvided && namespaceProvided,
"Both 'ns-prefix' and 'ns-uri' must be specified if one is specified.");
Assert.isTrue(!namespaceMapProvided, "It is not valid to specify both namespace and namespace-map.");
}
builder.setFactoryMethod("createXPathExpression");
builder.addConstructorArgValue(expression);
if (prefixProvided) {
Map<String, String> namespaceMap = new HashMap<String, String>();
namespaceMap.put(nsPrefix, nsUri);
@@ -103,8 +98,7 @@ public class XPathExpressionParser extends AbstractSingleBeanDefinitionParser {
}
}
@SuppressWarnings("unchecked")
protected Map parseNamespaceMapElement(Element element, ParserContext parserContext, BeanDefinition parentDefinition) {
protected Map<?,?> parseNamespaceMapElement(Element element, ParserContext parserContext, BeanDefinition parentDefinition) {
BeanDefinitionParserDelegate beanParser = new BeanDefinitionParserDelegate(parserContext.getReaderContext());
beanParser.initDefaults(element.getOwnerDocument().getDocumentElement());
return beanParser.parseMapElement(element, parentDefinition);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 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.
@@ -23,6 +23,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractConsumerEndpointParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.xml.splitter.XPathMessageSplitter;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -49,14 +50,10 @@ public class XPathMessageSplitterParser extends AbstractConsumerEndpointParser {
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(XPathMessageSplitter.class);
String xPathExpressionRef = element.getAttribute("xpath-expression-ref");
String documentBuilderFactoryRef = element.getAttribute("doc-builder-factory");
String createDocuments = element.getAttribute("create-documents");
NodeList xPathExpressionNodes = element.getElementsByTagNameNS(element.getNamespaceURI(), "xpath-expression");
Assert.isTrue(xPathExpressionNodes.getLength() <= 1, "only one xpath-expression child can be specified");
Assert.isTrue(xPathExpressionNodes.getLength() <= 1, "At most one xpath-expression child may be specified.");
boolean hasChild = xPathExpressionNodes.getLength() == 1;
boolean hasReference = StringUtils.hasText(xPathExpressionRef);
Assert.isTrue(hasChild ^ hasReference, "Exactly one of 'xpath-expression' or 'xpath-expression-ref' is required.");
if (hasChild) {
BeanDefinition beanDefinition = this.xpathParser.parse((Element) xPathExpressionNodes.item(0), parserContext);
@@ -65,14 +62,8 @@ public class XPathMessageSplitterParser extends AbstractConsumerEndpointParser {
else {
builder.addConstructorArgReference(xPathExpressionRef);
}
if(StringUtils.hasText(documentBuilderFactoryRef)){
builder.addPropertyReference("documentBuilder", documentBuilderFactoryRef);
}
if(StringUtils.hasText("create-documents")){
builder.addPropertyValue("createDocuments", Boolean.valueOf(createDocuments));
}
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "doc-builder-factory", "documentBuilder");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "create-documents");
return builder;
}

View File

@@ -16,14 +16,15 @@
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.ParserContext;
import org.springframework.integration.config.xml.AbstractRouterParser;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* Parser for the &lt;xpath-router/&gt; element.
@@ -36,14 +37,14 @@ public class XPathRouterParser extends AbstractRouterParser {
private XPathExpressionParser xpathParser = new XPathExpressionParser();
@Override
protected BeanDefinition doParseRouter(Element element,
ParserContext parserContext) {
protected BeanDefinition doParseRouter(Element element, ParserContext parserContext) {
BeanDefinitionBuilder xpathRouterBuilder = BeanDefinitionBuilder.genericBeanDefinition(
"org.springframework.integration.xml.router.XPathRouter");
NodeList xPathExpressionNodes = element.getElementsByTagNameNS(
element.getNamespaceURI(), "xpath-expression");
Assert.isTrue(xPathExpressionNodes.getLength() < 2, "Only one xpath-expression child can be specified.");
Assert.isTrue(xPathExpressionNodes.getLength() <= 1, "At most one xpath-expression child may be specified.");
String xPathExpressionRef = element.getAttribute("xpath-expression-ref");
boolean xPathExpressionChildPresent = (xPathExpressionNodes.getLength() == 1);
boolean xPathReferencePresent = StringUtils.hasText(xPathExpressionRef);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 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.
@@ -16,18 +16,18 @@
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.beans.factory.config.BeanDefinition;
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
*/
@@ -52,7 +52,7 @@ public class XPathSelectorParser extends AbstractSingleBeanDefinitionParser {
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");
Assert.isTrue(xPathExpressionNodes.getLength() <= 1, "At most one xpath-expression child may be specified.");
boolean xPathExpressionChildPresent = xPathExpressionNodes.getLength() == 1;
boolean xPathReferencePresent = StringUtils.hasText(xPathExpressionRef);
Assert.isTrue(xPathExpressionChildPresent ^ xPathReferencePresent,

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 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.

View File

@@ -16,61 +16,32 @@
package org.springframework.integration.xml.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractConsumerEndpointParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* @author Jonas Partner
* @author Oleg Zhurakousky
*/
public class XmlPayloadValidatingFilterParser extends AbstractConsumerEndpointParser {
private static String SELECTOR =
"org.springframework.integration.xml.selector.XmlValidatingMessageSelector";
private static String FILTER =
"org.springframework.integration.config.FilterFactoryBean";
private static String SELECTOR_CLASSNAME = "org.springframework.integration.xml.selector.XmlValidatingMessageSelector";
private static String FILTER_CLASSNAME = "org.springframework.integration.config.FilterFactoryBean";
/** Constant that defines a W3C XML Schema. */
public static final String SCHEMA_W3C_XML = "http://www.w3.org/2001/XMLSchema";
public static final String SCHEMA_W3C_XML = "http://www.w3.org/2001/XMLSchema";
/** Constant that defines a RELAX NG Schema. */
public static final String SCHEMA_RELAX_NG = "http://relaxng.org/ns/structure/1.0";
/** Constant that defines a RELAX NG Schema. */
public static final String SCHEMA_RELAX_NG = "http://relaxng.org/ns/structure/1.0";
@Override
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
BeanDefinitionBuilder filterBuilder = BeanDefinitionBuilder.genericBeanDefinition(FILTER);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(filterBuilder, element, "discard-channel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(filterBuilder, element, "throw-exception-on-rejection");
BeanDefinitionBuilder selectorBuilder = BeanDefinitionBuilder.genericBeanDefinition(SELECTOR);
String validator = element.getAttribute("xml-validator");
String schemaLocation = element.getAttribute("schema-location");
boolean validatorDefined = StringUtils.hasText(validator);
boolean schemaLocationDefined = StringUtils.hasText(schemaLocation);
selectorBuilder.addPropertyValue("throwExceptionOnRejection", element.getAttribute("throw-exception-on-rejection"));
if (!(validatorDefined ^ schemaLocationDefined)) {
throw new BeanDefinitionStoreException("Exactly one of 'xml-validator' or 'schema-location' is allowed on the 'validating-filter' element");
}
if (schemaLocationDefined){
selectorBuilder.addConstructorArgValue(schemaLocation);
// it is a restriction with the default value of 'xml-schema' which corresponds to 'http://www.w3.org/2001/XMLSchema'
String schemaType = "xml-schema".equals(element.getAttribute("schema-type")) ? SCHEMA_W3C_XML : SCHEMA_RELAX_NG;;
selectorBuilder.addConstructorArgValue(schemaType);
}
else {
selectorBuilder.addConstructorArgReference(validator);
}
filterBuilder.addPropertyValue("targetObject", selectorBuilder.getBeanDefinition());
return filterBuilder;
}
@Override
protected boolean shouldGenerateId() {
return false;
@@ -80,4 +51,35 @@ public class XmlPayloadValidatingFilterParser extends AbstractConsumerEndpointPa
protected boolean shouldGenerateIdAsFallback() {
return true;
}
@Override
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
BeanDefinitionBuilder filterBuilder = BeanDefinitionBuilder.genericBeanDefinition(FILTER_CLASSNAME);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(filterBuilder, element, "discard-channel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(filterBuilder, element, "throw-exception-on-rejection");
BeanDefinitionBuilder selectorBuilder = BeanDefinitionBuilder.genericBeanDefinition(SELECTOR_CLASSNAME);
String validator = element.getAttribute("xml-validator");
String schemaLocation = element.getAttribute("schema-location");
boolean validatorDefined = StringUtils.hasText(validator);
boolean schemaLocationDefined = StringUtils.hasText(schemaLocation);
if (!(validatorDefined ^ schemaLocationDefined)) {
throw new BeanDefinitionStoreException(
"Exactly one of 'xml-validator' or 'schema-location' is allowed on the 'validating-filter' element");
}
if (schemaLocationDefined) {
selectorBuilder.addConstructorArgValue(schemaLocation);
// it is a restriction with the default value of 'xml-schema' which
// corresponds to 'http://www.w3.org/2001/XMLSchema'
String schemaType = "xml-schema".equals(element.getAttribute("schema-type"))
? SCHEMA_W3C_XML : SCHEMA_RELAX_NG;
selectorBuilder.addConstructorArgValue(schemaType);
}
else {
selectorBuilder.addConstructorArgReference(validator);
}
selectorBuilder.addPropertyValue("throwExceptionOnRejection", element.getAttribute("throw-exception-on-rejection"));
filterBuilder.addPropertyValue("targetObject", selectorBuilder.getBeanDefinition());
return filterBuilder;
}
}

View File

@@ -19,6 +19,8 @@ package org.springframework.integration.xml.config;
import java.util.List;
import java.util.Map;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.support.RootBeanDefinition;
@@ -29,7 +31,6 @@ import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
/**
* @author Jonas Partner
@@ -63,23 +64,21 @@ public class XsltPayloadTransformerParser extends AbstractTransformerParser {
if (StringUtils.hasText(resultTransformer)) {
builder.addConstructorArgReference(resultTransformer);
}
List<Element> xslParameterElements = DomUtils.getChildElementsByTagName(element, "xslt-param");
if (!CollectionUtils.isEmpty(xslParameterElements)) {
Map<String, Object> xslParameterMappings = new ManagedMap<String, Object>();
for (Element xslParameterElement : xslParameterElements) {
String name = xslParameterElement.getAttribute("name");
String expression = xslParameterElement.getAttribute("expression");
String value = xslParameterElement.getAttribute("value");
Assert.isTrue(StringUtils.hasText(expression) ^ StringUtils.hasText(value),
"Exactly one of 'expression' or 'value' is required.");
RootBeanDefinition expressionDef = null;
if (StringUtils.hasText(value)){
if (StringUtils.hasText(value)) {
expressionDef = new RootBeanDefinition("org.springframework.expression.common.LiteralExpression");
expressionDef.getConstructorArgumentValues().addGenericArgumentValue(value);
} else if (StringUtils.hasText(expression)){
}
else if (StringUtils.hasText(expression)) {
expressionDef = new RootBeanDefinition("org.springframework.integration.config.ExpressionFactoryBean");
expressionDef.getConstructorArgumentValues().addGenericArgumentValue(expression);
}
@@ -89,7 +88,7 @@ public class XsltPayloadTransformerParser extends AbstractTransformerParser {
}
builder.addPropertyValue("xslParameterMappings", xslParameterMappings);
}
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "source-factory");
}
}