spring-framework / org.springframework.oxm.castor / CastorMarshaller

CastorMarshaller

open class CastorMarshaller : AbstractMarshaller, InitializingBean, BeanClassLoaderAware

Implementation of the Marshaller interface for Castor. By default, Castor does not require any further configuration, though setting target classes, target packages or providing a mapping file can be used to have more control over the behavior of Castor.

If a target class is specified using setTargetClass, the CastorMarshaller can only be used to unmarshal XML that represents that specific class. If you want to unmarshal multiple classes, you have to provide a mapping file using setMappingLocations.

Due to limitations of Castor's API, it is required to set the encoding used for writing to output streams. It defaults to UTF-8.

Author
Arjen Poutsma

Author
Jakub Narloch

Author
Juergen Hoeller

Since
3.0

See Also
#setEncoding(String)#setTargetClass(Class)#setTargetPackages(String[])#setMappingLocation(Resource)#setMappingLocations(Resource[])

Constructors

<init>

CastorMarshaller()

Implementation of the Marshaller interface for Castor. By default, Castor does not require any further configuration, though setting target classes, target packages or providing a mapping file can be used to have more control over the behavior of Castor.

If a target class is specified using setTargetClass, the CastorMarshaller can only be used to unmarshal XML that represents that specific class. If you want to unmarshal multiple classes, you have to provide a mapping file using setMappingLocations.

Due to limitations of Castor's API, it is required to set the encoding used for writing to output streams. It defaults to UTF-8.

Properties

DEFAULT_ENCODING

static val DEFAULT_ENCODING: String

The default encoding used for stream access: UTF-8.

Functions

afterPropertiesSet

open fun afterPropertiesSet(): Unit

setBeanClassLoader

open fun setBeanClassLoader(classLoader: ClassLoader): Unit

setCastorProperties

open fun setCastorProperties(castorProperties: MutableMap<String, String>): Unit

Set Castor-specific properties for marshalling and unmarshalling. Each entry key is considered the property name and each value the property value.

setClassDescriptorResolver

open fun setClassDescriptorResolver(classDescriptorResolver: XMLClassDescriptorResolver): Unit

Set the XMLClassDescriptorResolver to be used during unmarshalling. This resolver will used to resolve class descriptors.

setClearCollections

open fun setClearCollections(clearCollections: Boolean): Unit

Sets whether this unmarshaller should clear collections upon the first use.

The default is false which means that marshaller won't clear collections.

setDoctypes

open fun setDoctypes(doctypes: MutableMap<String, String>): Unit

Set the map containing document type definition for the marshaller. Each entry has system id as key and public id as value.

setEncoding

open fun setEncoding(encoding: String): Unit

Set the encoding to be used for stream access.

setEntityResolver

open fun setEntityResolver(entityResolver: EntityResolver): Unit

Set the EntityResolver to be used during unmarshalling. This resolver will used to resolve system and public ids.

setIdResolver

open fun setIdResolver(idResolver: IDResolver): Unit

Set the Castor IDResolver to be used during unmarshalling.

setIgnoreExtraAttributes

open fun setIgnoreExtraAttributes(ignoreExtraAttributes: Boolean): Unit

Set whether the Castor Unmarshaller should ignore attributes that do not match a specific field.

Default is true: Extra attributes are ignored.

setIgnoreExtraElements

open fun setIgnoreExtraElements(ignoreExtraElements: Boolean): Unit

Set whether the Castor Unmarshaller should ignore elements that do not match a specific field.

Default is false: Extra elements are flagged as an error.

setMappingLocation

open fun setMappingLocation(mappingLocation: Resource): Unit

Set the locations of the Castor XML mapping files.

setMappingLocations

open fun setMappingLocations(vararg mappingLocations: Resource): Unit

Set the locations of the Castor XML mapping files.

setMarshalAsDocument

open fun setMarshalAsDocument(marshalAsDocument: Boolean): Unit

Set whether this marshaller should output the xml declaration.

The default is true, the XML declaration will be written.

setMarshalExtendedType

open fun setMarshalExtendedType(marshalExtendedType: Boolean): Unit

Set whether this marshaller should output for given type the xsi:type attribute.

The default is true, the xsi:type attribute will be written.

setNamespaceMappings

open fun setNamespaceMappings(namespaceMappings: MutableMap<String, String>): Unit

Set the namespace mappings. Property names are interpreted as namespace prefixes; values are namespace URIs.

setNamespaceToPackageMapping

