From fa36d6e461c484603ef148c8c67f48284b80bf6d Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Fri, 2 May 2008 23:28:55 +0000 Subject: [PATCH] SWS-309 --- .../oxm/castor/CastorMarshaller.java | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java b/oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java index fbad8d30..21035e31 100644 --- a/oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java +++ b/oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java @@ -21,6 +21,8 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; +import java.util.Iterator; +import java.util.Properties; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLEventWriter; import javax.xml.stream.XMLStreamReader; @@ -95,6 +97,8 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing private boolean ignoreExtraElements = false; + private Properties namespaceMappings; + /** Returns whether the Castor {@link Unmarshaller} should ignore attributes that do not match a specific field. */ public boolean getIgnoreExtraAttributes() { return ignoreExtraAttributes; @@ -103,6 +107,8 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing /** * Sets whether the Castor {@link Unmarshaller} should ignore attributes that do not match a specific field. * Default is true: extra attributes are ignored. + * + * @see org.exolab.castor.xml.Unmarshaller#setIgnoreExtraAttributes(boolean) */ public void setIgnoreExtraAttributes(boolean ignoreExtraAttributes) { this.ignoreExtraAttributes = ignoreExtraAttributes; @@ -116,6 +122,8 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing /** * Sets whether the Castor {@link Unmarshaller} should ignore elements that do not match a specific field. Default * is false, extra attributes are flagged as an error. + * + * @see org.exolab.castor.xml.Unmarshaller#setIgnoreExtraElements(boolean) */ public void setIgnoreExtraElements(boolean ignoreExtraElements) { this.ignoreExtraElements = ignoreExtraElements; @@ -129,6 +137,8 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing /** * Sets whether the Castor {@link Unmarshaller} should preserve "ignorable" whitespace. Default is * false. + * + * @see org.exolab.castor.xml.Unmarshaller#setWhitespacePreserve(boolean) */ public void setWhitespacePreserve(boolean whitespacePreserve) { this.whitespacePreserve = whitespacePreserve; @@ -139,11 +149,29 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing return validating; } - /** Sets whether this marshaller should validate in- and outgoing documents. Default is false. */ + /** + * Sets whether this marshaller should validate in- and outgoing documents. Default is false. + * + * @see Marshaller#setValidation(boolean) + */ public void setValidating(boolean validating) { this.validating = validating; } + /** Returns the namespace mappings. Property names are interpreted as namespace prefixes; values are namespace URIs. */ + public Properties getNamespaceMappings() { + return namespaceMappings; + } + + /** + * Sets the namespace mappings. Property names are interpreted as namespace prefixes; values are namespace URIs. + * + * @see org.exolab.castor.xml.Marshaller#setNamespaceMapping(String, String) + */ + public void setNamespaceMappings(Properties namespaceMappings) { + this.namespaceMappings = namespaceMappings; + } + /** * Sets the encoding to be used for stream access. If this property is not set, the default encoding is used. * @@ -280,10 +308,19 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing * Template method that allows for customizing of the given Castor {@link Marshaller}. *

* Default implementation invokes {@link Marshaller#setValidation(boolean)} with the property set on this - * marshaller. + * marshaller, and calls {@link Marshaller#setNamespaceMapping(String, String)} with the {@linkplain + * #setNamespaceMappings(java.util.Properties) namespace mappings}. */ protected void customizeMarshaller(Marshaller marshaller) { marshaller.setValidation(isValidating()); + Properties namespaceMappings = getNamespaceMappings(); + if (namespaceMappings != null) { + for (Iterator iterator = namespaceMappings.keySet().iterator(); iterator.hasNext();) { + String prefix = (String) iterator.next(); + String uri = namespaceMappings.getProperty(prefix); + marshaller.setNamespaceMapping(prefix, uri); + } + } } //