From 4e4c4f69ffcf5975e5e86069e55263675442a40b Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 1 Nov 2010 14:17:39 -0400 Subject: [PATCH] polishing --- ...gregatedXmlMessageValidationException.java | 34 +++-- .../xml/DefaultXmlPayloadConverter.java | 140 +++++++++--------- .../integration/xml/XmlPayloadConverter.java | 5 +- 3 files changed, 101 insertions(+), 78 deletions(-) diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/AggregatedXmlMessageValidationException.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/AggregatedXmlMessageValidationException.java index 011369040c..9649dc8f8b 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/AggregatedXmlMessageValidationException.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/AggregatedXmlMessageValidationException.java @@ -1,8 +1,22 @@ -/** - * +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + package org.springframework.integration.xml; +import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -12,18 +26,20 @@ import java.util.List; */ @SuppressWarnings("serial") public class AggregatedXmlMessageValidationException extends RuntimeException { - + private final List exceptions; - public AggregatedXmlMessageValidationException(List exceptions){ - this.exceptions = exceptions; + + public AggregatedXmlMessageValidationException(List exceptions) { + this.exceptions = (exceptions != null) ? exceptions : Collections.emptyList(); } + + /** - * Will return iterator of exceptions aggregated by this Class. - * - * @return + * Returns an Iterator for the aggregated Exceptions. */ - public Iterator exceptionIterator(){ + public Iterator exceptionIterator() { return exceptions.iterator(); } + } diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/DefaultXmlPayloadConverter.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/DefaultXmlPayloadConverter.java index 7a85368523..890b9795da 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/DefaultXmlPayloadConverter.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/DefaultXmlPayloadConverter.java @@ -25,89 +25,95 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Source; import javax.xml.transform.dom.DOMSource; -import org.springframework.integration.MessagingException; -import org.springframework.xml.transform.StringSource; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xml.sax.InputSource; +import org.springframework.integration.MessagingException; +import org.springframework.xml.transform.StringSource; + /** - * Default implementation of {@link XmlPayloadConverter}. - * Supports {@link Document} and {@link String}. - * + * Default implementation of {@link XmlPayloadConverter}. Supports + * {@link Document}, {@link File} and {@link String} payloads. + * * @author Jonas Partner */ public class DefaultXmlPayloadConverter implements XmlPayloadConverter { - private DocumentBuilderFactory documentBuilderFactory; + private DocumentBuilderFactory documentBuilderFactory; - public DefaultXmlPayloadConverter() { - this.documentBuilderFactory = DocumentBuilderFactory.newInstance(); - this.documentBuilderFactory.setNamespaceAware(true); - } + public DefaultXmlPayloadConverter() { + this.documentBuilderFactory = DocumentBuilderFactory.newInstance(); + this.documentBuilderFactory.setNamespaceAware(true); + } - public DefaultXmlPayloadConverter(DocumentBuilderFactory documentBuilderFactory) { - this.documentBuilderFactory = documentBuilderFactory; - } + public DefaultXmlPayloadConverter(DocumentBuilderFactory documentBuilderFactory) { + this.documentBuilderFactory = documentBuilderFactory; + } - public Document convertToDocument(Object object) { - if (object instanceof Document) { - return (Document) object; - } - if (object instanceof File) { - try { - return getDocumentBuilder().parse((File) object); - } - catch (Exception e) { - throw new MessagingException("failed to parse File payload '" + object + "'", e); - } - } - if (object instanceof String) { - try { - return getDocumentBuilder().parse(new InputSource(new StringReader((String) object))); - } - catch (Exception e) { - throw new MessagingException("failed to parse String payload '" + object + "'", e); - } - } - throw new MessagingException("unsupported payload type [" + object.getClass().getName() + "]"); - } + public Document convertToDocument(Object object) { + if (object instanceof Document) { + return (Document) object; + } + if (object instanceof File) { + try { + return getDocumentBuilder().parse((File) object); + } + catch (Exception e) { + throw new MessagingException("failed to parse File payload '" + object + "'", e); + } + } + if (object instanceof String) { + try { + return getDocumentBuilder().parse(new InputSource(new StringReader((String) object))); + } + catch (Exception e) { + throw new MessagingException("failed to parse String payload '" + object + "'", e); + } + } + throw new MessagingException("unsupported payload type [" + object.getClass().getName() + "]"); + } - public Node convertToNode(Object object) { - Node n = null; - if (object instanceof Node) { - n = (Node) object; - } else if (object instanceof DOMSource) { - n = ((DOMSource) object).getNode(); - } else { - n = convertToDocument(object); - } - return n; - } + public Node convertToNode(Object object) { + Node node = null; + if (object instanceof Node) { + node = (Node) object; + } + else if (object instanceof DOMSource) { + node = ((DOMSource) object).getNode(); + } + else { + node = convertToDocument(object); + } + return node; + } - public Source convertToSource(Object object) { - Source source; - if (object instanceof Source) { - source = (Source) object; - } else if (object instanceof Document) { - source = new DOMSource((Document) object); - } else if (object instanceof String) { - source = new StringSource((String) object); - } else { - throw new MessagingException("unsupported payload type [" + object.getClass().getName() + "]"); - } - return source; - } + public Source convertToSource(Object object) { + Source source = null; + if (object instanceof Source) { + source = (Source) object; + } + else if (object instanceof Document) { + source = new DOMSource((Document) object); + } + else if (object instanceof String) { + source = new StringSource((String) object); + } + else { + throw new MessagingException("unsupported payload type [" + object.getClass().getName() + "]"); + } + return source; + } - protected synchronized DocumentBuilder getDocumentBuilder() { - try { - return this.documentBuilderFactory.newDocumentBuilder(); - } - catch (ParserConfigurationException e) { - throw new MessagingException("failed to create a new DocumentBuilder", e); - } - } + protected synchronized DocumentBuilder getDocumentBuilder() { + try { + return this.documentBuilderFactory.newDocumentBuilder(); + } + catch (ParserConfigurationException e) { + throw new MessagingException("failed to create a new DocumentBuilder", e); + } + } } diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/XmlPayloadConverter.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/XmlPayloadConverter.java index 0a92c04b0e..aae58e2382 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/XmlPayloadConverter.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/XmlPayloadConverter.java @@ -22,7 +22,8 @@ import org.w3c.dom.Document; import org.w3c.dom.Node; /** - * Converter for creating XML {@link Document} instances + * Converter for creating XML {@link Document}, {@link Node} or {@link Source} + * instances from other types (e.g. String). * * @author Jonas Partner */ @@ -31,7 +32,7 @@ public interface XmlPayloadConverter { public Document convertToDocument(Object object); public Node convertToNode(Object object); - + public Source convertToSource(Object object); }