Class AbstractMarshallerImpl

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractMarshallerImpl()
      Do-nothing constructor for the derived classes.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <A extends XmlAdapter<?,​?>>
      A
      getAdapter​(java.lang.Class<A> type)
      Gets the adapter associated with the specified type.
      AttachmentMarshaller getAttachmentMarshaller()  
      protected java.lang.String getEncoding()
      Convenience method for getting the current output encoding.
      ValidationEventHandler getEventHandler()
      Return the current event handler or the default event handler if one hasn't been set.
      protected java.lang.String getJavaEncoding​(java.lang.String encoding)
      Gets the corresponding Java encoding name from an IANA name.
      Marshaller.Listener getListener()
      Return Marshaller.Listener registered with this Marshaller.
      org.w3c.dom.Node getNode​(java.lang.Object obj)
      By default, the getNode method is unsupported and throw an UnsupportedOperationException.
      protected java.lang.String getNoNSSchemaLocation()
      Convenience method for getting the current noNamespaceSchemaLocation.
      java.lang.Object getProperty​(java.lang.String name)
      Default implementation of the getProperty method handles the four defined properties in Marshaller.
      javax.xml.validation.Schema getSchema()
      Get the JAXP Schema object being used to perform marshal-time validation.
      protected java.lang.String getSchemaLocation()
      Convenience method for getting the current schemaLocation.
      protected boolean isFormattedOutput()
      Convenience method for getting the formatted output flag.
      protected boolean isFragment()
      Convenience method for getting the fragment flag.
      void marshal​(java.lang.Object jaxbElement, java.io.File output)
      Marshal the content tree rooted at jaxbElement into a file.
      void marshal​(java.lang.Object obj, java.io.OutputStream os)
      Marshal the content tree rooted at jaxbElement into an output stream.
      void marshal​(java.lang.Object obj, java.io.Writer w)
      Marshal the content tree rooted at jaxbElement into a Writer.
      void marshal​(java.lang.Object obj, javax.xml.stream.XMLEventWriter writer)
      Marshal the content tree rooted at jaxbElement into a XMLEventWriter.
      void marshal​(java.lang.Object obj, javax.xml.stream.XMLStreamWriter writer)
      Marshal the content tree rooted at jaxbElement into a XMLStreamWriter.
      void marshal​(java.lang.Object obj, org.w3c.dom.Node node)
      Marshal the content tree rooted at jaxbElement into a DOM tree.
      void marshal​(java.lang.Object obj, org.xml.sax.ContentHandler handler)
      Marshal the content tree rooted at jaxbElement into SAX2 events.
      <A extends XmlAdapter<?,​?>>
      void
      setAdapter​(A adapter)
      Associates a configured instance of XmlAdapter with this marshaller.
      <A extends XmlAdapter<?,​?>>
      void
      setAdapter​(java.lang.Class<A> type, A adapter)
      Associates a configured instance of XmlAdapter with this marshaller.
      void setAttachmentMarshaller​(AttachmentMarshaller am)
      Associate a context that enables binary data within an XML document to be transmitted as XML-binary optimized attachment.
      protected void setEncoding​(java.lang.String encoding)
      Convenience method for setting the output encoding.
      void setEventHandler​(ValidationEventHandler handler)
      Allow an application to register a validation event handler.
      protected void setFormattedOutput​(boolean v)
      Convenience method for setting the formatted output flag.
      protected void setFragment​(boolean v)
      Convenience method for setting the fragment flag.
      void setListener​(Marshaller.Listener listener)
      Register marshal event callback Marshaller.Listener with this Marshaller.
      protected void setNoNSSchemaLocation​(java.lang.String location)
      Convenience method for setting the noNamespaceSchemaLocation.
      void setProperty​(java.lang.String name, java.lang.Object value)
      Default implementation of the setProperty method handles the four defined properties in Marshaller.
      void setSchema​(javax.xml.validation.Schema schema)
      Specify the JAXP Schema object that should be used to validate subsequent marshal operations against.
      protected void setSchemaLocation​(java.lang.String location)
      Convenience method for setting the schemaLocation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractMarshallerImpl

        protected AbstractMarshallerImpl()
        Do-nothing constructor for the derived classes.
    • Method Detail

      • marshal

        public final void marshal​(java.lang.Object obj,
                                  java.io.OutputStream os)
                           throws JAXBException
        Description copied from interface: Marshaller
        Marshal the content tree rooted at jaxbElement into an output stream.
        Specified by:
        marshal in interface Marshaller
        Parameters:
        obj - The root of content tree to be marshalled.
        os - XML will be added to this stream.
        Throws:
        JAXBException - If any unexpected problem occurs during the marshalling.
        MarshalException - If the ValidationEventHandler returns false from its handleEvent method or the Marshaller is unable to marshal jaxbElement (or any object reachable from jaxbElement). See Marshalling a Jakarta XML Binding element.
      • marshal

        public void marshal​(java.lang.Object jaxbElement,
                            java.io.File output)
                     throws JAXBException
        Description copied from interface: Marshaller
        Marshal the content tree rooted at jaxbElement into a file.
        Specified by:
        marshal in interface Marshaller
        Parameters:
        jaxbElement - The root of content tree to be marshalled.
        output - File to be written. If this file already exists, it will be overwritten.
        Throws:
        JAXBException - If any unexpected problem occurs during the marshalling.
        MarshalException - If the ValidationEventHandler returns false from its handleEvent method or the Marshaller is unable to marshal jaxbElement (or any object reachable from jaxbElement). See Marshalling a Jakarta XML Binding element.
      • marshal

        public final void marshal​(java.lang.Object obj,
                                  java.io.Writer w)
                           throws JAXBException
        Description copied from interface: Marshaller
        Marshal the content tree rooted at jaxbElement into a Writer.
        Specified by:
        marshal in interface Marshaller
        Parameters:
        obj - The root of content tree to be marshalled.
        w - XML will be sent to this writer.
        Throws:
        JAXBException - If any unexpected problem occurs during the marshalling.
        MarshalException - If the ValidationEventHandler returns false from its handleEvent method or the Marshaller is unable to marshal jaxbElement (or any object reachable from jaxbElement). See Marshalling a Jakarta XML Binding element.
      • marshal

        public final void marshal​(java.lang.Object obj,
                                  org.xml.sax.ContentHandler handler)
                           throws JAXBException
        Description copied from interface: Marshaller
        Marshal the content tree rooted at jaxbElement into SAX2 events.
        Specified by:
        marshal in interface Marshaller
        Parameters:
        obj - The root of content tree to be marshalled.
        handler - XML will be sent to this handler as SAX2 events.
        Throws:
        JAXBException - If any unexpected problem occurs during the marshalling.
        MarshalException - If the ValidationEventHandler returns false from its handleEvent method or the Marshaller is unable to marshal jaxbElement (or any object reachable from jaxbElement). See Marshalling a Jakarta XML Binding element.
      • marshal

        public final void marshal​(java.lang.Object obj,
                                  org.w3c.dom.Node node)
                           throws JAXBException
        Description copied from interface: Marshaller
        Marshal the content tree rooted at jaxbElement into a DOM tree.
        Specified by:
        marshal in interface Marshaller
        Parameters:
        obj - The content tree to be marshalled.
        node - DOM nodes will be added as children of this node. This parameter must be a Node that accepts children (Document, DocumentFragment, or Element)
        Throws:
        JAXBException - If any unexpected problem occurs during the marshalling.
        MarshalException - If the ValidationEventHandler returns false from its handleEvent method or the Marshaller is unable to marshal jaxbElement (or any object reachable from jaxbElement). See Marshalling a Jakarta XML Binding element.
      • getNode

        public org.w3c.dom.Node getNode​(java.lang.Object obj)
                                 throws JAXBException
        By default, the getNode method is unsupported and throw an UnsupportedOperationException. Implementations that choose to support this method must override this method.
        Specified by:
        getNode in interface Marshaller
        Parameters:
        obj - - Jakarta XML Binding Java representation of XML content
        Returns:
        the DOM tree view of the contentTree
        Throws:
        JAXBException - If any unexpected problem occurs
      • getEncoding

        protected java.lang.String getEncoding()
        Convenience method for getting the current output encoding.
        Returns:
        the current encoding or "UTF-8" if it hasn't been set.
      • setEncoding

        protected void setEncoding​(java.lang.String encoding)
        Convenience method for setting the output encoding.
        Parameters:
        encoding - a valid encoding as specified in the Marshaller class documentation
      • getSchemaLocation

        protected java.lang.String getSchemaLocation()
        Convenience method for getting the current schemaLocation.
        Returns:
        the current schemaLocation or null if it hasn't been set
      • setSchemaLocation

        protected void setSchemaLocation​(java.lang.String location)
        Convenience method for setting the schemaLocation.
        Parameters:
        location - the schemaLocation value
      • getNoNSSchemaLocation

        protected java.lang.String getNoNSSchemaLocation()
        Convenience method for getting the current noNamespaceSchemaLocation.
        Returns:
        the current noNamespaceSchemaLocation or null if it hasn't been set
      • setNoNSSchemaLocation

        protected void setNoNSSchemaLocation​(java.lang.String location)
        Convenience method for setting the noNamespaceSchemaLocation.
        Parameters:
        location - the noNamespaceSchemaLocation value
      • isFormattedOutput

        protected boolean isFormattedOutput()
        Convenience method for getting the formatted output flag.
        Returns:
        the current value of the formatted output flag or false if it hasn't been set.
      • setFormattedOutput

        protected void setFormattedOutput​(boolean v)
        Convenience method for setting the formatted output flag.
        Parameters:
        v - value of the formatted output flag.
      • isFragment

        protected boolean isFragment()
        Convenience method for getting the fragment flag.
        Returns:
        the current value of the fragment flag or false if it hasn't been set.
      • setFragment

        protected void setFragment​(boolean v)
        Convenience method for setting the fragment flag.
        Parameters:
        v - value of the fragment flag.
      • getJavaEncoding

        protected java.lang.String getJavaEncoding​(java.lang.String encoding)
                                            throws java.io.UnsupportedEncodingException
        Gets the corresponding Java encoding name from an IANA name. This method is a helper method for the derived class to convert encoding names.
        Throws:
        java.io.UnsupportedEncodingException - If this implementation couldn't find the Java encoding name.
      • setProperty

        public void setProperty​(java.lang.String name,
                                java.lang.Object value)
                         throws PropertyException
        Default 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:
        setProperty in interface Marshaller
        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
      • getProperty

        public java.lang.Object getProperty​(java.lang.String name)
                                     throws PropertyException
        Default 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:
        getProperty in interface Marshaller
        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
      • setEventHandler

        public void setEventHandler​(ValidationEventHandler handler)
                             throws JAXBException
        Description copied from interface: Marshaller
        Allow an application to register a validation event handler.

        The validation event handler will be called by the Jakarta XML Binding Provider if any validation errors are encountered during calls to any of the marshal API's. If the client application does not register a validation event handler before invoking one of the marshal methods, then validation events will be handled by the default event handler which will terminate the marshal operation after the first error or fatal error is encountered.

        Calling this method with a null parameter will cause the Marshaller to revert back to the default default event handler.

        Specified by:
        setEventHandler in interface Marshaller
        Parameters:
        handler - the validation event handler
        Throws:
        JAXBException - if an error was encountered while setting the event handler
        See Also:
        Marshaller.setEventHandler(ValidationEventHandler)
      • marshal

        public void marshal​(java.lang.Object obj,
                            javax.xml.stream.XMLEventWriter writer)
                     throws JAXBException
        Description copied from interface: Marshaller
        Marshal the content tree rooted at jaxbElement into a XMLEventWriter.
        Specified by:
        marshal in interface Marshaller
        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 the ValidationEventHandler returns false from its handleEvent method or the Marshaller is unable to marshal jaxbElement (or any object reachable from jaxbElement). See Marshalling a Jakarta XML Binding element.
      • marshal

        public void marshal​(java.lang.Object obj,
                            javax.xml.stream.XMLStreamWriter writer)
                     throws JAXBException
        Description copied from interface: Marshaller
        Marshal the content tree rooted at jaxbElement into a XMLStreamWriter.
        Specified by:
        marshal in interface Marshaller
        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 the ValidationEventHandler returns false from its handleEvent method or the Marshaller is unable to marshal jaxbElement (or any object reachable from jaxbElement). See Marshalling a Jakarta XML Binding element.
      • setSchema

        public void setSchema​(javax.xml.validation.Schema schema)
        Description copied from interface: Marshaller
        Specify the JAXP Schema object 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:
        setSchema in interface Marshaller
        Parameters:
        schema - Schema object to validate marshal operations against or null to disable validation
      • getSchema

        public javax.xml.validation.Schema getSchema()
        Description copied from interface: Marshaller
        Get the JAXP Schema object 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:
        getSchema in interface Marshaller
        Returns:
        the Schema object being used to perform marshal-time validation or null if not present.
      • setAdapter

        public <A extends XmlAdapter<?,​?>> void setAdapter​(A adapter)
        Description copied from interface: Marshaller
        Associates a configured instance of XmlAdapter with this marshaller.

        This is a convenience method that invokes setAdapter(adapter.getClass(),adapter);.

        Specified by:
        setAdapter in interface Marshaller
        Type Parameters:
        A - the type of the adapter
        Parameters:
        adapter - The instance of the adapter to be used. If null, it will un-register the current adapter set for this type.
        See Also:
        Marshaller.setAdapter(Class,XmlAdapter)
      • setAdapter

        public <A extends XmlAdapter<?,​?>> void setAdapter​(java.lang.Class<A> type,
                                                                 A adapter)
        Description copied from interface: Marshaller
        Associates a configured instance of XmlAdapter with this marshaller.

        Every marshaller internally maintains a Map<Class,XmlAdapter>, which it uses for marshalling classes whose fields/methods are annotated with XmlJavaTypeAdapter.

        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:
        setAdapter in interface Marshaller
        Type Parameters:
        A - the type of the adapter
        Parameters:
        type - The type of the adapter. The specified instance will be used when XmlJavaTypeAdapter.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​(java.lang.Class<A> type)
        Description copied from interface: Marshaller
        Gets the adapter associated with the specified type. This is the reverse operation of the Marshaller.setAdapter(A) method.
        Specified by:
        getAdapter in interface Marshaller
        Type Parameters:
        A - the type of the adapter
        Parameters:
        type - The type of the adapter. The specified instance will be used when XmlJavaTypeAdapter.value() refers to this type.
        Returns:
        The adapter associated with the specified type.
      • setAttachmentMarshaller

        public void setAttachmentMarshaller​(AttachmentMarshaller am)
        Description copied from interface: Marshaller
        Associate 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:
        setAttachmentMarshaller in interface Marshaller
        Parameters:
        am - the attachment marshaller to be set
      • setListener

        public void setListener​(Marshaller.Listener listener)
        Description copied from interface: Marshaller

        Register marshal event callback Marshaller.Listener with this Marshaller.

        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:
        setListener in interface Marshaller
        Parameters:
        listener - an instance of a class that implements Marshaller.Listener