Fixed SWS-133: CastorMarshaller ignoreExtraAttributes & Elements

This commit is contained in:
Arjen Poutsma
2007-05-31 12:19:19 +00:00
parent 4d14a0bfb2
commit 3d6dcb7a51
8 changed files with 309 additions and 235 deletions

View File

@@ -32,7 +32,7 @@
</target>
<target name="generate-test-castor" depends="generate-test-init" unless="skip">
<taskdef name="castor-srcgen" classname="org.exolab.castor.tools.ant.taskdefs.CastorSourceGenTask"
<taskdef name="castor-srcgen" classname="org.castor.anttask.CastorCodeGenTask"
classpathref="maven.test.classpath"/>
<castor-srcgen types="j2" warnings="false" file="${schema}" todir="${generate.target.directory}"
package="org.springframework.oxm.castor"/>

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>spring-ws</artifactId>
<groupId>org.springframework.ws</groupId>
@@ -29,8 +30,8 @@
<configuration>
<tasks>
<ant antfile="${basedir}/build-maven2.xml" inheritRefs="true">
<property name="maven.test.skip" value="${maven.test.skip}" />
<target name="generate-test-sources" />
<property name="maven.test.skip" value="${maven.test.skip}"/>
<target name="generate-test-sources"/>
</ant>
</tasks>
<testSourceRoot>${project.build.directory}/generated-sources/test/java</testSourceRoot>
@@ -45,8 +46,8 @@
<configuration>
<tasks>
<ant antfile="${basedir}/build-maven2.xml" inheritRefs="true">
<property name="maven.test.skip" value="${maven.test.skip}" />
<target name="test-compile" />
<property name="maven.test.skip" value="${maven.test.skip}"/>
<target name="test-compile"/>
</ant>
</tasks>
</configuration>
@@ -55,6 +56,13 @@
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-codegen-anttask</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

View File