open fun setNamespaceToPackageMapping(namespaceToPackageMapping: MutableMap<String, String>): Unit

Set the namespace to package mappings. Property names are represents the namespaces URI, values are packages.

setNoNamespaceSchemaLocation

open fun setNoNamespaceSchemaLocation(noNamespaceSchemaLocation: String): Unit

Set the value of xsi:noNamespaceSchemaLocation attribute. When set, the xsi:noNamespaceSchemaLocation attribute will be written for the root element.

setObjectFactory

open fun setObjectFactory(objectFactory: ObjectFactory): Unit

Set the Castor ObjectFactory to be used during unmarshalling.

setProcessingInstructions

open fun setProcessingInstructions(processingInstructions: MutableMap<String, String>): Unit

Sets the processing instructions that will be used by during marshalling. Keys are the processing targets and values contain the processing data.

setReuseObjects

open fun setReuseObjects(reuseObjects: Boolean): Unit

Set whether this unmarshaller should re-use objects. This will be only used when unmarshalling to an existing object.

The default is false, which means that the objects won't be re-used.

setRootElement

open fun setRootElement(rootElement: String): Unit

Set the name of the root element.

setRootObject

open fun setRootObject(root: Any): Unit

Set the expected root object for the unmarshaller, into which the source will be unmarshalled.

setSchemaLocation

open fun setSchemaLocation(schemaLocation: String): Unit

Set the value of xsi:schemaLocation attribute. When set, the xsi:schemaLocation attribute will be written for the root element.

setSuppressNamespaces

open fun setSuppressNamespaces(suppressNamespaces: Boolean): Unit

Sets whether this marshaller should output namespaces.

The default is false, i.e. namespaces are written.

setSuppressXsiType

open fun setSuppressXsiType(suppressXsiType: Boolean): Unit

Set whether this marshaller should output the xsi:type attribute.

The default is false, i.e. the xsi:type is written.

setTargetClass

open fun setTargetClass(targetClass: Class<*>): Unit

Set the Castor target class.

setTargetClasses

open fun setTargetClasses(vararg targetClasses: Class<*>): Unit

Set the Castor target classes.

setTargetPackage

open fun setTargetPackage(targetPackage: String): Unit

Set the name of a package with the Castor descriptor classes.

setTargetPackages

open fun setTargetPackages(vararg targetPackages: String): Unit

Set the names of packages with the Castor descriptor classes.

setUseXSITypeAtRoot

open fun setUseXSITypeAtRoot(useXSITypeAtRoot: Boolean): Unit

Sets whether this marshaller should output the xsi:type attribute for the root element. This can be useful when the type of the element can not be simply determined from the element name.

The default is false: The xsi:type attribute for the root element won't be written.

setValidating

open fun setValidating(validating: Boolean): Unit

Set whether this marshaller should validate in- and outgoing documents.

Default is false.

setWhitespacePreserve

open fun setWhitespacePreserve(whitespacePreserve: Boolean): Unit

Set whether the Castor Unmarshaller should preserve "ignorable" whitespace.

Default is false.

supports

open fun supports(clazz: Class<*>): Boolean

Returns true for all classes, i.e. Castor supports arbitrary classes.

Inherited Functions

isProcessExternalEntities

open fun isProcessExternalEntities(): Boolean

Returns the configured value for whether XML external entities are allowed.

isSupportDtd

open fun isSupportDtd(): Boolean

Whether DTD parsing is supported.

marshal

fun marshal(graph: Any, result: Result): Unit

Marshals the object graph with the given root into the provided javax.xml.transform.Result.

This implementation inspects the given result, and calls marshalDomResult, marshalSaxResult, or marshalStreamResult.

setProcessExternalEntities

open fun setProcessExternalEntities(processExternalEntities: Boolean): Unit

Indicates whether external XML entities are processed when unmarshalling.

Default is false, meaning that external entities are not resolved. Note that processing of external entities will only be enabled/disabled when the Source passed to #unmarshal(Source) is a SAXSource or StreamSource. It has no effect for DOMSource or StAXSource instances.

Note: setting this option to true also automatically sets #setSupportDtd to true.

setSupportDtd

open fun setSupportDtd(supportDtd: Boolean): Unit

Indicates whether DTD parsing should be supported.

Default is false meaning that DTD is disabled.

unmarshal

fun unmarshal(source: Source): Any

Unmarshals the given provided javax.xml.transform.Source into an object graph.

This implementation inspects the given result, and calls unmarshalDomSource, unmarshalSaxSource, or unmarshalStreamSource.