Class MarshallerImpl
- All Implemented Interfaces:
Marshaller,ValidationEventHandler
Marshaller interface for the JAXB RI.
Eventually all the marshal(java.lang.Object, java.io.OutputStream, javax.xml.namespace.NamespaceContext) methods call into
the write(org.glassfish.jaxb.runtime.v2.runtime.Name, org.glassfish.jaxb.runtime.v2.runtime.JaxBeanInfo<T>, T, org.glassfish.jaxb.runtime.v2.runtime.output.XmlOutput, java.lang.Runnable) method.
- Author:
- Kohsuke Kawaguchi, Vivek Pandey
-
Nested Class Summary
Nested classes/interfaces inherited from interface jakarta.xml.bind.Marshaller
Marshaller.Listener -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected final XMLSerializerprotected static final Stringprotected static final StringFields inherited from interface jakarta.xml.bind.Marshaller
JAXB_ENCODING, JAXB_FORMATTED_OUTPUT, JAXB_FRAGMENT, JAXB_NO_NAMESPACE_SCHEMA_LOCATION, JAXB_SCHEMA_LOCATION -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected CharacterEscapeHandlercreateEscapeHandler(String encoding) createWriter(OutputStream os, String encoding) createWriter(Writer w, String encoding) <A extends XmlAdapter<?,?>>
AgetAdapter(Class<A> type) Gets the adapter associated with the specified type.ReturnMarshaller.Listenerregistered with thisMarshaller.getProperty(String name) Default implementation of the getProperty method handles the four defined properties in Marshaller.Get the JAXPSchemaobject being used to perform marshal-time validation.booleanhandleEvent(ValidationEvent event) Default error handling behavior fotMarshaller.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 the content tree rooted atjaxbElementinto the specifiedjavax.xml.transform.Result.void<A extends XmlAdapter<?,?>>
voidsetAdapter(Class<A> type, A adapter) Associates a configured instance ofXmlAdapterwith this marshaller.voidAssociate 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.voidSpecify the JAXPSchemaobject 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 jakarta.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 Details
-
serializer
-
INDENT_STRING
- See Also:
-
PREFIX_MAPPER
- See Also:
-
ENCODING_HANDLER
- See Also:
-
ENCODING_HANDLER2
- See Also:
-
XMLDECLARATION
- See Also:
-
XML_HEADERS
- See Also:
-
C14N
- See Also:
-
OBJECT_IDENTITY_CYCLE_DETECTION
- See Also:
-
-
Constructor Details
-
MarshallerImpl
- Parameters:
assoc- non-null if the marshaller is working insideBinderImpl.
-
-
Method Details
-
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
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 Jakarta XML Binding element.
-
marshal
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 Jakarta XML Binding element.
-
marshal
- Throws:
JAXBException
-
marshal
Description copied from interface:MarshallerMarshal the content tree rooted atjaxbElementinto the specifiedjavax.xml.transform.Result.All Jakarta XML Binding 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 Jakarta XML Binding element.
-
write
protected <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
-
createWriter
-
createWriter
-
createWriter
- Throws:
JAXBException
-
createWriter
- Throws:
JAXBException
-
getProperty
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
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
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- Type Parameters:
A- the type of the adapter- 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
Description copied from interface:MarshallerGets the adapter associated with the specified type. This is the reverse operation of theMarshaller.setAdapter(A)method.- Specified by:
getAdapterin interfaceMarshaller- Overrides:
getAdapterin classAbstractMarshallerImpl- Type Parameters:
A- the type of the adapter- Parameters:
type- The type of the adapter. The specified instance will be used whenXmlJavaTypeAdapter.value()refers to this type.- Returns:
- The adapter associated with the specified type.
-
setAttachmentMarshaller
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- Parameters:
am- the attachment marshaller to be set
-
getAttachmentMarshaller
- Specified by:
getAttachmentMarshallerin interfaceMarshaller- Overrides:
getAttachmentMarshallerin classAbstractMarshallerImpl
-
getSchema
Description copied from interface:MarshallerGet the JAXPSchemaobject 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
Description copied from interface:MarshallerSpecify the JAXPSchemaobject 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
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 Jakarta XML Binding 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
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
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
-