From 36dad9371c2df1bff0823f4bb2a0579f473c5f7f Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 1 Nov 2010 14:36:07 -0400 Subject: [PATCH] formatting --- .../config/MarshallingTransformerParser.java | 2 +- .../UnmarshallingTransformerParser.java | 2 +- .../xml/config/XPathExpressionParser.java | 10 +-- .../config/XPathMessageSplitterParser.java | 19 ++--- .../xml/config/XPathRouterParser.java | 11 +-- .../xml/config/XPathSelectorParser.java | 12 +-- .../xml/config/XmlNamespaceUtils.java | 2 +- .../XmlPayloadValidatingFilterParser.java | 80 ++++++++++--------- .../config/XsltPayloadTransformerParser.java | 13 ++- 9 files changed, 69 insertions(+), 82 deletions(-) diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/MarshallingTransformerParser.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/MarshallingTransformerParser.java index edfa517191..fa796df527 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/MarshallingTransformerParser.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/MarshallingTransformerParser.java @@ -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. diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/UnmarshallingTransformerParser.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/UnmarshallingTransformerParser.java index 2a6436ae5e..fc7d31e381 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/UnmarshallingTransformerParser.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/UnmarshallingTransformerParser.java @@ -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. diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathExpressionParser.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathExpressionParser.java index 69bf51bbe5..24bf68e4a9 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathExpressionParser.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathExpressionParser.java @@ -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 namespaceMap = new HashMap(); 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); diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathMessageSplitterParser.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathMessageSplitterParser.java index 7e798632be..8b714b1303 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathMessageSplitterParser.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathMessageSplitterParser.java @@ -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; } diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathRouterParser.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathRouterParser.java index 22da832772..e36f3daebe 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathRouterParser.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathRouterParser.java @@ -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 <xpath-router/> 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); diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathSelectorParser.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathSelectorParser.java index 241f795518..c63b3dd6c2 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathSelectorParser.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathSelectorParser.java @@ -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, diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XmlNamespaceUtils.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XmlNamespaceUtils.java index a3d7a4b574..439e79cc46 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XmlNamespaceUtils.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XmlNamespaceUtils.java @@ -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. diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XmlPayloadValidatingFilterParser.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XmlPayloadValidatingFilterParser.java index d98e1dcdb0..ddbc97bdac 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XmlPayloadValidatingFilterParser.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XmlPayloadValidatingFilterParser.java @@ -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; + } + } diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XsltPayloadTransformerParser.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XsltPayloadTransformerParser.java index 96c2380bc2..2661711074 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XsltPayloadTransformerParser.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XsltPayloadTransformerParser.java @@ -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 xslParameterElements = DomUtils.getChildElementsByTagName(element, "xslt-param"); if (!CollectionUtils.isEmpty(xslParameterElements)) { Map xslParameterMappings = new ManagedMap(); 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"); } + }