Class MarshallerImpl
- java.lang.Object
-
- javax.xml.bind.helpers.AbstractMarshallerImpl
-
- com.sun.xml.bind.v2.runtime.MarshallerImpl
-
- All Implemented Interfaces:
Marshaller,ValidationEventHandler
public final class MarshallerImpl extends AbstractMarshallerImpl implements ValidationEventHandler
Implementation ofMarshallerinterface for the JAXB RI.Eventually all the
marshal(java.lang.Object, java.io.OutputStream, javax.xml.namespace.NamespaceContext)methods call into thewrite(com.sun.xml.bind.v2.runtime.Name, com.sun.xml.bind.v2.runtime.JaxBeanInfo<T>, T, com.sun.xml.bind.v2.runtime.output.XmlOutput, java.lang.Runnable)method.- Author:
- Kohsuke Kawaguchi, Vivek Pandey
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface javax.xml.bind.Marshaller
Marshaller.Listener
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringC14Nprotected static StringENCODING_HANDLERprotected static StringENCODING_HANDLER2protected static StringINDENT_STRINGprotected static StringOBJECT_IDENTITY_CYCLE_DETECTIONprotected static StringPREFIX_MAPPERprotected XMLSerializerserializerprotected static StringXML_HEADERSprotected static StringXMLDECLARATION-
Fields inherited from interface javax.xml.bind.Marshaller
JAXB_ENCODING, JAXB_FORMATTED_OUTPUT, JAXB_FRAGMENT, JAXB_NO_NAMESPACE_SCHEMA_LOCATION, JAXB_SCHEMA_LOCATION
-
-
Constructor Summary
Constructors Constructor Description MarshallerImpl(JAXBContextImpl c, AssociationMap assoc)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CharacterEscapeHandlercreateEscapeHandler(String encoding)XmlOutputcreateWriter(OutputStream os)XmlOutputcreateWriter(OutputStream os, String encoding)XmlOutputcreateWriter(Writer w)XmlOutputcreateWriter(Writer w, String encoding)<A extends XmlAdapter>
AgetAdapter(Class<A> type)Gets the adapter associated with the specified type.AttachmentMarshallergetAttachmentMarshaller()JAXBContextImplgetContext()Marshaller.ListenergetListener()ReturnMarshaller.Listenerregistered with thisMarshaller.ObjectgetProperty(String name)Default implementation of the getProperty method handles the four defined properties in Marshaller.SchemagetSchema()Get the JAXP 1.3Schemaobject being used to perform marshal-time validation.booleanhandleEvent(ValidationEvent event)Default error handling behavior fotMarshaller.voidmarshal(Object obj, XmlOutput output)voidmarshal(Object obj, OutputStream out, NamespaceContext inscopeNamespace)Marshals toOutputStreamwith the given in-scope namespaces taken into account.voidmarshal(Object obj, XMLEventWriter writer)Marshal the content tree rooted atjaxbElementinto aXMLEventWriter.voidmarshal(Object obj, XMLStreamWriter writer)Marshal the content tree rooted atjaxbElementinto aXMLStreamWriter.voidmarshal(Object target, Result result)Marshal the content tree rooted atjaxbElementinto the specifiedjavax.xml.transform.Result.<A extends XmlAdapter>
voidsetAdapter(Class<A> type, A adapter)Associates a configured instance ofXmlAdapterwith this marshaller.voidsetAttachmentMarshaller(AttachmentMarshaller am)Associate a context that enables binary data within an XML document to be transmitted as XML-binary optimized attachment.voidsetListener(Marshaller.Listener listener)Register marshal event callbackMarshaller.Listenerwith thisMarshaller.voidsetProperty(String name, Object value)Default implementation of the setProperty method handles the four defined properties in Marshaller.voidsetSchema(Schema s)Specify the JAXP 1.3Schemaobject that should be used to validate subsequent marshal operations against.protected <T> voidwrite(Name rootTagName, JaxBeanInfo<T> bi, T obj, XmlOutput out, Runnable postInitAction)Used byBridgeImplto write an arbitrary object as a fragment.-
Methods inherited from class javax.xml.bind.helpers.AbstractMarshallerImpl
getEncoding, getEventHandler, getJavaEncoding, getNode, getNoNSSchemaLocation, getSchemaLocation, isFormattedOutput, isFragment, marshal, marshal, marshal, marshal, marshal, setAdapter, setEncoding, setEventHandler, setFormattedOutput, setFragment, setNoNSSchemaLocation, setSchemaLocation
-
-
-
-
Field Detail
-
serializer
protected final XMLSerializer serializer
-
INDENT_STRING
protected static final String INDENT_STRING
- See Also:
- Constant Field Values
-
PREFIX_MAPPER
protected static final String PREFIX_MAPPER
- See Also:
- Constant Field Values
-
ENCODING_HANDLER
protected static final String ENCODING_HANDLER
- See Also:
- Constant Field Values
-
ENCODING_HANDLER2
protected static final String ENCODING_HANDLER2
- See Also:
- Constant Field Values
-
XMLDECLARATION
protected static final String XMLDECLARATION
- See Also:
- Constant Field Values
-
XML_HEADERS
protected static final String XML_HEADERS
- See Also:
- Constant Field Values
-
C14N
protected static final String C14N
- See Also:
- Constant Field Values
-
OBJECT_IDENTITY_CYCLE_DETECTION
protected static final String OBJECT_IDENTITY_CYCLE_DETECTION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MarshallerImpl
public MarshallerImpl(JAXBContextImpl c, AssociationMap assoc)
- Parameters:
assoc- non-null if the marshaller is working insideBinderImpl.
-
-
Method Detail
-
getContext
public JAXBContextImpl getContext()
-
marshal
public void marshal(Object obj, OutputStream out, NamespaceContext inscopeNamespace) throws JAXBException
Marshals toOutputStreamwith the given in-scope namespaces taken into account.- Throws:
JAXBException- Since:
- 2.1.5
-
marshal
public void marshal(Object obj, XMLStreamWriter writer) throws JAXBException
Description copied from interface:MarshallerMarshal the content tree rooted atjaxbElementinto aXMLStreamWriter.- Specified by:
marshalin interfaceMarshaller- Overrides:
marshalin classAbstractMarshallerImpl- Parameters:
obj- The content tree to be marshalled.writer- XML will be sent to this writer.- Throws:
JAXBException- If any unexpected problem occurs during the marshalling.MarshalException- If theValidationEventHandlerreturns false from itshandleEventmethod or theMarshalleris unable to marshaljaxbElement(or any object reachable fromjaxbElement). See Marshalling a JAXB element.
-
marshal
public void marshal(Object obj, XMLEventWriter writer) throws JAXBException
Description copied from interface:MarshallerMarshal the content tree rooted atjaxbElementinto aXMLEventWriter.- Specified by:
marshalin interfaceMarshaller- Overrides:
marshalin classAbstractMarshallerImpl- Parameters:
obj- The content tree rooted at jaxbElement to be marshalled.writer- XML will be sent to this writer.- Throws:
JAXBException- If any unexpected problem occurs during the marshalling.MarshalException- If theValidationEventHandlerreturns false from itshandleEventmethod or theMarshalleris unable to marshaljaxbElement(or any object reachable fromjaxbElement). See Marshalling a JAXB element.
-
marshal
public void marshal(Object obj, XmlOutput output) throws JAXBException
- Throws:
JAXBException
-
marshal
public void marshal(Object target, Result result) throws JAXBException
Description copied from interface:MarshallerMarshal the content tree rooted atjaxbElementinto the specifiedjavax.xml.transform.Result.All JAXB Providers must at least support
DOMResult,SAXResult, andStreamResult. It can support other derived classes ofResultas well.- Specified by:
marshalin interfaceMarshaller- Parameters:
target- The root of content tree to be marshalled.result- XML will be sent to this Result- Throws:
JAXBException- If any unexpected problem occurs during the marshalling.MarshalException- If theValidationEventHandlerreturns false from itshandleEventmethod or theMarshalleris unable to marshaljaxbElement(or any object reachable fromjaxbElement). See Marshalling a JAXB element.
-
write
protected final <T> void write(Name rootTagName, JaxBeanInfo<T> bi, T obj, XmlOutput out, Runnable postInitAction) throws JAXBException
Used byBridgeImplto write an arbitrary object as a fragment.- Throws:
JAXBException
-
createEscapeHandler
protected CharacterEscapeHandler createEscapeHandler(String encoding)
-
createWriter
public XmlOutput createWriter(OutputStream os) throws JAXBException
- Throws:
JAXBException
-
createWriter
public XmlOutput createWriter(OutputStream os, String encoding) throws JAXBException
- Throws:
JAXBException
-
getProperty
public Object getProperty(String name) throws PropertyException
Description copied from class:AbstractMarshallerImplDefault implementation of the getProperty method handles the four defined properties in Marshaller. If a provider needs to support additional provider specific properties, it should override this method in a derived class.- Specified by:
getPropertyin interfaceMarshaller- Overrides:
getPropertyin classAbstractMarshallerImpl- Parameters:
name- the name of the property to retrieve- Returns:
- the value of the requested property
- Throws:
PropertyException- when there is an error retrieving the given property or value property name
-
setProperty
public void setProperty(String name, Object value) throws PropertyException
Description copied from class:AbstractMarshallerImplDefault implementation of the setProperty method handles the four defined properties in Marshaller. If a provider needs to handle additional properties, it should override this method in a derived class.- Specified by:
setPropertyin interfaceMarshaller- Overrides:
setPropertyin classAbstractMarshallerImpl- Parameters:
name- the name of the property to be set. This value can either be specified using one of the constant fields or a user supplied string.value- the value of the property to be set- Throws:
PropertyException- when there is an error processing the given property or value
-
setAdapter
public <A extends XmlAdapter> void setAdapter(Class<A> type, A adapter)
Description copied from interface:MarshallerAssociates a configured instance ofXmlAdapterwith this marshaller.Every marshaller internally maintains a
Map<Class,XmlAdapter>, which it uses for marshalling classes whose fields/methods are annotated withXmlJavaTypeAdapter.This method allows applications to use a configured instance of
XmlAdapter. When an instance of an adapter is not given, a marshaller will create one by invoking its default constructor.- Specified by:
setAdapterin interfaceMarshaller- Overrides:
setAdapterin classAbstractMarshallerImpl- Parameters:
type- The type of the adapter. The specified instance will be used whenXmlJavaTypeAdapter.value()refers to this type.adapter- The instance of the adapter to be used. If null, it will un-register the current adapter set for this type.
-
getAdapter
public <A extends XmlAdapter> A getAdapter(Class<A> type)
Description copied from interface:MarshallerGets the adapter associated with the specified type. This is the reverse operation of theMarshaller.setAdapter(javax.xml.bind.annotation.adapters.XmlAdapter)method.- Specified by:
getAdapterin interfaceMarshaller- Overrides:
getAdapterin classAbstractMarshallerImpl
-
setAttachmentMarshaller
public void setAttachmentMarshaller(AttachmentMarshaller am)
Description copied from interface:MarshallerAssociate a context that enables binary data within an XML document to be transmitted as XML-binary optimized attachment. The attachment is referenced from the XML document content model by content-id URIs(cid) references stored within the xml document.
- Specified by:
setAttachmentMarshallerin interfaceMarshaller- Overrides:
setAttachmentMarshallerin classAbstractMarshallerImpl
-
getAttachmentMarshaller
public AttachmentMarshaller getAttachmentMarshaller()
- Specified by:
getAttachmentMarshallerin interfaceMarshaller- Overrides:
getAttachmentMarshallerin classAbstractMarshallerImpl
-
getSchema
public Schema getSchema()
Description copied from interface:MarshallerGet the JAXP 1.3Schemaobject being used to perform marshal-time validation. If there is no Schema set on the marshaller, then this method will return null indicating that marshal-time validation will not be performed.- Specified by:
getSchemain interfaceMarshaller- Overrides:
getSchemain classAbstractMarshallerImpl- Returns:
- the Schema object being used to perform marshal-time validation or null if not present.
-
setSchema
public void setSchema(Schema s)
Description copied from interface:MarshallerSpecify the JAXP 1.3Schemaobject that should be used to validate subsequent marshal operations against. Passing null into this method will disable validation.This method allows the caller to validate the marshalled XML as it's marshalled.
Initially this property is set to
null.- Specified by:
setSchemain interfaceMarshaller- Overrides:
setSchemain classAbstractMarshallerImpl- Parameters:
s- Schema object to validate marshal operations against or null to disable validation
-
handleEvent
public boolean handleEvent(ValidationEvent event)
Default error handling behavior fotMarshaller.- Specified by:
handleEventin interfaceValidationEventHandler- Parameters:
event- the encapsulated validation event information. It is a provider error if this parameter is null.- Returns:
- true if the JAXB Provider should attempt to continue the current
unmarshal, validate, or marshal operation after handling this
warning/error, false if the provider should terminate the current
operation with the appropriate
UnmarshalException,ValidationException, orMarshalException.
-
getListener
public Marshaller.Listener getListener()
Description copied from interface:MarshallerReturn
Marshaller.Listenerregistered with thisMarshaller.- Specified by:
getListenerin interfaceMarshaller- Overrides:
getListenerin classAbstractMarshallerImpl- Returns:
- registered
Marshaller.Listenerornullif no Listener is registered with this Marshaller.
-
setListener
public void setListener(Marshaller.Listener listener)
Description copied from interface:MarshallerRegister marshal event callback
Marshaller.Listenerwith thisMarshaller.There is only one Listener per Marshaller. Setting a Listener replaces the previous set Listener. One can unregister current Listener by setting listener to
null.- Specified by:
setListenerin interfaceMarshaller- Overrides:
setListenerin classAbstractMarshallerImpl- Parameters:
listener- an instance of a class that implementsMarshaller.Listener
-
-