@Deprecated public class CastorMarshaller extends AbstractMarshaller implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanClassLoaderAware
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.
setEncoding(String),
setTargetClass(Class),
setTargetPackages(String[]),
setMappingLocation(Resource),
setMappingLocations(Resource[])| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DEFAULT_ENCODING
已过时。
The default encoding used for stream access: UTF-8.
|
logger| 构造器和说明 |
|---|
CastorMarshaller()
已过时。
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
afterPropertiesSet()
已过时。
|
protected XmlMappingException |
convertCastorException(org.exolab.castor.xml.XMLException ex,
boolean marshalling)
已过时。
Convert the given
XMLException to an appropriate exception from the
org.springframework.oxm hierarchy. |
protected org.exolab.castor.xml.XMLContext |
createXMLContext(org.springframework.core.io.Resource[] mappingLocations,
Class<?>[] targetClasses,
String[] targetPackages)
已过时。
Create the Castor
XMLContext. |
protected void |
customizeMarshaller(org.exolab.castor.xml.Marshaller marshaller)
已过时。
Template method that allows for customizing of the given Castor
Marshaller. |
protected void |
customizeUnmarshaller(org.exolab.castor.xml.Unmarshaller unmarshaller)
已过时。
Template method that allows for customizing of the given Castor
Unmarshaller. |
protected String |
getDefaultEncoding()
已过时。
Determine the default encoding to use for marshalling or unmarshalling from
a byte stream, or
null if none. |
protected void |
marshalDomNode(Object graph,
Node node)
已过时。
Abstract template method for marshalling the given object graph to a DOM
Node. |
protected void |
marshalOutputStream(Object graph,
OutputStream outputStream)
已过时。
Abstract template method for marshalling the given object graph to a
OutputStream. |
protected void |
marshalSaxHandlers(Object graph,
ContentHandler contentHandler,
LexicalHandler lexicalHandler)
已过时。
Abstract template method for marshalling the given object graph to a SAX
ContentHandler. |
protected void |
marshalWriter(Object graph,
Writer writer)
已过时。
Abstract template method for marshalling the given object graph to a
Writer. |
protected void |
marshalXmlEventWriter(Object graph,
XMLEventWriter eventWriter)
已过时。
Abstract template method for marshalling the given object to a StAX
XMLEventWriter. |
protected void |
marshalXmlStreamWriter(Object graph,
XMLStreamWriter streamWriter)
已过时。
Abstract template method for marshalling the given object to a StAX
XMLStreamWriter. |
void |
setBeanClassLoader(ClassLoader classLoader)
已过时。
|
void |
setCastorProperties(Map<String,String> castorProperties)
已过时。
Set Castor-specific properties for marshalling and unmarshalling.
|
void |
setClassDescriptorResolver(org.exolab.castor.xml.XMLClassDescriptorResolver classDescriptorResolver)
已过时。
Set the
XMLClassDescriptorResolver to be used during unmarshalling. |
void |
setClearCollections(boolean clearCollections)
已过时。
Sets whether this unmarshaller should clear collections upon the first use.
|
void |
setDoctypes(Map<String,String> doctypes)
已过时。
Set the map containing document type definition for the marshaller.
|
void |
setEncoding(String encoding)
已过时。
Set the encoding to be used for stream access.
|
void |
setEntityResolver(EntityResolver entityResolver)
已过时。
Set the
EntityResolver to be used during unmarshalling. |
void |
setIdResolver(org.exolab.castor.xml.IDResolver idResolver)
已过时。
Set the Castor
IDResolver to be used during unmarshalling. |
void |
setIgnoreExtraAttributes(boolean ignoreExtraAttributes)
已过时。
Set whether the Castor
Unmarshaller should ignore attributes that do not match a specific field. |
void |
setIgnoreExtraElements(boolean ignoreExtraElements)
已过时。
Set whether the Castor
Unmarshaller should ignore elements that do not match a specific field. |
void |
setMappingLocation(org.springframework.core.io.Resource mappingLocation)
已过时。
Set the locations of the Castor XML mapping files.
|
void |
setMappingLocations(org.springframework.core.io.Resource... mappingLocations)
已过时。
Set the locations of the Castor XML mapping files.
|
void |
setMarshalAsDocument(boolean marshalAsDocument)
已过时。
Set whether this marshaller should output the xml declaration.
|
void |
setMarshalExtendedType(boolean marshalExtendedType)
已过时。
Set whether this marshaller should output for given type the
xsi:type attribute. |
void |
setNamespaceMappings(Map<String,String> namespaceMappings)
已过时。
Set the namespace mappings.
|
void |
setNamespaceToPackageMapping(Map<String,String> namespaceToPackageMapping)
已过时。
Set the namespace to package mappings.
|
void |
setNoNamespaceSchemaLocation(String noNamespaceSchemaLocation)
已过时。
Set the value of
xsi:noNamespaceSchemaLocation attribute. |
void |
setObjectFactory(org.exolab.castor.util.ObjectFactory objectFactory)
已过时。
Set the Castor
ObjectFactory to be used during unmarshalling. |
void |
setProcessingInstructions(Map<String,String> processingInstructions)
已过时。
Sets the processing instructions that will be used by during marshalling.
|
void |
setReuseObjects(boolean reuseObjects)
已过时。
Set whether this unmarshaller should re-use objects.
|
void |
setRootElement(String rootElement)
已过时。
Set the name of the root element.
|
void |
setRootObject(Object root)
已过时。
Set the expected root object for the unmarshaller, into which the source will be unmarshalled.
|
void |
setSchemaLocation(String schemaLocation)
已过时。
Set the value of
xsi:schemaLocation attribute. |
void |
setSuppressNamespaces(boolean suppressNamespaces)
已过时。
Sets whether this marshaller should output namespaces.
|
void |
setSuppressXsiType(boolean suppressXsiType)
已过时。
Set whether this marshaller should output the
xsi:type attribute. |
void |
setTargetClass(Class<?> targetClass)
已过时。
Set the Castor target class.
|
void |
setTargetClasses(Class<?>... targetClasses)
已过时。
Set the Castor target classes.
|
void |
setTargetPackage(String targetPackage)
已过时。
Set the name of a package with the Castor descriptor classes.
|
void |
setTargetPackages(String... targetPackages)
已过时。
Set the names of packages with the Castor descriptor classes.
|
void |
setUseXSITypeAtRoot(boolean useXSITypeAtRoot)
已过时。
Sets whether this marshaller should output the
xsi:type attribute for the root element. |
void |
setValidating(boolean validating)
已过时。
Set whether this marshaller should validate in- and outgoing documents.
|
void |
setWhitespacePreserve(boolean whitespacePreserve)
已过时。
Set whether the Castor
Unmarshaller should preserve "ignorable" whitespace. |
boolean |
supports(Class<?> clazz)
已过时。
Returns
true for all classes, i.e. |
protected Object |
unmarshalDomNode(Node node)
已过时。
Abstract template method for unmarshalling from a given DOM
Node. |
protected Object |
unmarshalInputStream(InputStream inputStream)
已过时。
Abstract template method for unmarshalling from a given
InputStream. |
protected Object |
unmarshalReader(Reader reader)
已过时。
Abstract template method for unmarshalling from a given
Reader. |
protected Object |
unmarshalSaxReader(XMLReader xmlReader,
InputSource inputSource)
已过时。
Abstract template method for unmarshalling using a given SAX
XMLReader
and InputSource. |
protected Object |
unmarshalXmlEventReader(XMLEventReader eventReader)
已过时。
Abstract template method for unmarshalling from a given Stax
XMLEventReader. |
protected Object |
unmarshalXmlStreamReader(XMLStreamReader streamReader)
已过时。
Abstract template method for unmarshalling from a given Stax
XMLStreamReader. |
buildDocument, createDocumentBuilder, createDocumentBuilderFactory, createXmlReader, isProcessExternalEntities, isSupportDtd, marshal, marshalDomResult, marshalSaxResult, marshalStaxResult, marshalStreamResult, setProcessExternalEntities, setSupportDtd, unmarshal, unmarshalDomSource, unmarshalSaxSource, unmarshalStaxSource, unmarshalStreamSourcepublic void setEncoding(String encoding)
DEFAULT_ENCODINGprotected String getDefaultEncoding()
AbstractMarshallernull if none.
The default implementation returns null.
getDefaultEncoding 在类中 AbstractMarshallerpublic void setMappingLocation(org.springframework.core.io.Resource mappingLocation)
public void setMappingLocations(org.springframework.core.io.Resource... mappingLocations)
public void setTargetClass(Class<?> targetClass)
public void setTargetClasses(Class<?>... targetClasses)
public void setTargetPackage(String targetPackage)
public void setTargetPackages(String... targetPackages)
public void setValidating(boolean validating)
Default is false.
Marshaller.setValidation(boolean)public void setSuppressNamespaces(boolean suppressNamespaces)
The default is false, i.e. namespaces are written.
Marshaller.setSuppressNamespaces(boolean)public void setSuppressXsiType(boolean suppressXsiType)
xsi:type attribute.
The default is false, i.e. the xsi:type is written.
Marshaller.setSuppressXSIType(boolean)public void setMarshalAsDocument(boolean marshalAsDocument)
The default is true, the XML declaration will be written.
Marshaller.setMarshalAsDocument(boolean)public void setMarshalExtendedType(boolean marshalExtendedType)
xsi:type attribute.
The default is true, the xsi:type attribute will be written.
Marshaller.setMarshalExtendedType(boolean)public void setRootElement(String rootElement)
Marshaller.setRootElement(String)public void setNoNamespaceSchemaLocation(String noNamespaceSchemaLocation)
xsi:noNamespaceSchemaLocation attribute. When set, the
xsi:noNamespaceSchemaLocation attribute will be written for the root element.Marshaller.setNoNamespaceSchemaLocation(String)public void setSchemaLocation(String schemaLocation)
xsi:schemaLocation attribute. When set, the
xsi:schemaLocation attribute will be written for the root element.Marshaller.setSchemaLocation(String)public void setUseXSITypeAtRoot(boolean useXSITypeAtRoot)
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.
Marshaller.setUseXSITypeAtRoot(boolean)public void setWhitespacePreserve(boolean whitespacePreserve)
Unmarshaller should preserve "ignorable" whitespace.
Default is false.
Unmarshaller.setWhitespacePreserve(boolean)public void setIgnoreExtraAttributes(boolean ignoreExtraAttributes)
Unmarshaller should ignore attributes that do not match a specific field.
Default is true: Extra attributes are ignored.
Unmarshaller.setIgnoreExtraAttributes(boolean)public void setIgnoreExtraElements(boolean ignoreExtraElements)
Unmarshaller should ignore elements that do not match a specific field.
Default is false: Extra elements are flagged as an error.
Unmarshaller.setIgnoreExtraElements(boolean)public void setRootObject(Object root)
Unmarshaller.setObject(Object)public void setReuseObjects(boolean reuseObjects)
The default is false, which means that the objects won't be re-used.
Unmarshaller.setReuseObjects(boolean)public void setClearCollections(boolean clearCollections)
The default is false which means that marshaller won't clear collections.
Unmarshaller.setClearCollections(boolean)public void setCastorProperties(Map<String,String> castorProperties)
Marshaller.setProperty(String, String),
Unmarshaller.setProperty(String, String)public void setDoctypes(Map<String,String> doctypes)
Marshaller.setDoctype(String, String)public void setProcessingInstructions(Map<String,String> processingInstructions)
Marshaller.addProcessingInstruction(String, String)public void setNamespaceMappings(Map<String,String> namespaceMappings)
Marshaller.setNamespaceMapping(String, String)public void setNamespaceToPackageMapping(Map<String,String> namespaceToPackageMapping)
Marshaller.setNamespaceMapping(String, String)public void setEntityResolver(EntityResolver entityResolver)
EntityResolver to be used during unmarshalling.
This resolver will used to resolve system and public ids.Unmarshaller.setEntityResolver(EntityResolver)public void setClassDescriptorResolver(org.exolab.castor.xml.XMLClassDescriptorResolver classDescriptorResolver)
XMLClassDescriptorResolver to be used during unmarshalling.
This resolver will used to resolve class descriptors.Unmarshaller.setResolver(XMLClassDescriptorResolver)public void setIdResolver(org.exolab.castor.xml.IDResolver idResolver)
IDResolver to be used during unmarshalling.Unmarshaller.setIDResolver(IDResolver)public void setObjectFactory(org.exolab.castor.util.ObjectFactory objectFactory)
ObjectFactory to be used during unmarshalling.Unmarshaller.setObjectFactory(ObjectFactory)public void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader 在接口中 org.springframework.beans.factory.BeanClassLoaderAwarepublic void afterPropertiesSet()
throws CastorMappingException,
IOException
afterPropertiesSet 在接口中 org.springframework.beans.factory.InitializingBeanCastorMappingExceptionIOExceptionprotected org.exolab.castor.xml.XMLContext createXMLContext(@Nullable
org.springframework.core.io.Resource[] mappingLocations,
@Nullable
Class<?>[] targetClasses,
@Nullable
String[] targetPackages)
throws org.exolab.castor.mapping.MappingException,
org.exolab.castor.xml.ResolverException,
IOException
XMLContext. Subclasses can override this to create a custom context.
The default implementation loads mapping files if defined, or the target class or packages if defined.
org.exolab.castor.mapping.MappingException - when the mapping file cannot be loadedIOException - in case of I/O errorsorg.exolab.castor.xml.ResolverExceptionXMLContext.addMapping(org.exolab.castor.mapping.Mapping),
XMLContext.addClass(Class)public boolean supports(Class<?> clazz)
true for all classes, i.e. Castor supports arbitrary classes.supports 在接口中 Marshallersupports 在接口中 Unmarshallerclazz - the class that this marshaller is being asked if it can marshaltrue if this marshaller can indeed marshal instances of the supplied class;
false otherwiseprotected void marshalDomNode(Object graph, Node node) throws XmlMappingException
AbstractMarshallerNode.
In practice, node is be a Document node, a DocumentFragment node,
or a Element node. In other words, a node that accepts children.
marshalDomNode 在类中 AbstractMarshallergraph - the root of the object graph to marshalnode - the DOM node that will contain the result treeXmlMappingException - if the given object cannot be marshalled to the DOM nodeDocument,
DocumentFragment,
Elementprotected void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter) throws XmlMappingException
AbstractMarshallerXMLEventWriter.marshalXmlEventWriter 在类中 AbstractMarshallergraph - the root of the object graph to marshaleventWriter - the XMLEventWriter to write toXmlMappingException - if the given object cannot be marshalled to the DOM nodeprotected void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException
AbstractMarshallerXMLStreamWriter.marshalXmlStreamWriter 在类中 AbstractMarshallergraph - the root of the object graph to marshalstreamWriter - the XMLStreamWriter to write toXmlMappingException - if the given object cannot be marshalled to the DOM nodeprotected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, @Nullable LexicalHandler lexicalHandler) throws XmlMappingException
AbstractMarshallerContentHandler.marshalSaxHandlers 在类中 AbstractMarshallergraph - the root of the object graph to marshalcontentHandler - the SAX ContentHandlerlexicalHandler - the SAX2 LexicalHandler. Can be null.XmlMappingException - if the given object cannot be marshalled to the handlersprotected void marshalOutputStream(Object graph, OutputStream outputStream) throws XmlMappingException, IOException
AbstractMarshallerOutputStream.marshalOutputStream 在类中 AbstractMarshallergraph - the root of the object graph to marshaloutputStream - the OutputStream to write toXmlMappingException - if the given object cannot be marshalled to the writerIOException - if an I/O exception occursprotected void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException
AbstractMarshallerWriter.marshalWriter 在类中 AbstractMarshallergraph - the root of the object graph to marshalwriter - the Writer to write toXmlMappingException - if the given object cannot be marshalled to the writerIOException - if an I/O exception occursprotected void customizeMarshaller(org.exolab.castor.xml.Marshaller marshaller)
Marshaller.protected Object unmarshalDomNode(Node node) throws XmlMappingException
AbstractMarshallerNode.unmarshalDomNode 在类中 AbstractMarshallernode - the DOM node that contains the objects to be unmarshalledXmlMappingException - if the given DOM node cannot be mapped to an objectprotected Object unmarshalXmlEventReader(XMLEventReader eventReader)
AbstractMarshallerXMLEventReader.unmarshalXmlEventReader 在类中 AbstractMarshallereventReader - the XMLEventReader to read fromprotected Object unmarshalXmlStreamReader(XMLStreamReader streamReader)
AbstractMarshallerXMLStreamReader.unmarshalXmlStreamReader 在类中 AbstractMarshallerstreamReader - the XMLStreamReader to read fromprotected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource) throws XmlMappingException, IOException
AbstractMarshallerXMLReader
and InputSource.unmarshalSaxReader 在类中 AbstractMarshallerxmlReader - the SAX XMLReader to parse withinputSource - the input source to parse fromXmlMappingException - if the given reader and input source cannot be converted to an objectIOException - if an I/O exception occursprotected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException
AbstractMarshallerInputStream.unmarshalInputStream 在类中 AbstractMarshallerinputStream - the InputStreamStream to read fromXmlMappingException - if the given stream cannot be converted to an objectIOException - if an I/O exception occursprotected Object unmarshalReader(Reader reader) throws XmlMappingException, IOException
AbstractMarshallerReader.unmarshalReader 在类中 AbstractMarshallerreader - the Reader to read fromXmlMappingException - if the given reader cannot be converted to an objectIOException - if an I/O exception occursprotected void customizeUnmarshaller(org.exolab.castor.xml.Unmarshaller unmarshaller)
Unmarshaller.protected XmlMappingException convertCastorException(org.exolab.castor.xml.XMLException ex, boolean marshalling)
XMLException to an appropriate exception from the
org.springframework.oxm hierarchy.
A boolean flag is used to indicate whether this exception occurs during marshalling or unmarshalling, since Castor itself does not make this distinction in its exception hierarchy.
ex - Castor XMLException that occurredmarshalling - indicates whether the exception occurs during marshalling (true),
or unmarshalling (false)XmlMappingException