Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxws/src/share/jaxws_classes/javax/xml/bind/Marshaller.java
38890 views
/*1* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.xml.bind;2627import javax.xml.bind.annotation.XmlRootElement;28import javax.xml.bind.annotation.adapters.XmlAdapter;29import javax.xml.bind.attachment.AttachmentMarshaller;30import javax.xml.validation.Schema;31import java.io.File;3233/**34* <p>35* The <tt>Marshaller</tt> class is responsible for governing the process36* of serializing Java content trees back into XML data. It provides the basic37* marshalling methods:38*39* <p>40* <i>Assume the following setup code for all following code fragments:</i>41* <blockquote>42* <pre>43* JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );44* Unmarshaller u = jc.createUnmarshaller();45* Object element = u.unmarshal( new File( "foo.xml" ) );46* Marshaller m = jc.createMarshaller();47* </pre>48* </blockquote>49*50* <p>51* Marshalling to a File:52* <blockquote>53* <pre>54* OutputStream os = new FileOutputStream( "nosferatu.xml" );55* m.marshal( element, os );56* </pre>57* </blockquote>58*59* <p>60* Marshalling to a SAX ContentHandler:61* <blockquote>62* <pre>63* // assume MyContentHandler instanceof ContentHandler64* m.marshal( element, new MyContentHandler() );65* </pre>66* </blockquote>67*68* <p>69* Marshalling to a DOM Node:70* <blockquote>71* <pre>72* DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();73* dbf.setNamespaceAware(true);74* DocumentBuilder db = dbf.newDocumentBuilder();75* Document doc = db.newDocument();76*77* m.marshal( element, doc );78* </pre>79* </blockquote>80*81* <p>82* Marshalling to a java.io.OutputStream:83* <blockquote>84* <pre>85* m.marshal( element, System.out );86* </pre>87* </blockquote>88*89* <p>90* Marshalling to a java.io.Writer:91* <blockquote>92* <pre>93* m.marshal( element, new PrintWriter( System.out ) );94* </pre>95* </blockquote>96*97* <p>98* Marshalling to a javax.xml.transform.SAXResult:99* <blockquote>100* <pre>101* // assume MyContentHandler instanceof ContentHandler102* SAXResult result = new SAXResult( new MyContentHandler() );103*104* m.marshal( element, result );105* </pre>106* </blockquote>107*108* <p>109* Marshalling to a javax.xml.transform.DOMResult:110* <blockquote>111* <pre>112* DOMResult result = new DOMResult();113*114* m.marshal( element, result );115* </pre>116* </blockquote>117*118* <p>119* Marshalling to a javax.xml.transform.StreamResult:120* <blockquote>121* <pre>122* StreamResult result = new StreamResult( System.out );123*124* m.marshal( element, result );125* </pre>126* </blockquote>127*128* <p>129* Marshalling to a javax.xml.stream.XMLStreamWriter:130* <blockquote>131* <pre>132* XMLStreamWriter xmlStreamWriter =133* XMLOutputFactory.newInstance().createXMLStreamWriter( ... );134*135* m.marshal( element, xmlStreamWriter );136* </pre>137* </blockquote>138*139* <p>140* Marshalling to a javax.xml.stream.XMLEventWriter:141* <blockquote>142* <pre>143* XMLEventWriter xmlEventWriter =144* XMLOutputFactory.newInstance().createXMLEventWriter( ... );145*146* m.marshal( element, xmlEventWriter );147* </pre>148* </blockquote>149*150* <p>151* <a name="elementMarshalling"></a>152* <b>Marshalling content tree rooted by a JAXB element</b><br>153* <blockquote>154* The first parameter of the overloaded155* <tt>Marshaller.marshal(java.lang.Object, ...)</tt> methods must be a156* JAXB element as computed by157* {@link JAXBIntrospector#isElement(java.lang.Object)};158* otherwise, a <tt>Marshaller.marshal</tt> method must throw a159* {@link MarshalException}. There exist two mechanisms160* to enable marshalling an instance that is not a JAXB element.161* One method is to wrap the instance as a value of a {@link JAXBElement},162* and pass the wrapper element as the first parameter to163* a <tt>Marshaller.marshal</tt> method. For java to schema binding, it164* is also possible to simply annotate the instance's class with165* @{@link XmlRootElement}.166* </blockquote>167*168* <p>169* <b>Encoding</b><br>170* <blockquote>171* By default, the Marshaller will use UTF-8 encoding when generating XML data172* to a <tt>java.io.OutputStream</tt>, or a <tt>java.io.Writer</tt>. Use the173* {@link #setProperty(String,Object) setProperty} API to change the output174* encoding used during these marshal operations. Client applications are175* expected to supply a valid character encoding name as defined in the176* <a href="http://www.w3.org/TR/2000/REC-xml-20001006#charencoding">W3C XML 1.0177* Recommendation</a> and supported by your Java Platform</a>.178* </blockquote>179*180* <p>181* <b>Validation and Well-Formedness</b><br>182* <blockquote>183* <p>184* Client applications are not required to validate the Java content tree prior185* to calling any of the marshal API's. Furthermore, there is no requirement186* that the Java content tree be valid with respect to its original schema in187* order to marshal it back into XML data. Different JAXB Providers will188* support marshalling invalid Java content trees at varying levels, however189* all JAXB Providers must be able to marshal a valid content tree back to190* XML data. A JAXB Provider must throw a <tt>MarshalException</tt> when it191* is unable to complete the marshal operation due to invalid content. Some192* JAXB Providers will fully allow marshalling invalid content, others will fail193* on the first validation error.194* <p>195* Even when schema validation is not explictly enabled for the marshal operation,196* it is possible that certain types of validation events will be detected197* during the operation. Validation events will be reported to the registered198* event handler. If the client application has not registered an event handler199* prior to invoking one of the marshal API's, then events will be delivered to200* a default event handler which will terminate the marshal operation after201* encountering the first error or fatal error. Note that for JAXB 2.0 and202* later versions, {@link javax.xml.bind.helpers.DefaultValidationEventHandler} is203* no longer used.204*205* </blockquote>206*207* <p>208* <a name="supportedProps"></a>209* <b>Supported Properties</b><br>210* <blockquote>211* <p>212* All JAXB Providers are required to support the following set of properties.213* Some providers may support additional properties.214* <dl>215* <dt><tt>jaxb.encoding</tt> - value must be a java.lang.String</dt>216* <dd>The output encoding to use when marshalling the XML data. The217* Marshaller will use "UTF-8" by default if this property is not218* specified.</dd>219* <dt><tt>jaxb.formatted.output</tt> - value must be a java.lang.Boolean</dt>220* <dd>This property controls whether or not the Marshaller will format221* the resulting XML data with line breaks and indentation. A222* true value for this property indicates human readable indented223* xml data, while a false value indicates unformatted xml data.224* The Marshaller will default to false (unformatted) if this225* property is not specified.</dd>226* <dt><tt>jaxb.schemaLocation</tt> - value must be a java.lang.String</dt>227* <dd>This property allows the client application to specify an228* xsi:schemaLocation attribute in the generated XML data. The format of229* the schemaLocation attribute value is discussed in an easy to230* understand, non-normative form in231* <a href="http://www.w3.org/TR/xmlschema-0/#schemaLocation">Section 5.6232* of the W3C XML Schema Part 0: Primer</a> and specified in233* <a href="http://www.w3.org/TR/xmlschema-1/#Instance_Document_Constructions">234* Section 2.6 of the W3C XML Schema Part 1: Structures</a>.</dd>235* <dt><tt>jaxb.noNamespaceSchemaLocation</tt> - value must be a java.lang.String</dt>236* <dd>This property allows the client application to specify an237* xsi:noNamespaceSchemaLocation attribute in the generated XML238* data. The format of the schemaLocation attribute value is discussed in239* an easy to understand, non-normative form in240* <a href="http://www.w3.org/TR/xmlschema-0/#schemaLocation">Section 5.6241* of the W3C XML Schema Part 0: Primer</a> and specified in242* <a href="http://www.w3.org/TR/xmlschema-1/#Instance_Document_Constructions">243* Section 2.6 of the W3C XML Schema Part 1: Structures</a>.</dd>244* <dt><tt>jaxb.fragment</tt> - value must be a java.lang.Boolean</dt>245* <dd>This property determines whether or not document level events will be246* generated by the Marshaller. If the property is not specified, the247* default is <tt>false</tt>. This property has different implications depending248* on which marshal api you are using - when this property is set to true:<br>249* <ul>250* <li>{@link #marshal(Object,org.xml.sax.ContentHandler) marshal(Object,ContentHandler)} - the Marshaller won't251* invoke {@link org.xml.sax.ContentHandler#startDocument()} and252* {@link org.xml.sax.ContentHandler#endDocument()}.</li>253* <li>{@link #marshal(Object,org.w3c.dom.Node) marshal(Object,Node)} - the property has no effect on this254* API.</li>255* <li>{@link #marshal(Object,java.io.OutputStream) marshal(Object,OutputStream)} - the Marshaller won't256* generate an xml declaration.</li>257* <li>{@link #marshal(Object,java.io.Writer) marshal(Object,Writer)} - the Marshaller won't258* generate an xml declaration.</li>259* <li>{@link #marshal(Object,javax.xml.transform.Result) marshal(Object,Result)} - depends on the kind of260* Result object, see semantics for Node, ContentHandler, and Stream APIs</li>261* <li>{@link #marshal(Object,javax.xml.stream.XMLEventWriter) marshal(Object,XMLEventWriter)} - the262* Marshaller will not generate {@link javax.xml.stream.events.XMLEvent#START_DOCUMENT} and263* {@link javax.xml.stream.events.XMLEvent#END_DOCUMENT} events.</li>264* <li>{@link #marshal(Object,javax.xml.stream.XMLStreamWriter) marshal(Object,XMLStreamWriter)} - the265* Marshaller will not generate {@link javax.xml.stream.events.XMLEvent#START_DOCUMENT} and266* {@link javax.xml.stream.events.XMLEvent#END_DOCUMENT} events.</li>267* </ul>268* </dd>269* </dl>270* </blockquote>271*272* <p>273* <a name="marshalEventCallback"></a>274* <b>Marshal Event Callbacks</b><br>275* <blockquote>276* "The {@link Marshaller} provides two styles of callback mechanisms277* that allow application specific processing during key points in the278* unmarshalling process. In 'class defined' event callbacks, application279* specific code placed in JAXB mapped classes is triggered during280* marshalling. 'External listeners' allow for centralized processing281* of marshal events in one callback method rather than by type event callbacks.282*283* <p>284* Class defined event callback methods allow any JAXB mapped class to specify285* its own specific callback methods by defining methods with the following method signatures:286* <blockquote>287* <pre>288* // Invoked by Marshaller after it has created an instance of this object.289* boolean beforeMarshal(Marshaller);290*291* // Invoked by Marshaller after it has marshalled all properties of this object.292* void afterMarshal(Marshaller);293* </pre>294* </blockquote>295* The class defined event callback methods should be used when the callback method requires296* access to non-public methods and/or fields of the class.297* <p>298* The external listener callback mechanism enables the registration of a {@link Listener}299* instance with a {@link Marshaller#setListener(Listener)}. The external listener receives all callback events,300* allowing for more centralized processing than per class defined callback methods.301* <p>302* The 'class defined' and external listener event callback methods are independent of each other,303* both can be called for one event. The invocation ordering when both listener callback methods exist is304* defined in {@link Listener#beforeMarshal(Object)} and {@link Listener#afterMarshal(Object)}.305* <p>306* An event callback method throwing an exception terminates the current marshal process.307* </blockquote>308*309* @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li><li>Ryan Shoemaker, Sun Microsystems, Inc.</li><li>Joe Fialli, Sun Microsystems, Inc.</li></ul>310* @see JAXBContext311* @see Validator312* @see Unmarshaller313* @since JAXB1.0314*/315public interface Marshaller {316317/**318* The name of the property used to specify the output encoding in319* the marshalled XML data.320*/321public static final String JAXB_ENCODING =322"jaxb.encoding";323324/**325* The name of the property used to specify whether or not the marshalled326* XML data is formatted with linefeeds and indentation.327*/328public static final String JAXB_FORMATTED_OUTPUT =329"jaxb.formatted.output";330331/**332* The name of the property used to specify the xsi:schemaLocation333* attribute value to place in the marshalled XML output.334*/335public static final String JAXB_SCHEMA_LOCATION =336"jaxb.schemaLocation";337338/**339* The name of the property used to specify the340* xsi:noNamespaceSchemaLocation attribute value to place in the marshalled341* XML output.342*/343public static final String JAXB_NO_NAMESPACE_SCHEMA_LOCATION =344"jaxb.noNamespaceSchemaLocation";345346/**347* The name of the property used to specify whether or not the marshaller348* will generate document level events (ie calling startDocument or endDocument).349*/350public static final String JAXB_FRAGMENT =351"jaxb.fragment";352353/**354* Marshal the content tree rooted at <tt>jaxbElement</tt> into the specified355* <tt>javax.xml.transform.Result</tt>.356*357* <p>358* All JAXB Providers must at least support359* {@link javax.xml.transform.dom.DOMResult},360* {@link javax.xml.transform.sax.SAXResult}, and361* {@link javax.xml.transform.stream.StreamResult}. It can362* support other derived classes of <tt>Result</tt> as well.363*364* @param jaxbElement365* The root of content tree to be marshalled.366* @param result367* XML will be sent to this Result368*369* @throws JAXBException370* If any unexpected problem occurs during the marshalling.371* @throws MarshalException372* If the {@link ValidationEventHandler ValidationEventHandler}373* returns false from its <tt>handleEvent</tt> method or the374* <tt>Marshaller</tt> is unable to marshal <tt>obj</tt> (or any375* object reachable from <tt>obj</tt>). See <a href="#elementMarshalling">376* Marshalling a JAXB element</a>.377* @throws IllegalArgumentException378* If any of the method parameters are null379*/380public void marshal( Object jaxbElement, javax.xml.transform.Result result )381throws JAXBException;382383/**384* Marshal the content tree rooted at <tt>jaxbElement</tt> into an output stream.385*386* @param jaxbElement387* The root of content tree to be marshalled.388* @param os389* XML will be added to this stream.390*391* @throws JAXBException392* If any unexpected problem occurs during the marshalling.393* @throws MarshalException394* If the {@link ValidationEventHandler ValidationEventHandler}395* returns false from its <tt>handleEvent</tt> method or the396* <tt>Marshaller</tt> is unable to marshal <tt>obj</tt> (or any397* object reachable from <tt>obj</tt>). See <a href="#elementMarshalling">398* Marshalling a JAXB element</a>.399* @throws IllegalArgumentException400* If any of the method parameters are null401*/402public void marshal( Object jaxbElement, java.io.OutputStream os )403throws JAXBException;404405/**406* Marshal the content tree rooted at <tt>jaxbElement</tt> into a file.407*408* @param jaxbElement409* The root of content tree to be marshalled.410* @param output411* File to be written. If this file already exists, it will be overwritten.412*413* @throws JAXBException414* If any unexpected problem occurs during the marshalling.415* @throws MarshalException416* If the {@link ValidationEventHandler ValidationEventHandler}417* returns false from its <tt>handleEvent</tt> method or the418* <tt>Marshaller</tt> is unable to marshal <tt>obj</tt> (or any419* object reachable from <tt>obj</tt>). See <a href="#elementMarshalling">420* Marshalling a JAXB element</a>.421* @throws IllegalArgumentException422* If any of the method parameters are null423* @since JAXB2.1424*/425public void marshal( Object jaxbElement, File output )426throws JAXBException;427428/**429* Marshal the content tree rooted at <tt>jaxbElement</tt> into a Writer.430*431* @param jaxbElement432* The root of content tree to be marshalled.433* @param writer434* XML will be sent to this writer.435*436* @throws JAXBException437* If any unexpected problem occurs during the marshalling.438* @throws MarshalException439* If the {@link ValidationEventHandler ValidationEventHandler}440* returns false from its <tt>handleEvent</tt> method or the441* <tt>Marshaller</tt> is unable to marshal <tt>obj</tt> (or any442* object reachable from <tt>obj</tt>). See <a href="#elementMarshalling">443* Marshalling a JAXB element</a>.444* @throws IllegalArgumentException445* If any of the method parameters are null446*/447public void marshal( Object jaxbElement, java.io.Writer writer )448throws JAXBException;449450/**451* Marshal the content tree rooted at <tt>jaxbElement</tt> into SAX2 events.452*453* @param jaxbElement454* The root of content tree to be marshalled.455* @param handler456* XML will be sent to this handler as SAX2 events.457*458* @throws JAXBException459* If any unexpected problem occurs during the marshalling.460* @throws MarshalException461* If the {@link ValidationEventHandler ValidationEventHandler}462* returns false from its <tt>handleEvent</tt> method or the463* <tt>Marshaller</tt> is unable to marshal <tt>obj</tt> (or any464* object reachable from <tt>obj</tt>). See <a href="#elementMarshalling">465* Marshalling a JAXB element</a>.466* @throws IllegalArgumentException467* If any of the method parameters are null468*/469public void marshal( Object jaxbElement, org.xml.sax.ContentHandler handler )470throws JAXBException;471472/**473* Marshal the content tree rooted at <tt>jaxbElement</tt> into a DOM tree.474*475* @param jaxbElement476* The content tree to be marshalled.477* @param node478* DOM nodes will be added as children of this node.479* This parameter must be a Node that accepts children480* ({@link org.w3c.dom.Document},481* {@link org.w3c.dom.DocumentFragment}, or482* {@link org.w3c.dom.Element})483*484* @throws JAXBException485* If any unexpected problem occurs during the marshalling.486* @throws MarshalException487* If the {@link ValidationEventHandler ValidationEventHandler}488* returns false from its <tt>handleEvent</tt> method or the489* <tt>Marshaller</tt> is unable to marshal <tt>jaxbElement</tt> (or any490* object reachable from <tt>jaxbElement</tt>). See <a href="#elementMarshalling">491* Marshalling a JAXB element</a>.492* @throws IllegalArgumentException493* If any of the method parameters are null494*/495public void marshal( Object jaxbElement, org.w3c.dom.Node node )496throws JAXBException;497498/**499* Marshal the content tree rooted at <tt>jaxbElement</tt> into a500* {@link javax.xml.stream.XMLStreamWriter}.501*502* @param jaxbElement503* The content tree to be marshalled.504* @param writer505* XML will be sent to this writer.506*507* @throws JAXBException508* If any unexpected problem occurs during the marshalling.509* @throws MarshalException510* If the {@link ValidationEventHandler ValidationEventHandler}511* returns false from its <tt>handleEvent</tt> method or the512* <tt>Marshaller</tt> is unable to marshal <tt>obj</tt> (or any513* object reachable from <tt>obj</tt>). See <a href="#elementMarshalling">514* Marshalling a JAXB element</a>.515* @throws IllegalArgumentException516* If any of the method parameters are null517* @since JAXB 2.0518*/519public void marshal( Object jaxbElement, javax.xml.stream.XMLStreamWriter writer )520throws JAXBException;521522/**523* Marshal the content tree rooted at <tt>jaxbElement</tt> into a524* {@link javax.xml.stream.XMLEventWriter}.525*526* @param jaxbElement527* The content tree rooted at jaxbElement to be marshalled.528* @param writer529* XML will be sent to this writer.530*531* @throws JAXBException532* If any unexpected problem occurs during the marshalling.533* @throws MarshalException534* If the {@link ValidationEventHandler ValidationEventHandler}535* returns false from its <tt>handleEvent</tt> method or the536* <tt>Marshaller</tt> is unable to marshal <tt>obj</tt> (or any537* object reachable from <tt>obj</tt>). See <a href="#elementMarshalling">538* Marshalling a JAXB element</a>.539* @throws IllegalArgumentException540* If any of the method parameters are null541* @since JAXB 2.0542*/543public void marshal( Object jaxbElement, javax.xml.stream.XMLEventWriter writer )544throws JAXBException;545546/**547* Get a DOM tree view of the content tree(Optional).548*549* If the returned DOM tree is updated, these changes are also550* visible in the content tree.551* Use {@link #marshal(Object, org.w3c.dom.Node)} to force552* a deep copy of the content tree to a DOM representation.553*554* @param contentTree - JAXB Java representation of XML content555*556* @return the DOM tree view of the contentTree557*558* @throws UnsupportedOperationException559* If the JAXB provider implementation does not support a560* DOM view of the content tree561*562* @throws IllegalArgumentException563* If any of the method parameters are null564*565* @throws JAXBException566* If any unexpected problem occurs567*568*/569public org.w3c.dom.Node getNode( java.lang.Object contentTree )570throws JAXBException;571572/**573* Set the particular property in the underlying implementation of574* <tt>Marshaller</tt>. This method can only be used to set one of575* the standard JAXB defined properties above or a provider specific576* property. Attempting to set an undefined property will result in577* a PropertyException being thrown. See <a href="#supportedProps">578* Supported Properties</a>.579*580* @param name the name of the property to be set. This value can either581* be specified using one of the constant fields or a user582* supplied string.583* @param value the value of the property to be set584*585* @throws PropertyException when there is an error processing the given586* property or value587* @throws IllegalArgumentException588* If the name parameter is null589*/590public void setProperty( String name, Object value )591throws PropertyException;592593/**594* Get the particular property in the underlying implementation of595* <tt>Marshaller</tt>. This method can only be used to get one of596* the standard JAXB defined properties above or a provider specific597* property. Attempting to get an undefined property will result in598* a PropertyException being thrown. See <a href="#supportedProps">599* Supported Properties</a>.600*601* @param name the name of the property to retrieve602* @return the value of the requested property603*604* @throws PropertyException605* when there is an error retrieving the given property or value606* property name607* @throws IllegalArgumentException608* If the name parameter is null609*/610public Object getProperty( String name ) throws PropertyException;611612/**613* Allow an application to register a validation event handler.614* <p>615* The validation event handler will be called by the JAXB Provider if any616* validation errors are encountered during calls to any of the marshal617* API's. If the client application does not register a validation event618* handler before invoking one of the marshal methods, then validation619* events will be handled by the default event handler which will terminate620* the marshal operation after the first error or fatal error is encountered.621* <p>622* Calling this method with a null parameter will cause the Marshaller623* to revert back to the default default event handler.624*625* @param handler the validation event handler626* @throws JAXBException if an error was encountered while setting the627* event handler628*/629public void setEventHandler( ValidationEventHandler handler )630throws JAXBException;631632/**633* Return the current event handler or the default event handler if one634* hasn't been set.635*636* @return the current ValidationEventHandler or the default event handler637* if it hasn't been set638* @throws JAXBException if an error was encountered while getting the639* current event handler640*/641public ValidationEventHandler getEventHandler()642throws JAXBException;643644645646/**647* Associates a configured instance of {@link XmlAdapter} with this marshaller.648*649* <p>650* This is a convenience method that invokes <code>setAdapter(adapter.getClass(),adapter);</code>.651*652* @see #setAdapter(Class,XmlAdapter)653* @throws IllegalArgumentException654* if the adapter parameter is null.655* @throws UnsupportedOperationException656* if invoked agains a JAXB 1.0 implementation.657* @since JAXB 2.0658*/659public void setAdapter( XmlAdapter adapter );660661/**662* Associates a configured instance of {@link XmlAdapter} with this marshaller.663*664* <p>665* Every marshaller internally maintains a666* {@link java.util.Map}<{@link Class},{@link XmlAdapter}>,667* which it uses for marshalling classes whose fields/methods are annotated668* with {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter}.669*670* <p>671* This method allows applications to use a configured instance of {@link XmlAdapter}.672* When an instance of an adapter is not given, a marshaller will create673* one by invoking its default constructor.674*675* @param type676* The type of the adapter. The specified instance will be used when677* {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter#value()}678* refers to this type.679* @param adapter680* The instance of the adapter to be used. If null, it will un-register681* the current adapter set for this type.682* @throws IllegalArgumentException683* if the type parameter is null.684* @throws UnsupportedOperationException685* if invoked agains a JAXB 1.0 implementation.686* @since JAXB 2.0687*/688public <A extends XmlAdapter> void setAdapter( Class<A> type, A adapter );689690/**691* Gets the adapter associated with the specified type.692*693* This is the reverse operation of the {@link #setAdapter} method.694*695* @throws IllegalArgumentException696* if the type parameter is null.697* @throws UnsupportedOperationException698* if invoked agains a JAXB 1.0 implementation.699* @since JAXB 2.0700*/701public <A extends XmlAdapter> A getAdapter( Class<A> type );702703704/**705* <p>Associate a context that enables binary data within an XML document706* to be transmitted as XML-binary optimized attachment.707* The attachment is referenced from the XML document content model708* by content-id URIs(cid) references stored within the xml document.709*710* @throws IllegalStateException if attempt to concurrently call this711* method during a marshal operation.712*/713void setAttachmentMarshaller(AttachmentMarshaller am);714715AttachmentMarshaller getAttachmentMarshaller();716717/**718* Specify the JAXP 1.3 {@link javax.xml.validation.Schema Schema}719* object that should be used to validate subsequent marshal operations720* against. Passing null into this method will disable validation.721*722* <p>723* This method allows the caller to validate the marshalled XML as it's marshalled.724*725* <p>726* Initially this property is set to <tt>null</tt>.727*728* @param schema Schema object to validate marshal operations against or null to disable validation729* @throws UnsupportedOperationException could be thrown if this method is730* invoked on an Marshaller created from a JAXBContext referencing731* JAXB 1.0 mapped classes732* @since JAXB2.0733*/734public void setSchema( Schema schema );735736/**737* Get the JAXP 1.3 {@link javax.xml.validation.Schema Schema} object738* being used to perform marshal-time validation. If there is no739* Schema set on the marshaller, then this method will return null740* indicating that marshal-time validation will not be performed.741*742* @return the Schema object being used to perform marshal-time743* validation or null if not present.744* @throws UnsupportedOperationException could be thrown if this method is745* invoked on an Marshaller created from a JAXBContext referencing746* JAXB 1.0 mapped classes747* @since JAXB2.0748*/749public Schema getSchema();750751/**752* <p/>753* Register an instance of an implementation of this class with a {@link Marshaller} to externally listen754* for marshal events.755* <p/>756* <p/>757* This class enables pre and post processing of each marshalled object.758* The event callbacks are called when marshalling from an instance that maps to an xml element or759* complex type definition. The event callbacks are not called when marshalling from an instance of a760* Java datatype that represents a simple type definition.761* <p/>762* <p/>763* External listener is one of two different mechanisms for defining marshal event callbacks.764* See <a href="Marshaller.html#marshalEventCallback">Marshal Event Callbacks</a> for an overview.765*766* @see Marshaller#setListener(Listener)767* @see Marshaller#getListener()768* @since JAXB2.0769*/770public static abstract class Listener {771/**772* <p/>773* Callback method invoked before marshalling from <tt>source</tt> to XML.774* <p/>775* <p/>776* This method is invoked just before marshalling process starts to marshal <tt>source</tt>.777* Note that if the class of <tt>source</tt> defines its own <tt>beforeMarshal</tt> method,778* the class specific callback method is invoked just before this method is invoked.779*780* @param source instance of JAXB mapped class prior to marshalling from it.781*/782public void beforeMarshal(Object source) {783}784785/**786* <p/>787* Callback method invoked after marshalling <tt>source</tt> to XML.788* <p/>789* <p/>790* This method is invoked after <tt>source</tt> and all its descendants have been marshalled.791* Note that if the class of <tt>source</tt> defines its own <tt>afterMarshal</tt> method,792* the class specific callback method is invoked just before this method is invoked.793*794* @param source instance of JAXB mapped class after marshalling it.795*/796public void afterMarshal(Object source) {797}798}799800/**801* <p>802* Register marshal event callback {@link Listener} with this {@link Marshaller}.803*804* <p>805* There is only one Listener per Marshaller. Setting a Listener replaces the previous set Listener.806* One can unregister current Listener by setting listener to <tt>null</tt>.807*808* @param listener an instance of a class that implements {@link Listener}809* @since JAXB2.0810*/811public void setListener(Listener listener);812813/**814* <p>Return {@link Listener} registered with this {@link Marshaller}.815*816* @return registered {@link Listener} or <code>null</code> if no Listener is registered with this Marshaller.817* @since JAXB2.0818*/819public Listener getListener();820}821822823