Package org.eclipse.persistence.oxm
Class XMLMarshaller
- java.lang.Object
-
- org.eclipse.persistence.internal.oxm.Marshaller<CHARACTER_ESCAPE_HANDLER,CONTEXT,MARSHALLER_LISTENER,MEDIA_TYPE,NAMESPACE_PREFIX_MAPPER>
-
- org.eclipse.persistence.internal.oxm.XMLMarshaller<org.eclipse.persistence.internal.sessions.AbstractSession,CharacterEscapeHandler,XMLContext,XMLDescriptor,XMLMarshalListener,MediaType,NamespacePrefixMapper,org.eclipse.persistence.internal.oxm.TreeObjectBuilder,DatabaseSession>
-
- org.eclipse.persistence.oxm.XMLMarshaller
-
- All Implemented Interfaces:
java.lang.Cloneable
public class XMLMarshaller extends org.eclipse.persistence.internal.oxm.XMLMarshaller<org.eclipse.persistence.internal.sessions.AbstractSession,CharacterEscapeHandler,XMLContext,XMLDescriptor,XMLMarshalListener,MediaType,NamespacePrefixMapper,org.eclipse.persistence.internal.oxm.TreeObjectBuilder,DatabaseSession> implements java.lang.Cloneable
Class used to marshal object to XML.
Create an XMLMarshaller from an XMLContext.
Code Sample
XMLContext context = new XMLContext("mySessionName");
XMLMarshaller marshaller = context.createMarshaller();
Objects can be marshalled to the following outputs:
- java.io.OutputStream
- java.io.Writer
- javax.xml.transform.Result
- org.w3c.dom.Node
- org.xml.sax.ContentHandler
Objects that can be marshalled are those which are mapped in the TopLink project associated with the XMLContext, and which are mapped to an XMLDescriptor that has a default root element specified.
- See Also:
XMLContext
-
-
Field Summary
-
Fields inherited from class org.eclipse.persistence.internal.oxm.XMLMarshaller
attachmentMarshaller, DEFAULT_XML_VERSION, domToEventWriterClass, domToStreamWriterClass, mediaType, staxResultClass, staxResultGetEventWriterMethod, staxResultGetStreamWriterMethod, transformer, writeToEventWriterMethod, writeToStreamMethod
-
-
Constructor Summary
Constructors Modifier Constructor Description XMLMarshaller(XMLContext xmlContext)Create a new XMLMarshaller based on the specified sessionprotectedXMLMarshaller(XMLMarshaller xmlMarshaller)Copy constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description XMLMarshallerclone()CharacterEscapeHandlergetCharacterEscapeHandler()Return this Marshaller's CharacterEscapeHandler.protected XMLDescriptorgetDescriptor(java.lang.Object object, org.eclipse.persistence.internal.sessions.AbstractSession session, boolean isXMLRoot)org.eclipse.persistence.internal.oxm.JsonTypeConfigurationgetJsonTypeConfiguration()Returns json type configuration.XMLMarshalListenergetMarshalListener()MediaTypegetMediaType()Get the MediaType for this xmlMarshaller.NamespacePrefixMappergetNamespacePrefixMapper()NamespacePrefixMapper that can be used during marshal (instead of those set in the project meta data)protected org.w3c.dom.NodegetNode(java.lang.Object object, org.w3c.dom.Node parentNode, org.eclipse.persistence.internal.sessions.AbstractSession session, XMLDescriptor xmlDescriptor, boolean isXMLRoot)java.util.PropertiesgetProperties()Return a properties object for a given instance of the XMLMarshaller.XMLContextgetXMLContext()Return the instance of XMLContext that was used to create this instance of XMLMarshaller.voidmarshal(java.lang.Object object, javax.xml.transform.Result result)PUBLIC: Convert the given object to XML and update the given result with that XML Documentprotected voidmarshal(java.lang.Object object, org.eclipse.persistence.internal.sessions.AbstractSession session, MarshalRecord marshalRecord)Convert the given object to XML and update the given marshal record with that XML Document.protected org.w3c.dom.DocumentobjectToXML(java.lang.Object object, XMLDescriptor descriptor, boolean isXMLRoot)INTERNAL: Convert the given object to an XML Documentorg.w3c.dom.DocumentobjectToXML(java.lang.Object object, XMLDescriptor descriptor, XMLRecord xmlRow, boolean isXMLRoot, DocumentPreservationPolicy docPresPolicy)INTERNAL: Convert the given object to an XML Documentorg.w3c.dom.DocumentobjectToXML(java.lang.Object object, org.w3c.dom.Node parent)Deprecated.org.w3c.dom.DocumentobjectToXML(java.lang.Object object, org.w3c.dom.Node parent, DocumentPreservationPolicy docPresPolicy)org.w3c.dom.DocumentobjectToXML(java.lang.Object object, org.w3c.dom.Node rootNode, XMLDescriptor descriptor, XMLRecord xmlRow, boolean isXMLRoot, DocumentPreservationPolicy docPresPolicy)protected org.w3c.dom.NodeobjectToXMLNode(java.lang.Object object, org.w3c.dom.Node rootNode, org.eclipse.persistence.internal.sessions.AbstractSession session, XMLDescriptor descriptor, boolean isXMLRoot)voidsetCharacterEscapeHandler(CharacterEscapeHandler c)Set this Marshaller's CharacterEscapeHandler.voidsetMarshalListener(XMLMarshalListener listener)voidsetMediaType(MediaType mediaType)Set the MediaType for this xmlMarshaller.voidsetNamespacePrefixMapper(NamespacePrefixMapper mapper)NamespacePrefixMapper that can be used during marshal (instead of those set in the project meta data)voidsetXMLContext(XMLContext value)Set the XMLContext used by this instance of XMLMarshaller.voidsetXMLMarshalHandler(XMLMarshalListener marshalListener)-
Methods inherited from class org.eclipse.persistence.internal.oxm.XMLMarshaller
addDescriptorNamespacesToXMLRecord, copyNamespaces, getAttachmentMarshaller, getAttributePrefix, getDescriptor, getDescriptor, getDescriptor, getDescriptor, getDescriptor, getDescriptor, getMarshalAttributeGroup, getNamespaceSeparator, getNoNamespaceSchemaLocation, getSchema, getSchemaLocation, getTransformer, getValueWrapper, getXmlHeader, isApplicationJSON, isApplicationXML, isFragment, isIncludeRoot, isLogPayload, isMarshalEmptyCollections, isReduceAnyArrays, isSimpleXMLRoot, isWrapperAsCollectionName, marshal, marshal, marshal, marshal, marshal, marshal, marshal, objectToXML, objectToXMLNode, setAttachmentMarshaller, setAttributePrefix, setEncoding, setFormattedOutput, setFragment, setIncludeRoot, setLogPayload, setMarshalAttributeGroup, setMarshalEmptyCollections, setNamespaceSeparator, setNoNamespaceSchemaLocation, setReduceAnyArrays, setSchema, setSchemaLocation, setValueWrapper, setWrapperAsCollectionName, setXmlHeader
-
-
-
-
Constructor Detail
-
XMLMarshaller
public XMLMarshaller(XMLContext xmlContext)
Create a new XMLMarshaller based on the specified session- Parameters:
xmlContext- the XML content
-
XMLMarshaller
protected XMLMarshaller(XMLMarshaller xmlMarshaller)
Copy constructor
-
-
Method Detail
-
getXMLContext
public XMLContext getXMLContext()
Return the instance of XMLContext that was used to create this instance of XMLMarshaller.
-
setXMLContext
public void setXMLContext(XMLContext value)
Set the XMLContext used by this instance of XMLMarshaller.
-
getProperties
public java.util.Properties getProperties()
Return a properties object for a given instance of the XMLMarshaller.- Returns:
-
setXMLMarshalHandler
public void setXMLMarshalHandler(XMLMarshalListener marshalListener)
-
marshal
public void marshal(java.lang.Object object, javax.xml.transform.Result result) throws XMLMarshalExceptionPUBLIC: Convert the given object to XML and update the given result with that XML Document- Overrides:
marshalin classorg.eclipse.persistence.internal.oxm.XMLMarshaller<org.eclipse.persistence.internal.sessions.AbstractSession,CharacterEscapeHandler,XMLContext,XMLDescriptor,XMLMarshalListener,MediaType,NamespacePrefixMapper,org.eclipse.persistence.internal.oxm.TreeObjectBuilder,DatabaseSession>- Parameters:
object- the object to marshalresult- the result to marshal the object to- Throws:
XMLMarshalException- if an error occurred during marshalling
-
getNode
protected org.w3c.dom.Node getNode(java.lang.Object object, org.w3c.dom.Node parentNode, org.eclipse.persistence.internal.sessions.AbstractSession session, XMLDescriptor xmlDescriptor, boolean isXMLRoot)- Overrides:
getNodein classorg.eclipse.persistence.internal.oxm.XMLMarshaller<org.eclipse.persistence.internal.sessions.AbstractSession,CharacterEscapeHandler,XMLContext,XMLDescriptor,XMLMarshalListener,MediaType,NamespacePrefixMapper,org.eclipse.persistence.internal.oxm.TreeObjectBuilder,DatabaseSession>
-
getMarshalListener
public XMLMarshalListener getMarshalListener()
- Overrides:
getMarshalListenerin classorg.eclipse.persistence.internal.oxm.Marshaller<CharacterEscapeHandler,XMLContext,XMLMarshalListener,MediaType,NamespacePrefixMapper>
-
setMarshalListener
public void setMarshalListener(XMLMarshalListener listener)
- Overrides:
setMarshalListenerin classorg.eclipse.persistence.internal.oxm.Marshaller<CharacterEscapeHandler,XMLContext,XMLMarshalListener,MediaType,NamespacePrefixMapper>
-
marshal
protected void marshal(java.lang.Object object, org.eclipse.persistence.internal.sessions.AbstractSession session, MarshalRecord marshalRecord)Convert the given object to XML and update the given marshal record with that XML Document.- Parameters:
object- the object to marshalmarshalRecord- the marshalRecord to marshal the object to
-
objectToXML
protected org.w3c.dom.Document objectToXML(java.lang.Object object, XMLDescriptor descriptor, boolean isXMLRoot) throws XMLMarshalExceptionINTERNAL: Convert the given object to an XML Document- Overrides:
objectToXMLin classorg.eclipse.persistence.internal.oxm.XMLMarshaller<org.eclipse.persistence.internal.sessions.AbstractSession,CharacterEscapeHandler,XMLContext,XMLDescriptor,XMLMarshalListener,MediaType,NamespacePrefixMapper,org.eclipse.persistence.internal.oxm.TreeObjectBuilder,DatabaseSession>- Parameters:
object- the object to marshaldescriptor- the XMLDescriptor for the object being marshalled- Returns:
- the document which the specified object has been marshalled to
- Throws:
XMLMarshalException- if an error occurred during marshalling
-
objectToXMLNode
protected org.w3c.dom.Node objectToXMLNode(java.lang.Object object, org.w3c.dom.Node rootNode, org.eclipse.persistence.internal.sessions.AbstractSession session, XMLDescriptor descriptor, boolean isXMLRoot) throws XMLMarshalException- Overrides:
objectToXMLNodein classorg.eclipse.persistence.internal.oxm.XMLMarshaller<org.eclipse.persistence.internal.sessions.AbstractSession,CharacterEscapeHandler,XMLContext,XMLDescriptor,XMLMarshalListener,MediaType,NamespacePrefixMapper,org.eclipse.persistence.internal.oxm.TreeObjectBuilder,DatabaseSession>- Throws:
XMLMarshalException
-
objectToXML
@Deprecated public org.w3c.dom.Document objectToXML(java.lang.Object object, org.w3c.dom.Node parent) throws XMLMarshalExceptionDeprecated.PUBLIC: Convert the given object to descendants of the parent element- Parameters:
object- the object to marshalparent- the node to marshal the object to- Returns:
- the document which the specified object has been marshalled to
- Throws:
XMLMarshalException- if an error occurred during marshalling
-
objectToXML
public org.w3c.dom.Document objectToXML(java.lang.Object object, org.w3c.dom.Node parent, DocumentPreservationPolicy docPresPolicy)
-
objectToXML
public org.w3c.dom.Document objectToXML(java.lang.Object object, XMLDescriptor descriptor, XMLRecord xmlRow, boolean isXMLRoot, DocumentPreservationPolicy docPresPolicy)INTERNAL: Convert the given object to an XML Document
-
objectToXML
public org.w3c.dom.Document objectToXML(java.lang.Object object, org.w3c.dom.Node rootNode, XMLDescriptor descriptor, XMLRecord xmlRow, boolean isXMLRoot, DocumentPreservationPolicy docPresPolicy)
-
getDescriptor
protected XMLDescriptor getDescriptor(java.lang.Object object, org.eclipse.persistence.internal.sessions.AbstractSession session, boolean isXMLRoot)
-
clone
public XMLMarshaller clone()
- Overrides:
clonein classjava.lang.Object
-
setNamespacePrefixMapper
public void setNamespacePrefixMapper(NamespacePrefixMapper mapper)
NamespacePrefixMapper that can be used during marshal (instead of those set in the project meta data)- Overrides:
setNamespacePrefixMapperin classorg.eclipse.persistence.internal.oxm.Marshaller<CharacterEscapeHandler,XMLContext,XMLMarshalListener,MediaType,NamespacePrefixMapper>- Since:
- 2.3.3
-
getNamespacePrefixMapper
public NamespacePrefixMapper getNamespacePrefixMapper()
NamespacePrefixMapper that can be used during marshal (instead of those set in the project meta data)- Overrides:
getNamespacePrefixMapperin classorg.eclipse.persistence.internal.oxm.Marshaller<CharacterEscapeHandler,XMLContext,XMLMarshalListener,MediaType,NamespacePrefixMapper>- Returns:
- Since:
- 2.3.3
-
getCharacterEscapeHandler
public CharacterEscapeHandler getCharacterEscapeHandler()
Return this Marshaller's CharacterEscapeHandler.- Overrides:
getCharacterEscapeHandlerin classorg.eclipse.persistence.internal.oxm.Marshaller<CharacterEscapeHandler,XMLContext,XMLMarshalListener,MediaType,NamespacePrefixMapper>- Since:
- 2.3.3
-
setCharacterEscapeHandler
public void setCharacterEscapeHandler(CharacterEscapeHandler c)
Set this Marshaller's CharacterEscapeHandler.- Overrides:
setCharacterEscapeHandlerin classorg.eclipse.persistence.internal.oxm.Marshaller<CharacterEscapeHandler,XMLContext,XMLMarshalListener,MediaType,NamespacePrefixMapper>- Since:
- 2.3.3
-
setMediaType
public void setMediaType(MediaType mediaType)
Set the MediaType for this xmlMarshaller. See org.eclipse.persistence.oxm.MediaType for the media types supported by EclipseLink MOXy- Overrides:
setMediaTypein classorg.eclipse.persistence.internal.oxm.XMLMarshaller<org.eclipse.persistence.internal.sessions.AbstractSession,CharacterEscapeHandler,XMLContext,XMLDescriptor,XMLMarshalListener,MediaType,NamespacePrefixMapper,org.eclipse.persistence.internal.oxm.TreeObjectBuilder,DatabaseSession>- Parameters:
mediaType-- Since:
- EclipseLink 2.4.0
-
getMediaType
public MediaType getMediaType()
Get the MediaType for this xmlMarshaller. See org.eclipse.persistence.oxm.MediaType for the media types supported by EclipseLink MOXy If not set the default is MediaType.APPLICATION_XML- Returns:
- MediaType
- Since:
- EclipseLink 2.4.0
-
getJsonTypeConfiguration
public org.eclipse.persistence.internal.oxm.JsonTypeConfiguration getJsonTypeConfiguration()
Returns json type configuration.- Specified by:
getJsonTypeConfigurationin classorg.eclipse.persistence.internal.oxm.Marshaller<CharacterEscapeHandler,XMLContext,XMLMarshalListener,MediaType,NamespacePrefixMapper>- Returns:
- json type configuration
- Since:
- 2.6.0
-
-