@@ -59,38 +59,11 @@ import org.xml.sax.helpers.XMLReaderFactory;
*/
public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
/**
* Logger available to subclasses.
*/
/** Logger available to subclasses. */
protected final Log logger = LogFactory.getLog(getClass());
private boolean validating = false;
private boolean namespaceAware = true;
private DocumentBuilderFactory documentBuilderFactory;
/**
* Set whether or not the XML parser should be XML namespace aware. Default is <code>true</code>.
*/
public void setNamespaceAware(boolean namespaceAware) {
this.namespaceAware = namespaceAware;
}
/**
* Set if the XML parser should validate the document. Default is <code>false</code>.
*/
public void setValidating(boolean validating) {
this.validating = validating;
}
/**
* Returns whether the XML parser should validate the document. Default is <code>false</code>.
*/
public boolean isValidating() {
return validating;
}
/**
* Marshals the object graph with the given root into the provided <code>javax.xml.transform.Result</code>.
* <p/>
@@ -103,9 +76,9 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
* @throws IOException if an I/O exception occurs
* @throws IllegalArgumentException if <code>result</code> if neither a <code>DOMResult</code>,
* <code>SAXResult</code>, <code>StreamResult</code>
* @see #marshalDomResult(Object, javax.xml.transform.dom.DOMResult)
* @see #marshalSaxResult(Object, javax.xml.transform.sax.SAXResult)
* @see #marshalStreamResult(Object, javax.xml.transform.stream.StreamResult)
* @see #marshalDomResult(Object,javax.xml.transform.dom.DOMResult)
* @see #marshalSaxResult(Object,javax.xml.transform.sax.SAXResult)
* @see #marshalStreamResult(Object,javax.xml.transform.stream.StreamResult)
*/
public final void marshal(Object graph, Result result) throws XmlMappingException, IOException {
if (result instanceof DOMResult) {
@@ -183,8 +156,8 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
*/
protected DocumentBuilderFactory createDocumentBuilderFactory() throws ParserConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(validating);
factory.setNamespaceAware(namespaceAware);
factory.setValidating(false);
factory.setNamespaceAware(true);
return factory;
}
@@ -246,7 +219,7 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
* @param graph the root of the object graph to marshal
* @param saxResult the <code>SAXResult</code>
* @throws XmlMappingException if the given object cannot be marshalled to the result
* @see #marshalSaxHandlers(Object, org.xml.sax.ContentHandler, org.xml.sax.ext.LexicalHandler)
* @see #marshalSaxHandlers(Object,org.xml.sax.ContentHandler,org.xml.sax.ext.LexicalHandler)
*/
protected void marshalSaxResult(Object graph, SAXResult saxResult) throws XmlMappingException {
ContentHandler contentHandler = saxResult.getHandler();
@@ -340,7 +313,7 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
* @return the object graph
* @throws XmlMappingException if the given source cannot be mapped to an object
* @throws IOException if an I/O Exception occurs
* @see #unmarshalSaxReader(org.xml.sax.XMLReader, org.xml.sax.InputSource)
* @see #unmarshalSaxReader(org.xml.sax.XMLReader,org.xml.sax.InputSource)
*/
protected Object unmarshalSaxSource(SAXSource saxSource) throws XmlMappingException, IOException {
if (saxSource.getXMLReader() == null) {

View File

@@ -91,22 +91,65 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
private boolean whitespacePreserve = false;
private boolean ignoreExtraAttributes = true;
private boolean ignoreExtraElements = false;
/**
* Set if the Castor <code>Unmarshaller</code> should validate the incoming document. Default is
* <code>false</code>.
* Returns whether the Castor {@link Unmarshaller} should ignore attributes that do not match
* a specific field.
*/
public void setValidating(boolean validating) {
this.validating = validating;
public boolean getIgnoreExtraAttributes() {
return ignoreExtraAttributes;
}
/**
* Indicates whether the Castor <code>Unmarshaller</code> should preserve "ignorable" whitespace. Default is
* Sets whether the Castor {@link Unmarshaller} should ignore attributes that do not match
* a specific field. Default is <code>true</code>: extra attributes are ignored.
*/
public void setIgnoreExtraAttributes(boolean ignoreExtraAttributes) {
this.ignoreExtraAttributes = ignoreExtraAttributes;
}
/**
* Returns whether the Castor {@link Unmarshaller} should ignore elements that do not match
* a specific field.
*/
public boolean getIgnoreExtraElements() {
return ignoreExtraElements;
}
/**
* Sets whether the Castor {@link Unmarshaller} should ignore elements that do not match
* a specific field. Default is <code>false</code>, extra attributes are flagged as an error.
*/
public void setIgnoreExtraElements(boolean ignoreExtraElements) {
this.ignoreExtraElements = ignoreExtraElements;
}
/** Returns whether the Castor {@link Unmarshaller} should preserve "ignorable" whitespace. */
public boolean getWhitespacePreserve() {
return whitespacePreserve;
}
/**
* Sets whether the Castor {@link Unmarshaller} should preserve "ignorable" whitespace. Default is
* <code>false</code>.
*/
public void setWhitespacePreserve(boolean whitespacePreserve) {
this.whitespacePreserve = whitespacePreserve;
}
/** Returns whether this marshaller should validate in- and outgoing documents. */
public boolean isValidating() {
return validating;
}
/** Sets whether this marshaller should validate in- and outgoing documents. Default is <code>false</code>. */
public void setValidating(boolean validating) {
this.validating = validating;
}
/**
* Sets the encoding to be used for stream access. If this property is not set, the default encoding is used.
*
@@ -116,16 +159,6 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
this.encoding = encoding;
}
/**
* Sets the Castor target class. If this property is set, this <code>CastorMarshaller</code> is tied to this one
* specific class. Use a mapping file for unmarshalling multiple classes.
* <p/>
* You cannot set both this property and the mapping (location).
*/
public void setTargetClass(Class targetClass) {
this.targetClass = targetClass;
}
/** Sets the locations of the Castor XML Mapping files. */
public void setMappingLocation(Resource mappingLocation) {
mappingLocations = new Resource[]{mappingLocation};
@@ -136,6 +169,16 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
this.mappingLocations = mappingLocations;
}
/**
* Sets the Castor target class. If this property is set, this <code>CastorMarshaller</code> is tied to this one
* specific class. Use a mapping file for unmarshalling multiple classes.
* <p/>
* You cannot set both this property and the mapping (location).
*/
public void setTargetClass(Class targetClass) {
this.targetClass = targetClass;
}
public final void afterPropertiesSet() throws IOException {
if (mappingLocations != null && targetClass != null) {
throw new IllegalArgumentException("Cannot set both the 'mappingLocations' and 'targetClass' property. " +
@@ -160,10 +203,103 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
}
}
/** Returns <code>true</code> for all classes, i.e. Castor supports arbitrary classes. */
public boolean supports(Class clazz) {
return true;
}
protected final void marshalDomNode(Object graph, Node node) throws XmlMappingException {
marshalSaxHandlers(graph, new DomContentHandler(node), null);
}
protected final void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)
throws XmlMappingException {
try {
marshal(graph, new Marshaller(contentHandler));
}
catch (IOException ex) {
throw new CastorSystemException("Could not construct Castor ContentHandler Marshaller", ex);
}
}
protected final void marshalOutputStream(Object graph, OutputStream outputStream)
throws XmlMappingException, IOException {
marshalWriter(graph, new OutputStreamWriter(outputStream, encoding));
}
protected final void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException {
marshal(graph, new Marshaller(writer));
}
protected final void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter) throws XmlMappingException {
marshalSaxHandlers(graph, new StaxEventContentHandler(eventWriter), null);
}
protected final void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException {
marshalSaxHandlers(graph, new StaxStreamContentHandler(streamWriter), null);
}
protected final Object unmarshalDomNode(Node node) throws XmlMappingException {
try {
return createUnmarshaller().unmarshal(node);
}
catch (XMLException ex) {
throw convertCastorException(ex, false);
}
}
protected final Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException {
try {
return createUnmarshaller().unmarshal(new InputSource(inputStream));
}
catch (XMLException ex) {
throw convertCastorException(ex, false);
}
}
protected final Object unmarshalReader(Reader reader) throws XmlMappingException, IOException {
try {
return createUnmarshaller().unmarshal(new InputSource(reader));
}
catch (XMLException ex) {
throw convertCastorException(ex, false);
}
}
protected final Object unmarshalXmlEventReader(XMLEventReader eventReader) {
XMLReader reader = new StaxEventXmlReader(eventReader);
try {
return unmarshalSaxReader(reader, new InputSource());
}
catch (IOException ex) {
throw new CastorUnmarshallingFailureException(new MarshalException(ex));
}
}
protected final Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)
throws XmlMappingException, IOException {
UnmarshalHandler unmarshalHandler = createUnmarshaller().createHandler();
try {
ContentHandler contentHandler = Unmarshaller.getContentHandler(unmarshalHandler);
xmlReader.setContentHandler(contentHandler);
xmlReader.parse(inputSource);
return unmarshalHandler.getObject();
}
catch (SAXException ex) {
throw new CastorUnmarshallingFailureException(ex);
}
}
protected final Object unmarshalXmlStreamReader(XMLStreamReader streamReader) {
XMLReader reader = new StaxStreamXmlReader(streamReader);
try {
return unmarshalSaxReader(reader, new InputSource());
}
catch (IOException ex) {
throw new CastorUnmarshallingFailureException(new MarshalException(ex));
}
}
/**
* Creates the Castor <code>XMLClassDescriptorResolver</code>. Subclasses can override this to create a custom
* resolver.
@@ -194,6 +330,55 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
return classDescriptorResolver;
}
private Unmarshaller createUnmarshaller() {
Unmarshaller unmarshaller = null;
if (targetClass != null) {
unmarshaller = new Unmarshaller(targetClass);
}
else {
unmarshaller = new Unmarshaller();
}
unmarshaller.setResolver(classDescriptorResolver);
customizeUnmarshaller(unmarshaller);
return unmarshaller;
}
/**
* Template method that allows for customizing of the given Castor {@link Unmarshaller}.
* <p/>
* Default implementation invokes {@link Unmarshaller#setValidation(boolean)},
* {@link Unmarshaller#setWhitespacePreserve(boolean)},
* {@link Unmarshaller#setIgnoreExtraAttributes(boolean)}, and {@link Unmarshaller#setIgnoreExtraElements(boolean)}
* with the properties set on this marshaller.
*/
protected void customizeUnmarshaller(Unmarshaller unmarshaller) {
unmarshaller.setValidation(isValidating());
unmarshaller.setWhitespacePreserve(getWhitespacePreserve());
unmarshaller.setIgnoreExtraAttributes(getIgnoreExtraAttributes());
unmarshaller.setIgnoreExtraElements(getIgnoreExtraElements());
}
private void marshal(Object graph, Marshaller marshaller) {
try {
marshaller.setResolver(classDescriptorResolver);
customizeMarshaller(marshaller);
marshaller.marshal(graph);
}
catch (XMLException ex) {
throw convertCastorException(ex, true);
}
}
/**
* Template method that allows for customizing of the given Castor {@link Marshaller}.
* <p/>
* Default implementation invokes {@link Marshaller#setValidation(boolean)} with the property set on this
* marshaller.
*/
protected void customizeMarshaller(Marshaller marshaller) {
marshaller.setValidation(isValidating());
}
/**
* Converts the given <code>CastorException</code> to an appropriate exception from the
* <code>org.springframework.oxm</code> hierarchy.
@@ -213,125 +398,5 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
return CastorUtils.convertXmlException(ex, marshalling);
}
private Unmarshaller createUnmarshaller() {
Unmarshaller unmarshaller = null;
if (targetClass != null) {
unmarshaller = new Unmarshaller(targetClass);
}
else {
unmarshaller = new Unmarshaller();
}
unmarshaller.setResolver(classDescriptorResolver);
unmarshaller.setValidation(validating);
unmarshaller.setWhitespacePreserve(whitespacePreserve);
return unmarshaller;
}
private void marshal(Object graph, Marshaller marshaller) {
try {
marshaller.setResolver(classDescriptorResolver);
marshaller.marshal(graph);
}
catch (XMLException ex) {
throw convertCastorException(ex, true);
}
}
protected void marshalDomNode(Object graph, Node node) throws XmlMappingException {
ContentHandler contentHandler = new DomContentHandler(node);
marshalSaxHandlers(graph, contentHandler, null);
}
protected void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter) throws XmlMappingException {
ContentHandler contentHandler = new StaxEventContentHandler(eventWriter);
marshalSaxHandlers(graph, contentHandler, null);
}
protected void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException {
ContentHandler contentHandler = new StaxStreamContentHandler(streamWriter);
marshalSaxHandlers(graph, contentHandler, null);
}
protected void marshalOutputStream(Object graph, OutputStream outputStream)
throws XmlMappingException, IOException {
OutputStreamWriter writer = new OutputStreamWriter(outputStream, encoding);
marshalWriter(graph, writer);
}
protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)
throws XmlMappingException {
try {
Marshaller marshaller = new Marshaller(contentHandler);
marshal(graph, marshaller);
}
catch (IOException ex) {
throw new CastorSystemException("Could not construct Castor ContentHandler Marshaller", ex);
}
}
protected void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException {
Marshaller marshaller = new Marshaller(writer);
marshal(graph, marshaller);
}
protected Object unmarshalDomNode(Node node) throws XmlMappingException {
try {
return createUnmarshaller().unmarshal(node);
}
catch (XMLException ex) {
throw convertCastorException(ex, false);
}
}
protected Object unmarshalXmlEventReader(XMLEventReader eventReader) {
XMLReader reader = new StaxEventXmlReader(eventReader);
try {
return unmarshalSaxReader(reader, new InputSource());
}
catch (IOException ex) {
throw new CastorUnmarshallingFailureException(new MarshalException(ex));
}
}
protected Object unmarshalXmlStreamReader(XMLStreamReader streamReader) {
XMLReader reader = new StaxStreamXmlReader(streamReader);
try {
return unmarshalSaxReader(reader, new InputSource());
}
catch (IOException ex) {
throw new CastorUnmarshallingFailureException(new MarshalException(ex));
}
}
protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)
throws XmlMappingException, IOException {
UnmarshalHandler unmarshalHandler = createUnmarshaller().createHandler();
try {
ContentHandler contentHandler = Unmarshaller.getContentHandler(unmarshalHandler);
xmlReader.setContentHandler(contentHandler);
xmlReader.parse(inputSource);
return unmarshalHandler.getObject();
}
catch (SAXException ex) {
throw new CastorUnmarshallingFailureException(ex);
}
}
protected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException {
try {
return createUnmarshaller().unmarshal(new InputSource(inputStream));
}
catch (XMLException ex) {
throw convertCastorException(ex, false);
}
}
protected Object unmarshalReader(Reader reader) throws XmlMappingException, IOException {
try {
return createUnmarshaller().unmarshal(new InputSource(reader));
}
catch (XMLException ex) {
throw convertCastorException(ex, false);
}
}
// abstract
}

View File

@@ -20,6 +20,7 @@ import org.apache.xmlbeans.XmlOptions;
import org.apache.xmlbeans.XmlSaxHandler;
import org.apache.xmlbeans.XmlValidationError;
import org.springframework.oxm.AbstractMarshaller;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.XmlMappingException;
import org.springframework.xml.stream.StaxEventContentHandler;
import org.springframework.xml.stream.StaxEventXmlReader;
@@ -36,61 +37,60 @@ import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
/**
* Implementation of the <code>Marshaller</code> interface for XMLBeans. Further options can be set by setting the
* <code>xmlOptions</code> property. A <code>XmlOptionsFactoryBean</code> is provided to easily wire up
* <code>XmlObjects</code> instances.
* Implementation of the {@link Marshaller} interface for XMLBeans. Further options can be set by setting the
* <code>xmlOptions</code> property. The {@link XmlOptionsFactoryBean} is provided to easily wire up
* {@link XmlOptions} instances.
* <p/>
* Unmarshalled objects can be validated by setting the <code>validating</code> property, or by calling the
* <code>validiate()</code> method directly. Invalid objects will result in an <code>XmlBeansValidationFailureException</code>.
* {@link #validate(XmlObject)} method directly. Invalid objects will result in an
* {@link XmlBeansValidationFailureException}.
* <p/>
* <strong>Note</strong> that due to the nature of XMLBeans, this marshaller requires all passed objects to be of type
* <code>XmlObject</code>.
* {@link XmlObject}.
*
* @author Arjen Poutsma
* @see #setXmlOptions(org.apache.xmlbeans.XmlOptions)
* @see XmlOptionsFactoryBean
* @see #setValidating(boolean)
* @see org.apache.xmlbeans.XmlObject
*/
public class XmlBeansMarshaller extends AbstractMarshaller {
private XmlOptions xmlOptions;
private boolean validating = false;
/** Returns the <code>XmlOptions</code>. */
public XmlOptions getXmlOptions() {
return xmlOptions;
}
/**
* Sets the <code>XmlOptions</code>.
*
* @param xmlOptions the xml options
* @see XmlOptionsFactoryBean
*/
public void setXmlOptions(XmlOptions xmlOptions) {
this.xmlOptions = xmlOptions;
}
/** Returns whether this marshaller should validate in- and outgoing documents. */
public boolean isValidating() {
return validating;
}
/** Sets whether this marshaller should validate in- and outgoing documents. Default is <code>false</code>. */
public void setValidating(boolean validating) {
this.validating = validating;
}
/** Returns true if the given class is an implementation of {@link XmlObject}. */
public boolean supports(Class clazz) {
return XmlObject.class.isAssignableFrom(clazz);
}
/**
* Converts the given XMLBeans exception to an appropriate exception from the <code>org.springframework.oxm</code>
* hierarchy.
* <p/>
* The default implementation delegates to <code>XmlBeansUtils</code>. Can be overridden in subclasses.
* <p/>
* A boolean flag is used to indicate whether this exception occurs during marshalling or unmarshalling, since
* XMLBeans itself does not make this distinction in its exception hierarchy.
*
* @param ex XMLBeans Exception that occured
* @param marshalling indicates whether the exception occurs during marshalling (<code>true</code>), or
* unmarshalling (<code>false</code>)
* @return the corresponding <code>XmlMappingException</code>
* @see XmlBeansUtils#convertXmlBeansException(Exception,boolean)
*/
public XmlMappingException convertXmlBeansException(Exception ex, boolean marshalling) {
return XmlBeansUtils.convertXmlBeansException(ex, marshalling);
}
protected void marshalDomNode(Object graph, Node node) throws XmlMappingException {
protected final void marshalDomNode(Object graph, Node node) throws XmlMappingException {
Document document = node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node : node.getOwnerDocument();
Node xmlBeansNode = ((XmlObject) graph).newDomNode(xmlOptions);
Node xmlBeansNode = ((XmlObject) graph).newDomNode(getXmlOptions());
NodeList xmlBeansChildNodes = xmlBeansNode.getChildNodes();
for (int i = 0; i < xmlBeansChildNodes.getLength(); i++) {
Node xmlBeansChildNode = xmlBeansChildNodes.item(i);
@@ -99,38 +99,38 @@ public class XmlBeansMarshaller extends AbstractMarshaller {
}
}
protected void marshalOutputStream(Object graph, OutputStream outputStream)
protected final void marshalOutputStream(Object graph, OutputStream outputStream)
throws XmlMappingException, IOException {
((XmlObject) graph).save(outputStream, xmlOptions);
((XmlObject) graph).save(outputStream, getXmlOptions());
}
protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)
protected final void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)
throws XmlMappingException {
try {
((XmlObject) graph).save(contentHandler, lexicalHandler, xmlOptions);
((XmlObject) graph).save(contentHandler, lexicalHandler, getXmlOptions());
}
catch (SAXException ex) {
throw convertXmlBeansException(ex, true);
}
}
protected void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException {
((XmlObject) graph).save(writer, xmlOptions);
protected final void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException {
((XmlObject) graph).save(writer, getXmlOptions());
}
protected void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter) {
protected final void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter) {
ContentHandler contentHandler = new StaxEventContentHandler(eventWriter);
marshalSaxHandlers(graph, contentHandler, null);
}
protected void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException {
protected final void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException {
ContentHandler contentHandler = new StaxStreamContentHandler(streamWriter);
marshalSaxHandlers(graph, contentHandler, null);
}
protected Object unmarshalDomNode(Node node) throws XmlMappingException {
protected final Object unmarshalDomNode(Node node) throws XmlMappingException {
try {
XmlObject object = XmlObject.Factory.parse(node, xmlOptions);
XmlObject object = XmlObject.Factory.parse(node, getXmlOptions());
validate(object);
return object;
}
@@ -139,9 +139,9 @@ public class XmlBeansMarshaller extends AbstractMarshaller {
}
}
protected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException {
protected final Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException {
try {
XmlObject object = XmlObject.Factory.parse(inputStream, xmlOptions);
XmlObject object = XmlObject.Factory.parse(inputStream, getXmlOptions());
validate(object);
return object;
}
@@ -150,9 +150,9 @@ public class XmlBeansMarshaller extends AbstractMarshaller {
}
}
protected Object unmarshalReader(Reader reader) throws XmlMappingException, IOException {
protected final Object unmarshalReader(Reader reader) throws XmlMappingException, IOException {
try {
XmlObject object = XmlObject.Factory.parse(reader, xmlOptions);
XmlObject object = XmlObject.Factory.parse(reader, getXmlOptions());
validate(object);
return object;
}
@@ -161,9 +161,9 @@ public class XmlBeansMarshaller extends AbstractMarshaller {
}
}
protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)
protected final Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)
throws XmlMappingException, IOException {
XmlSaxHandler saxHandler = XmlObject.Factory.newXmlSaxHandler(xmlOptions);
XmlSaxHandler saxHandler = XmlObject.Factory.newXmlSaxHandler(getXmlOptions());
xmlReader.setContentHandler(saxHandler.getContentHandler());
try {
xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", saxHandler.getLexicalHandler());
@@ -188,7 +188,7 @@ public class XmlBeansMarshaller extends AbstractMarshaller {
}
}
protected Object unmarshalXmlEventReader(XMLEventReader eventReader) throws XmlMappingException {
protected final Object unmarshalXmlEventReader(XMLEventReader eventReader) throws XmlMappingException {
XMLReader reader = new StaxEventXmlReader(eventReader);
try {
return unmarshalSaxReader(reader, new InputSource());
@@ -198,9 +198,9 @@ public class XmlBeansMarshaller extends AbstractMarshaller {
}
}
protected Object unmarshalXmlStreamReader(XMLStreamReader streamReader) throws XmlMappingException {
protected final Object unmarshalXmlStreamReader(XMLStreamReader streamReader) throws XmlMappingException {
try {
XmlObject object = XmlObject.Factory.parse(streamReader, xmlOptions);
XmlObject object = XmlObject.Factory.parse(streamReader, getXmlOptions());
validate(object);
return object;
}
@@ -209,6 +209,25 @@ public class XmlBeansMarshaller extends AbstractMarshaller {
}
}
/**
* Converts the given XMLBeans exception to an appropriate exception from the <code>org.springframework.oxm</code>
* hierarchy.
* <p/>
* The default implementation delegates to <code>XmlBeansUtils</code>. Can be overridden in subclasses.
* <p/>
* A boolean flag is used to indicate whether this exception occurs during marshalling or unmarshalling, since
* XMLBeans itself does not make this distinction in its exception hierarchy.
*
* @param ex XMLBeans Exception that occured
* @param marshalling indicates whether the exception occurs during marshalling (<code>true</code>), or
* unmarshalling (<code>false</code>)
* @return the corresponding <code>XmlMappingException</code>
* @see XmlBeansUtils#convertXmlBeansException(Exception,boolean)
*/
public XmlMappingException convertXmlBeansException(Exception ex, boolean marshalling) {
return XmlBeansUtils.convertXmlBeansException(ex, marshalling);
}
/**
* Validates the given <code>XmlObject</code>.
*
@@ -219,7 +238,7 @@ public class XmlBeansMarshaller extends AbstractMarshaller {
public void validate(XmlObject object) throws XmlBeansValidationFailureException {
if (isValidating() && object != null) {
// create a temporary xmlOptions just for validation
XmlOptions validateOptions = xmlOptions != null ? xmlOptions : new XmlOptions();
XmlOptions validateOptions = getXmlOptions() != null ? getXmlOptions() : new XmlOptions();
List errorsList = new ArrayList();
validateOptions.setErrorListener(errorsList);
if (!object.validate(validateOptions)) {

View File

@@ -505,11 +505,12 @@
<artifactId>xpp3</artifactId>
<version>1.1.3.4.O</version>
</dependency>
<!-- O/X Mapping dependencies --><!-- Castor -->
<!-- O/X Mapping dependencies -->
<!-- Castor -->
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor</artifactId>
<version>1.0.5</version>
<version>1.1.1</version>
</dependency>
<!-- XMLBeans -->
<dependency>

View File

@@ -6,13 +6,20 @@
</properties>
<body>
<release version="1.0-rc2">
<action dev="poutsma" type="add" issue="SWS-133">Added ignoreExtraAttributes and ignoreExtraElements
properties to CastorMarshaller
</action>
<action dev="poutsma" type="add" issue="SWS-129">Moved SimpleMethodEndpointMapping from sandbox</action>
<action dev="poutsma" type="add">Moved PayloadMethodEndpointAdapter and MessageMethodEndpointAdapter from sandbox</action>
<action dev="poutsma" type="add" issue="SWS-123">CommonsHttpMessageSender should expose setters for username and password</action>
<action dev="poutsma" type="add"
issue="SWS-122">A MessageSender setter on WebServicesGatewaySupport</action>
<action dev="poutsma" type="fix"
issue="SWS-128">A SOAP:Fault does not set the the response code to 500</action>
<action dev="poutsma" type="add">Moved PayloadMethodEndpointAdapter and MessageMethodEndpointAdapter from
sandbox
</action>
<action dev="poutsma" type="add" issue="SWS-123">CommonsHttpMessageSender should expose setters for username
and password
</action>
<action dev="poutsma" type="add" issue="SWS-122">A MessageSender setter on WebServicesGatewaySupport
</action>
<action dev="poutsma" type="fix" issue="SWS-128">A SOAP:Fault does not set the the response code to 500
</action>
</release>
<release version="1.0-rc1" date="2007-05-21">
<action dev="poutsma" type="add" issue="SWS-98">Changing URL in CommonsHttpMessageSender</action>

View File

@@ -7,13 +7,14 @@
</skin>
<publishDate position="left" format="yyyy-MM-dd"/>
<bannerLeft>
<name>Spring Web Services</name>
<src>images/spring-ws.png</src>
<href>http://www.springframework.org/spring-ws</href>
</bannerLeft>
<body>
<links>
<item name="Spring Framework" href="http://www.springframework.org/"/>
<item name="Spring Web Services" href="http://www.springframework.org/spring-ws/"/>
<item name="Spring Framework" href="http://www.springframework.org"/>
<item name="Spring Web Services" href="http://www.springframework.org/spring-ws"/>
</links>
<menu name="Overview">
<item name="Home" href="index.html"/>