|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2012 the original author or authors. |
|
|
|
* Copyright 2002-2013 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -30,16 +30,20 @@ import javax.xml.stream.XMLStreamWriter; |
|
|
|
|
|
|
|
|
|
|
|
import org.exolab.castor.mapping.Mapping; |
|
|
|
import org.exolab.castor.mapping.Mapping; |
|
|
|
import org.exolab.castor.mapping.MappingException; |
|
|
|
import org.exolab.castor.mapping.MappingException; |
|
|
|
|
|
|
|
import org.exolab.castor.util.ObjectFactory; |
|
|
|
|
|
|
|
import org.exolab.castor.xml.IDResolver; |
|
|
|
import org.exolab.castor.xml.MarshalException; |
|
|
|
import org.exolab.castor.xml.MarshalException; |
|
|
|
import org.exolab.castor.xml.Marshaller; |
|
|
|
import org.exolab.castor.xml.Marshaller; |
|
|
|
import org.exolab.castor.xml.ResolverException; |
|
|
|
import org.exolab.castor.xml.ResolverException; |
|
|
|
import org.exolab.castor.xml.UnmarshalHandler; |
|
|
|
import org.exolab.castor.xml.UnmarshalHandler; |
|
|
|
import org.exolab.castor.xml.Unmarshaller; |
|
|
|
import org.exolab.castor.xml.Unmarshaller; |
|
|
|
import org.exolab.castor.xml.ValidationException; |
|
|
|
import org.exolab.castor.xml.ValidationException; |
|
|
|
|
|
|
|
import org.exolab.castor.xml.XMLClassDescriptorResolver; |
|
|
|
import org.exolab.castor.xml.XMLContext; |
|
|
|
import org.exolab.castor.xml.XMLContext; |
|
|
|
import org.exolab.castor.xml.XMLException; |
|
|
|
import org.exolab.castor.xml.XMLException; |
|
|
|
import org.w3c.dom.Node; |
|
|
|
import org.w3c.dom.Node; |
|
|
|
import org.xml.sax.ContentHandler; |
|
|
|
import org.xml.sax.ContentHandler; |
|
|
|
|
|
|
|
import org.xml.sax.EntityResolver; |
|
|
|
import org.xml.sax.InputSource; |
|
|
|
import org.xml.sax.InputSource; |
|
|
|
import org.xml.sax.SAXException; |
|
|
|
import org.xml.sax.SAXException; |
|
|
|
import org.xml.sax.XMLReader; |
|
|
|
import org.xml.sax.XMLReader; |
|
|
|
@ -56,30 +60,30 @@ import org.springframework.oxm.XmlMappingException; |
|
|
|
import org.springframework.oxm.support.AbstractMarshaller; |
|
|
|
import org.springframework.oxm.support.AbstractMarshaller; |
|
|
|
import org.springframework.oxm.support.SaxResourceUtils; |
|
|
|
import org.springframework.oxm.support.SaxResourceUtils; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
import org.springframework.util.xml.DomUtils; |
|
|
|
import org.springframework.util.xml.DomUtils; |
|
|
|
import org.springframework.util.xml.StaxUtils; |
|
|
|
import org.springframework.util.xml.StaxUtils; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Implementation of the {@code Marshaller} interface for Castor. By default, Castor does not require any further |
|
|
|
* Implementation of the {@code Marshaller} interface for Castor. By default, Castor does |
|
|
|
* configuration, though setting target classes, target packages or providing a mapping file can be used to have more |
|
|
|
* not require any further configuration, though setting target classes, target packages or |
|
|
|
* control over the behavior of Castor. |
|
|
|
* providing a mapping file can be used to have more control over the behavior of Castor. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>If a target class is specified using {@code setTargetClass}, the {@code CastorMarshaller} can only be |
|
|
|
* <p>If a target class is specified using {@code setTargetClass}, the {@code CastorMarshaller} |
|
|
|
* used to unmarshal XML that represents that specific class. If you want to unmarshal multiple classes, you have to |
|
|
|
* can only be used to unmarshal XML that represents that specific class. If you want to unmarshal |
|
|
|
* provide a mapping file using {@code setMappingLocations}. |
|
|
|
* multiple classes, you have to provide a mapping file using {@code setMappingLocations}. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>Due to limitations of Castor's API, it is required to set the encoding used for writing to output streams. It |
|
|
|
* <p>Due to limitations of Castor's API, it is required to set the encoding used for |
|
|
|
* defaults to {@code UTF-8}. |
|
|
|
* writing to output streams. It defaults to {@code UTF-8}. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Jakub Narloch |
|
|
|
* @author Jakub Narloch |
|
|
|
|
|
|
|
* @author Juergen Hoeller |
|
|
|
|
|
|
|
* @since 3.0 |
|
|
|
* @see #setEncoding(String) |
|
|
|
* @see #setEncoding(String) |
|
|
|
* @see #setTargetClass(Class) |
|
|
|
* @see #setTargetClass(Class) |
|
|
|
* @see #setTargetPackages(String[]) |
|
|
|
* @see #setTargetPackages(String[]) |
|
|
|
* @see #setMappingLocation(Resource) |
|
|
|
* @see #setMappingLocation(Resource) |
|
|
|
* @see #setMappingLocations(Resource[]) |
|
|
|
* @see #setMappingLocations(Resource[]) |
|
|
|
* @since 3.0 |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class CastorMarshaller extends AbstractMarshaller implements InitializingBean, BeanClassLoaderAware { |
|
|
|
public class CastorMarshaller extends AbstractMarshaller implements InitializingBean, BeanClassLoaderAware { |
|
|
|
|
|
|
|
|
|
|
|
@ -88,6 +92,7 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static final String DEFAULT_ENCODING = "UTF-8"; |
|
|
|
public static final String DEFAULT_ENCODING = "UTF-8"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Resource[] mappingLocations; |
|
|
|
private Resource[] mappingLocations; |
|
|
|
|
|
|
|
|
|
|
|
private String encoding = DEFAULT_ENCODING; |
|
|
|
private String encoding = DEFAULT_ENCODING; |
|
|
|
@ -98,47 +103,59 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing |
|
|
|
|
|
|
|
|
|
|
|
private boolean validating = false; |
|
|
|
private boolean validating = false; |
|
|
|
|
|
|
|
|
|
|
|
private boolean whitespacePreserve = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean ignoreExtraAttributes = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean ignoreExtraElements = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, String> namespaceMappings; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private XMLContext xmlContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean suppressNamespaces = false; |
|
|
|
private boolean suppressNamespaces = false; |
|
|
|
|
|
|
|
|
|
|
|
private boolean suppressXsiType = false; |
|
|
|
private boolean suppressXsiType = false; |
|
|
|
|
|
|
|
|
|
|
|
private boolean marshalAsDocument = true; |
|
|
|
private boolean marshalAsDocument = true; |
|
|
|
|
|
|
|
|
|
|
|
private String rootElement; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean marshalExtendedType = true; |
|
|
|
private boolean marshalExtendedType = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String rootElement; |
|
|
|
|
|
|
|
|
|
|
|
private String noNamespaceSchemaLocation; |
|
|
|
private String noNamespaceSchemaLocation; |
|
|
|
|
|
|
|
|
|
|
|
private String schemaLocation; |
|
|
|
private String schemaLocation; |
|
|
|
|
|
|
|
|
|
|
|
private boolean useXSITypeAtRoot = false; |
|
|
|
private boolean useXSITypeAtRoot = false; |
|
|
|
|
|
|
|
|
|
|
|
private Map<String, String> processingInstructions; |
|
|
|
private boolean whitespacePreserve = false; |
|
|
|
|
|
|
|
|
|
|
|
private Map<String, String> namespaceToPackageMapping; |
|
|
|
private boolean ignoreExtraAttributes = true; |
|
|
|
|
|
|
|
|
|
|
|
private ClassLoader classLoader; |
|
|
|
private boolean ignoreExtraElements = false; |
|
|
|
|
|
|
|
|
|
|
|
private Object root; |
|
|
|
private Object rootObject; |
|
|
|
|
|
|
|
|
|
|
|
private boolean reuseObjects = false; |
|
|
|
private boolean reuseObjects = false; |
|
|
|
|
|
|
|
|
|
|
|
private boolean clearCollections = false; |
|
|
|
private boolean clearCollections = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, String> castorProperties; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, String> doctypes; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, String> processingInstructions; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, String> namespaceMappings; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, String> namespaceToPackageMapping; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private EntityResolver entityResolver; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private XMLClassDescriptorResolver classDescriptorResolver; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IDResolver idResolver; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ObjectFactory objectFactory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ClassLoader beanClassLoader; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private XMLContext xmlContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the encoding to be used for stream access. |
|
|
|
* Set the encoding to be used for stream access. |
|
|
|
* |
|
|
|
|
|
|
|
* @see #DEFAULT_ENCODING |
|
|
|
* @see #DEFAULT_ENCODING |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setEncoding(String encoding) { |
|
|
|
public void setEncoding(String encoding) { |
|
|
|
@ -146,7 +163,7 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the locations of the Castor XML Mapping files. |
|
|
|
* Set the locations of the Castor XML mapping files. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setMappingLocation(Resource mappingLocation) { |
|
|
|
public void setMappingLocation(Resource mappingLocation) { |
|
|
|
this.mappingLocations = new Resource[]{mappingLocation}; |
|
|
|
this.mappingLocations = new Resource[]{mappingLocation}; |
|
|
|
@ -190,8 +207,8 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set whether this marshaller should validate in- and outgoing documents. <p>Default is {@code false}. |
|
|
|
* Set whether this marshaller should validate in- and outgoing documents. |
|
|
|
* |
|
|
|
* <p>Default is {@code false}. |
|
|
|
* @see Marshaller#setValidation(boolean) |
|
|
|
* @see Marshaller#setValidation(boolean) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setValidating(boolean validating) { |
|
|
|
public void setValidating(boolean validating) { |
|
|
|
@ -199,152 +216,180 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set whether the Castor {@link Unmarshaller} should preserve "ignorable" whitespace. <p>Default is |
|
|
|
* Sets whether this marshaller should output namespaces. |
|
|
|
* {@code false}. |
|
|
|
* <p>The default is {@code false}, i.e. namespaces are written. |
|
|
|
* |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setSuppressNamespaces(boolean) |
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setWhitespacePreserve(boolean) |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setWhitespacePreserve(boolean whitespacePreserve) { |
|
|
|
public void setSuppressNamespaces(boolean suppressNamespaces) { |
|
|
|
this.whitespacePreserve = whitespacePreserve; |
|
|
|
this.suppressNamespaces = suppressNamespaces; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set whether the Castor {@link Unmarshaller} should ignore attributes that do not match a specific field. <p>Default |
|
|
|
* Set whether this marshaller should output the {@code xsi:type} attribute. |
|
|
|
* is {@code true}: extra attributes are ignored. |
|
|
|
* <p>The default is {@code false}, i.e. the {@code xsi:type} is written. |
|
|
|
* |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setSuppressXSIType(boolean) |
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setIgnoreExtraAttributes(boolean) |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setIgnoreExtraAttributes(boolean ignoreExtraAttributes) { |
|
|
|
public void setSuppressXsiType(boolean suppressXsiType) { |
|
|
|
this.ignoreExtraAttributes = ignoreExtraAttributes; |
|
|
|
this.suppressXsiType = suppressXsiType; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set whether the Castor {@link Unmarshaller} should ignore elements that do not match a specific field. <p>Default |
|
|
|
* Set whether this marshaller should output the xml declaration. |
|
|
|
* is |
|
|
|
* <p>The default is {@code true}, the XML declaration will be written. |
|
|
|
* {@code false}, extra attributes are flagged as an error. |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setMarshalAsDocument(boolean) |
|
|
|
* |
|
|
|
|
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setIgnoreExtraElements(boolean) |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setIgnoreExtraElements(boolean ignoreExtraElements) { |
|
|
|
public void setMarshalAsDocument(boolean marshalAsDocument) { |
|
|
|
this.ignoreExtraElements = ignoreExtraElements; |
|
|
|
this.marshalAsDocument = marshalAsDocument; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the namespace mappings. Property names are interpreted as namespace prefixes; values are namespace URIs. |
|
|
|
* Set whether this marshaller should output for given type the {@code xsi:type} attribute. |
|
|
|
* |
|
|
|
* <p>The default is {@code true}, the {@code xsi:type} attribute will be written. |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setNamespaceMapping(String, String) |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setMarshalExtendedType(boolean) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setNamespaceMappings(Map<String, String> namespaceMappings) { |
|
|
|
public void setMarshalExtendedType(boolean marshalExtendedType) { |
|
|
|
this.namespaceMappings = namespaceMappings; |
|
|
|
this.marshalExtendedType = marshalExtendedType; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns whether this marshaller should output namespaces. |
|
|
|
* Set the name of the root element. |
|
|
|
|
|
|
|
* @see org.exolab.castor.xml.Marshaller#setRootElement(String) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean isSuppressNamespaces() { |
|
|
|
public void setRootElement(String rootElement) { |
|
|
|
return suppressNamespaces; |
|
|
|
this.rootElement = rootElement; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets whether this marshaller should output namespaces. The default is {@code false}, i.e. namespaces are written. |
|
|
|
* Set the value of {@code xsi:noNamespaceSchemaLocation} attribute. When set, the |
|
|
|
* |
|
|
|
* {@code xsi:noNamespaceSchemaLocation} attribute will be written for the root element. |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setSuppressNamespaces(boolean) |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setNoNamespaceSchemaLocation(String) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setSuppressNamespaces(boolean suppressNamespaces) { |
|
|
|
public void setNoNamespaceSchemaLocation(String noNamespaceSchemaLocation) { |
|
|
|
this.suppressNamespaces = suppressNamespaces; |
|
|
|
this.noNamespaceSchemaLocation = noNamespaceSchemaLocation; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets whether this marshaller should output the xsi:type attribute. |
|
|
|
* Set the value of {@code xsi:schemaLocation} attribute. When set, the |
|
|
|
|
|
|
|
* {@code xsi:schemaLocation} attribute will be written for the root element. |
|
|
|
|
|
|
|
* @see org.exolab.castor.xml.Marshaller#setSchemaLocation(String) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean isSuppressXsiType() { |
|
|
|
public void setSchemaLocation(String schemaLocation) { |
|
|
|
return suppressXsiType; |
|
|
|
this.schemaLocation = schemaLocation; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets whether this marshaller should output the {@code xsi:type} attribute. The default is {@code false}, i.e. the |
|
|
|
* Sets whether this marshaller should output the {@code xsi:type} attribute for the root element. |
|
|
|
* {@code xsi:type} is written. |
|
|
|
* This can be useful when the type of the element can not be simply determined from the element name. |
|
|
|
* |
|
|
|
* <p>The default is {@code false}: The {@code xsi:type} attribute for the root element won't be written. |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setSuppressXSIType(boolean) |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setUseXSITypeAtRoot(boolean) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setSuppressXsiType(boolean suppressXsiType) { |
|
|
|
public void setUseXSITypeAtRoot(boolean useXSITypeAtRoot) { |
|
|
|
this.suppressXsiType = suppressXsiType; |
|
|
|
this.useXSITypeAtRoot = useXSITypeAtRoot; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets whether this marshaller should output the xml declaration. </p> The default is {@code true}, the xml |
|
|
|
* Set whether the Castor {@link Unmarshaller} should preserve "ignorable" whitespace. |
|
|
|
* declaration will be written. |
|
|
|
* <p>Default is {@code false}. |
|
|
|
* |
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setWhitespacePreserve(boolean) |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setMarshalAsDocument(boolean) |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setMarshalAsDocument(boolean marshalAsDocument) { |
|
|
|
public void setWhitespacePreserve(boolean whitespacePreserve) { |
|
|
|
this.marshalAsDocument = marshalAsDocument; |
|
|
|
this.whitespacePreserve = whitespacePreserve; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets the name of the root element. |
|
|
|
* Set whether the Castor {@link Unmarshaller} should ignore attributes that do not match a specific field. |
|
|
|
* |
|
|
|
* <p>Default is {@code true}: Extra attributes are ignored. |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setRootElement(String) |
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setIgnoreExtraAttributes(boolean) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setRootElement(String rootElement) { |
|
|
|
public void setIgnoreExtraAttributes(boolean ignoreExtraAttributes) { |
|
|
|
this.rootElement = rootElement; |
|
|
|
this.ignoreExtraAttributes = ignoreExtraAttributes; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets whether this marshaller should output for given type the {@code xsi:type} attribute.</p> The default is {@code |
|
|
|
* Set whether the Castor {@link Unmarshaller} should ignore elements that do not match a specific field. |
|
|
|
* true}, the {@code xsi:type} attribute will be written. |
|
|
|
* <p>Default is {@code false}: Extra elements are flagged as an error. |
|
|
|
* |
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setIgnoreExtraElements(boolean) |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setMarshalExtendedType(boolean) |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setMarshalExtendedType(boolean marshalExtendedType) { |
|
|
|
public void setIgnoreExtraElements(boolean ignoreExtraElements) { |
|
|
|
this.marshalExtendedType = marshalExtendedType; |
|
|
|
this.ignoreExtraElements = ignoreExtraElements; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets the value of {@code xsi:noNamespaceSchemaLocation} attribute. When set, the {@code |
|
|
|
* Set the expected root object for the unmarshaller, into which the source will be unmarshalled. |
|
|
|
* xsi:noNamespaceSchemaLocation} attribute will be written for the root element. |
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setObject(Object) |
|
|
|
* |
|
|
|
* @deprecated in favor of {@link #setRootObject} |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setNoNamespaceSchemaLocation(String) |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setNoNamespaceSchemaLocation(String noNamespaceSchemaLocation) { |
|
|
|
@Deprecated |
|
|
|
this.noNamespaceSchemaLocation = noNamespaceSchemaLocation; |
|
|
|
public void setObject(Object root) { |
|
|
|
|
|
|
|
this.rootObject = root; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets the value of {@code xsi:schemaLocation} attribute.When set, the {@code xsi:schemaLocation} attribute will be |
|
|
|
* Set the expected root object for the unmarshaller, into which the source will be unmarshalled. |
|
|
|
* written for the root element. |
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setObject(Object) |
|
|
|
* |
|
|
|
|
|
|
|
* @see org.exolab.castor.xml.Marshaller#setSchemaLocation(String) |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setSchemaLocation(String schemaLocation) { |
|
|
|
public void setRootObject(Object root) { |
|
|
|
this.schemaLocation = schemaLocation; |
|
|
|
this.rootObject = root; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets whether this marshaller should output the {@code xsi:type} attribute for the root element. This can be useful |
|
|
|
* Set whether this unmarshaller should re-use objects. |
|
|
|
* when the type of the element can not be simply determined from the element name. </p> The default is {@code false}, |
|
|
|
* This will be only used when unmarshalling to an existing object. |
|
|
|
* the {@code xsi:type} attribute for the root element won't be written. |
|
|
|
* <p>The default is {@code false}, which means that the objects won't be re-used. |
|
|
|
* |
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setReuseObjects(boolean) |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setUseXSITypeAtRoot(boolean) |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setUseXSITypeAtRoot(boolean useXSITypeAtRoot) { |
|
|
|
public void setReuseObjects(boolean reuseObjects) { |
|
|
|
this.useXSITypeAtRoot = useXSITypeAtRoot; |
|
|
|
this.reuseObjects = reuseObjects; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets the processing instructions that will be used by during marshalling. Keys are the processing targets and |
|
|
|
* Sets whether this unmarshaller should clear collections upon the first use. |
|
|
|
* values |
|
|
|
* <p>The default is {@code false} which means that marshaller won't clear collections. |
|
|
|
* contain the processing data. |
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setClearCollections(boolean) |
|
|
|
* |
|
|
|
*/ |
|
|
|
|
|
|
|
public void setClearCollections(boolean clearCollections) { |
|
|
|
|
|
|
|
this.clearCollections = clearCollections; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Set Castor-specific properties for marshalling and unmarshalling. |
|
|
|
|
|
|
|
* Each entry key is considered the property name and each value the property value. |
|
|
|
|
|
|
|
* @see org.exolab.castor.xml.Marshaller#setProperty(String, String) |
|
|
|
|
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setProperty(String, String) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void setCastorProperties(Map<String, String> castorProperties) { |
|
|
|
|
|
|
|
this.castorProperties = castorProperties; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Set the map containing document type definition for the marshaller. |
|
|
|
|
|
|
|
* Each entry has system id as key and public id as value. |
|
|
|
|
|
|
|
* @see org.exolab.castor.xml.Marshaller#setDoctype(String, String) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void setDoctypes(Map<String, String> doctypes) { |
|
|
|
|
|
|
|
this.doctypes = doctypes; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Sets the processing instructions that will be used by during marshalling. |
|
|
|
|
|
|
|
* Keys are the processing targets and values contain the processing data. |
|
|
|
* @see org.exolab.castor.xml.Marshaller#addProcessingInstruction(String, String) |
|
|
|
* @see org.exolab.castor.xml.Marshaller#addProcessingInstruction(String, String) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setProcessingInstructions(Map<String, String> processingInstructions) { |
|
|
|
public void setProcessingInstructions(Map<String, String> processingInstructions) { |
|
|
|
this.processingInstructions = processingInstructions; |
|
|
|
this.processingInstructions = processingInstructions; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Set 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(Map<String, String> namespaceMappings) { |
|
|
|
|
|
|
|
this.namespaceMappings = namespaceMappings; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the namespace to package mappings. Property names are represents the namespaces URI, values are packages. |
|
|
|
* Set the namespace to package mappings. Property names are represents the namespaces URI, values are packages. |
|
|
|
* |
|
|
|
|
|
|
|
* @see org.exolab.castor.xml.Marshaller#setNamespaceMapping(String, String) |
|
|
|
* @see org.exolab.castor.xml.Marshaller#setNamespaceMapping(String, String) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setNamespaceToPackageMapping(Map<String, String> namespaceToPackageMapping) { |
|
|
|
public void setNamespaceToPackageMapping(Map<String, String> namespaceToPackageMapping) { |
|
|
|
@ -352,58 +397,45 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets the expected object for the unmarshaller, into which the source will be unmarshalled. |
|
|
|
* Set the {@link EntityResolver} to be used during unmarshalling. |
|
|
|
* |
|
|
|
* This resolver will used to resolve system and public ids. |
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setObject(Object) |
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setEntityResolver(EntityResolver) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setObject(Object root) { |
|
|
|
public void setEntityResolver(EntityResolver entityResolver) { |
|
|
|
this.root = root; |
|
|
|
this.entityResolver = entityResolver; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets whether this unmarshaller should re-use objects. This will be only used when unmarshalling to existing |
|
|
|
* Set the {@link XMLClassDescriptorResolver} to be used during unmarshalling. |
|
|
|
* object. </p> The default is {@code false}, which means that the objects won't be re-used. |
|
|
|
* This resolver will used to resolve class descriptors. |
|
|
|
* |
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setResolver(XMLClassDescriptorResolver) |
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setReuseObjects(boolean) |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setReuseObjects(boolean reuseObjects) { |
|
|
|
public void setClassDescriptorResolver(XMLClassDescriptorResolver classDescriptorResolver) { |
|
|
|
this.reuseObjects = reuseObjects; |
|
|
|
this.classDescriptorResolver = classDescriptorResolver; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets whether this unmarshaller should clear collections upon the first use. </p> The default is {@code false}, |
|
|
|
* Set the Castor {@link IDResolver} to be used during unmarshalling. |
|
|
|
* which means that marshaller won't clear collections. |
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setIDResolver(IDResolver) |
|
|
|
* |
|
|
|
|
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setClearCollections(boolean) |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setClearCollections(boolean clearCollections) { |
|
|
|
public void setIdResolver(IDResolver idResolver) { |
|
|
|
this.clearCollections = clearCollections; |
|
|
|
this.idResolver = idResolver; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Set the Castor {@link ObjectFactory} to be used during unmarshalling. |
|
|
|
|
|
|
|
* @see org.exolab.castor.xml.Unmarshaller#setObjectFactory(ObjectFactory) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void setObjectFactory(ObjectFactory objectFactory) { |
|
|
|
|
|
|
|
this.objectFactory = objectFactory; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setBeanClassLoader(ClassLoader classLoader) { |
|
|
|
public void setBeanClassLoader(ClassLoader classLoader) { |
|
|
|
this.classLoader = classLoader; |
|
|
|
this.beanClassLoader = classLoader; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public final void afterPropertiesSet() throws CastorMappingException, IOException { |
|
|
|
|
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
public void afterPropertiesSet() throws CastorMappingException, IOException { |
|
|
|
if (!ObjectUtils.isEmpty(this.mappingLocations)) { |
|
|
|
|
|
|
|
logger.info( |
|
|
|
|
|
|
|
"Configured using [" + StringUtils.arrayToCommaDelimitedString(this.mappingLocations) + "]"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!ObjectUtils.isEmpty(this.targetClasses)) { |
|
|
|
|
|
|
|
logger.info("Configured for target classes " + StringUtils.arrayToCommaDelimitedString(targetClasses) + |
|
|
|
|
|
|
|
"]"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!ObjectUtils.isEmpty(this.targetPackages)) { |
|
|
|
|
|
|
|
logger.info( |
|
|
|
|
|
|
|
"Configured for target packages [" + StringUtils.arrayToCommaDelimitedString(targetPackages) + |
|
|
|
|
|
|
|
"]"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (ObjectUtils.isEmpty(this.mappingLocations) && ObjectUtils.isEmpty(this.targetClasses) && |
|
|
|
|
|
|
|
ObjectUtils.isEmpty(this.targetPackages)) { |
|
|
|
|
|
|
|
logger.info("Using default configuration"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
this.xmlContext = createXMLContext(this.mappingLocations, this.targetClasses, this.targetPackages); |
|
|
|
this.xmlContext = createXMLContext(this.mappingLocations, this.targetClasses, this.targetPackages); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -416,9 +448,8 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create the Castor {@code XMLContext}. Subclasses can override this to create a custom context. <p> The default |
|
|
|
* Create the Castor {@code XMLContext}. Subclasses can override this to create a custom context. |
|
|
|
* implementation loads mapping files if defined, or the target class or packages if defined. |
|
|
|
* <p>The default implementation loads mapping files if defined, or the target class or packages if defined. |
|
|
|
* |
|
|
|
|
|
|
|
* @return the created resolver |
|
|
|
* @return the created resolver |
|
|
|
* @throws MappingException when the mapping file cannot be loaded |
|
|
|
* @throws MappingException when the mapping file cannot be loaded |
|
|
|
* @throws IOException in case of I/O errors |
|
|
|
* @throws IOException in case of I/O errors |
|
|
|
@ -442,9 +473,15 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing |
|
|
|
if (!ObjectUtils.isEmpty(targetPackages)) { |
|
|
|
if (!ObjectUtils.isEmpty(targetPackages)) { |
|
|
|
context.addPackages(targetPackages); |
|
|
|
context.addPackages(targetPackages); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (this.castorProperties != null) { |
|
|
|
|
|
|
|
for (Map.Entry<String, String> property : this.castorProperties.entrySet()) { |
|
|
|
|
|
|
|
context.setProperty(property.getKey(), property.getValue()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return context; |
|
|
|
return context; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns {@code true} for all classes, i.e. Castor supports arbitrary classes. |
|
|
|
* Returns {@code true} for all classes, i.e. Castor supports arbitrary classes. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -462,6 +499,7 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected final void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler) |
|
|
|
protected final void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler) |
|
|
|
throws XmlMappingException { |
|
|
|
throws XmlMappingException { |
|
|
|
|
|
|
|
|
|
|
|
Marshaller marshaller = xmlContext.createMarshaller(); |
|
|
|
Marshaller marshaller = xmlContext.createMarshaller(); |
|
|
|
marshaller.setContentHandler(contentHandler); |
|
|
|
marshaller.setContentHandler(contentHandler); |
|
|
|
marshal(graph, marshaller); |
|
|
|
marshal(graph, marshaller); |
|
|
|
@ -470,6 +508,7 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected final void marshalOutputStream(Object graph, OutputStream outputStream) |
|
|
|
protected final void marshalOutputStream(Object graph, OutputStream outputStream) |
|
|
|
throws XmlMappingException, IOException { |
|
|
|
throws XmlMappingException, IOException { |
|
|
|
|
|
|
|
|
|
|
|
marshalWriter(graph, new OutputStreamWriter(outputStream, encoding)); |
|
|
|
marshalWriter(graph, new OutputStreamWriter(outputStream, encoding)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -502,42 +541,29 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Template method that allows for customizing of the given Castor {@link Marshaller}. |
|
|
|
* Template method that allows for customizing of the given Castor {@link Marshaller}. |
|
|
|
* |
|
|
|
|
|
|
|
* </p>The default implementation invokes |
|
|
|
|
|
|
|
* <ol> |
|
|
|
|
|
|
|
* <li>{@link Marshaller#setValidation(boolean)},</li> |
|
|
|
|
|
|
|
* <li>{@link Marshaller#setSuppressNamespaces(boolean)},</li> |
|
|
|
|
|
|
|
* <li>{@link Marshaller#setSuppressXSIType(boolean)}, </li> |
|
|
|
|
|
|
|
* <li>{@link Marshaller#setMarshalAsDocument(boolean)}, </li> |
|
|
|
|
|
|
|
* <li>{@link Marshaller#setRootElement(String)},</li> |
|
|
|
|
|
|
|
* <li>{@link Marshaller#setMarshalExtendedType(boolean)},</li> |
|
|
|
|
|
|
|
* <li>{@link Marshaller#setNoNamespaceSchemaLocation(String)},</li> |
|
|
|
|
|
|
|
* <li>{@link Marshaller#setSchemaLocation(String)} and</li> |
|
|
|
|
|
|
|
* <li>{@link Marshaller#setUseXSITypeAtRoot(boolean)}.</li> |
|
|
|
|
|
|
|
* </ol> |
|
|
|
|
|
|
|
* with the property set on this marshaller. |
|
|
|
|
|
|
|
* It also calls {@link Marshaller#setNamespaceMapping(String, String)} |
|
|
|
|
|
|
|
* with the {@linkplain #setNamespaceMappings(java.util.Map) namespace mappings} and |
|
|
|
|
|
|
|
* {@link Marshaller#addProcessingInstruction(String, String)} with the |
|
|
|
|
|
|
|
* {@linkplain #setProcessingInstructions(java.util.Map) processing instructions}. |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void customizeMarshaller(Marshaller marshaller) { |
|
|
|
protected void customizeMarshaller(Marshaller marshaller) { |
|
|
|
marshaller.setValidation(this.validating); |
|
|
|
marshaller.setValidation(this.validating); |
|
|
|
marshaller.setSuppressNamespaces(isSuppressNamespaces()); |
|
|
|
marshaller.setSuppressNamespaces(this.suppressNamespaces); |
|
|
|
marshaller.setSuppressXSIType(isSuppressXsiType()); |
|
|
|
marshaller.setSuppressXSIType(this.suppressXsiType); |
|
|
|
marshaller.setMarshalAsDocument(marshalAsDocument); |
|
|
|
marshaller.setMarshalAsDocument(this.marshalAsDocument); |
|
|
|
marshaller.setRootElement(rootElement); |
|
|
|
marshaller.setMarshalExtendedType(this.marshalExtendedType); |
|
|
|
marshaller.setMarshalExtendedType(marshalExtendedType); |
|
|
|
marshaller.setRootElement(this.rootElement); |
|
|
|
marshaller.setNoNamespaceSchemaLocation(noNamespaceSchemaLocation); |
|
|
|
marshaller.setNoNamespaceSchemaLocation(this.noNamespaceSchemaLocation); |
|
|
|
marshaller.setSchemaLocation(schemaLocation); |
|
|
|
marshaller.setSchemaLocation(this.schemaLocation); |
|
|
|
marshaller.setUseXSITypeAtRoot(useXSITypeAtRoot); |
|
|
|
marshaller.setUseXSITypeAtRoot(this.useXSITypeAtRoot); |
|
|
|
if (processingInstructions != null) { |
|
|
|
if (this.doctypes != null) { |
|
|
|
for (Map.Entry<String, String> processingInstruction : processingInstructions.entrySet()) { |
|
|
|
for (Map.Entry<String, String> doctype : this.doctypes.entrySet()) { |
|
|
|
|
|
|
|
marshaller.setDoctype(doctype.getKey(), doctype.getValue()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.processingInstructions != null) { |
|
|
|
|
|
|
|
for (Map.Entry<String, String> processingInstruction : this.processingInstructions.entrySet()) { |
|
|
|
marshaller.addProcessingInstruction(processingInstruction.getKey(), processingInstruction.getValue()); |
|
|
|
marshaller.addProcessingInstruction(processingInstruction.getKey(), processingInstruction.getValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.namespaceMappings != null) { |
|
|
|
if (this.namespaceMappings != null) { |
|
|
|
for (Map.Entry<String, String> entry : namespaceMappings.entrySet()) { |
|
|
|
for (Map.Entry<String, String> entry : this.namespaceMappings.entrySet()) { |
|
|
|
marshaller.setNamespaceMapping(entry.getKey(), entry.getValue()); |
|
|
|
marshaller.setNamespaceMapping(entry.getKey(), entry.getValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -619,48 +645,45 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Template method that allows for customizing of the given Castor {@link Unmarshaller}. |
|
|
|
* Template method that allows for customizing of the given Castor {@link Unmarshaller}. |
|
|
|
* |
|
|
|
|
|
|
|
* </p> The default implementation invokes |
|
|
|
|
|
|
|
* <ol> |
|
|
|
|
|
|
|
* <li>{@link Unmarshaller#setValidation(boolean)}, |
|
|
|
|
|
|
|
* <li>{@link Unmarshaller#setWhitespacePreserve(boolean)}, |
|
|
|
|
|
|
|
* <li>{@link Unmarshaller#setIgnoreExtraAttributes(boolean)}, |
|
|
|
|
|
|
|
* <li>{@link Unmarshaller#setIgnoreExtraElements(boolean)}, |
|
|
|
|
|
|
|
* <li>{@link Unmarshaller#setClassLoader(ClassLoader)}, |
|
|
|
|
|
|
|
* <li>{@link Unmarshaller#setObject(Object)}, |
|
|
|
|
|
|
|
* <li>{@link Unmarshaller#setReuseObjects(boolean)} and |
|
|
|
|
|
|
|
* <li>{@link Unmarshaller#setClearCollections(boolean)} |
|
|
|
|
|
|
|
* </ol> |
|
|
|
|
|
|
|
* with the properties set on this marshaller. |
|
|
|
|
|
|
|
* It also calls {@link Unmarshaller#addNamespaceToPackageMapping(String, String)} with the |
|
|
|
|
|
|
|
* {@linkplain #setNamespaceMappings(java.util.Map) namespace to package mapping}. |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void customizeUnmarshaller(Unmarshaller unmarshaller) { |
|
|
|
protected void customizeUnmarshaller(Unmarshaller unmarshaller) { |
|
|
|
unmarshaller.setValidation(this.validating); |
|
|
|
unmarshaller.setValidation(this.validating); |
|
|
|
unmarshaller.setWhitespacePreserve(this.whitespacePreserve); |
|
|
|
unmarshaller.setWhitespacePreserve(this.whitespacePreserve); |
|
|
|
unmarshaller.setIgnoreExtraAttributes(this.ignoreExtraAttributes); |
|
|
|
unmarshaller.setIgnoreExtraAttributes(this.ignoreExtraAttributes); |
|
|
|
unmarshaller.setIgnoreExtraElements(this.ignoreExtraElements); |
|
|
|
unmarshaller.setIgnoreExtraElements(this.ignoreExtraElements); |
|
|
|
unmarshaller.setClassLoader(classLoader); |
|
|
|
unmarshaller.setObject(this.rootObject); |
|
|
|
unmarshaller.setObject(root); |
|
|
|
unmarshaller.setReuseObjects(this.reuseObjects); |
|
|
|
unmarshaller.setReuseObjects(reuseObjects); |
|
|
|
unmarshaller.setClearCollections(this.clearCollections); |
|
|
|
unmarshaller.setClearCollections(clearCollections); |
|
|
|
if (this.namespaceToPackageMapping != null) { |
|
|
|
if (namespaceToPackageMapping != null) { |
|
|
|
for (Map.Entry<String, String> mapping : this.namespaceToPackageMapping.entrySet()) { |
|
|
|
for (Map.Entry<String, String> mapping : namespaceToPackageMapping.entrySet()) { |
|
|
|
|
|
|
|
unmarshaller.addNamespaceToPackageMapping(mapping.getKey(), mapping.getValue()); |
|
|
|
unmarshaller.addNamespaceToPackageMapping(mapping.getKey(), mapping.getValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (this.entityResolver != null) { |
|
|
|
|
|
|
|
unmarshaller.setEntityResolver(this.entityResolver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.classDescriptorResolver != null) { |
|
|
|
|
|
|
|
unmarshaller.setResolver(this.classDescriptorResolver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.idResolver != null) { |
|
|
|
|
|
|
|
unmarshaller.setIDResolver(this.idResolver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.objectFactory != null) { |
|
|
|
|
|
|
|
unmarshaller.setObjectFactory(this.objectFactory); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.beanClassLoader != null) { |
|
|
|
|
|
|
|
unmarshaller.setClassLoader(this.beanClassLoader); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Convert the given {@code XMLException} to an appropriate exception from the |
|
|
|
* Convert the given {@code XMLException} to an appropriate exception from the |
|
|
|
* {@code org.springframework.oxm} hierarchy. <p> A boolean flag is used to indicate whether this exception |
|
|
|
* {@code org.springframework.oxm} hierarchy. |
|
|
|
* occurs |
|
|
|
* <p>A boolean flag is used to indicate whether this exception occurs during marshalling or |
|
|
|
* during marshalling or unmarshalling, since Castor itself does not make this distinction in its exception hierarchy. |
|
|
|
* unmarshalling, since Castor itself does not make this distinction in its exception hierarchy. |
|
|
|
* |
|
|
|
|
|
|
|
* @param ex Castor {@code XMLException} that occurred |
|
|
|
* @param ex Castor {@code XMLException} that occurred |
|
|
|
* @param marshalling indicates whether the exception occurs during marshalling ({@code true}), or unmarshalling |
|
|
|
* @param marshalling indicates whether the exception occurs during marshalling ({@code true}), |
|
|
|
* ({@code false}) |
|
|
|
* or unmarshalling ({@code false}) |
|
|
|
* @return the corresponding {@code XmlMappingException} |
|
|
|
* @return the corresponding {@code XmlMappingException} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected XmlMappingException convertCastorException(XMLException ex, boolean marshalling) { |
|
|
|
protected XmlMappingException convertCastorException(XMLException ex, boolean marshalling) { |
|
|
|
|