Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxws/src/share/jaxws_classes/javax/xml/bind/JAXBContext.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 org.w3c.dom.Node;2829import java.util.Collections;30import java.util.Map;31import java.util.Properties;32import java.io.IOException;33import java.io.InputStream;3435/**36* <p>37* The <tt>JAXBContext</tt> class provides the client's entry point to the38* JAXB API. It provides an abstraction for managing the XML/Java binding39* information necessary to implement the JAXB binding framework operations:40* unmarshal, marshal and validate.41*42* <p>A client application normally obtains new instances of this class using43* one of these two styles for newInstance methods, although there are other44* specialized forms of the method available:45*46* <ul>47* <li>{@link #newInstance(String,ClassLoader) JAXBContext.newInstance( "com.acme.foo:com.acme.bar" )} <br/>48* The JAXBContext instance is initialized from a list of colon49* separated Java package names. Each java package contains50* JAXB mapped classes, schema-derived classes and/or user annotated51* classes. Additionally, the java package may contain JAXB package annotations52* that must be processed. (see JLS, Section 7.4.1 "Named Packages").53* </li>54* <li>{@link #newInstance(Class...) JAXBContext.newInstance( com.acme.foo.Foo.class )} <br/>55* The JAXBContext instance is initialized with class(es)56* passed as parameter(s) and classes that are statically reachable from57* these class(es). See {@link #newInstance(Class...)} for details.58* </li>59* </ul>60*61* <p>62* <i><B>SPEC REQUIREMENT:</B> the provider must supply an implementation63* class containing the following method signatures:</i>64*65* <pre>66* public static JAXBContext createContext( String contextPath, ClassLoader classLoader, Map<String,Object> properties ) throws JAXBException67* public static JAXBContext createContext( Class[] classes, Map<String,Object> properties ) throws JAXBException68* </pre>69*70* <p><i>71* The following JAXB 1.0 requirement is only required for schema to72* java interface/implementation binding. It does not apply to JAXB annotated73* classes. JAXB Providers must generate a <tt>jaxb.properties</tt> file in74* each package containing schema derived classes. The property file must75* contain a property named <tt>javax.xml.bind.context.factory</tt> whose76* value is the name of the class that implements the <tt>createContext</tt>77* APIs.</i>78*79* <p><i>80* The class supplied by the provider does not have to be assignable to81* <tt>javax.xml.bind.JAXBContext</tt>, it simply has to provide a class that82* implements the <tt>createContext</tt> APIs.</i>83*84* <p><i>85* In addition, the provider must call the86* {@link DatatypeConverter#setDatatypeConverter(DatatypeConverterInterface)87* DatatypeConverter.setDatatypeConverter} api prior to any client88* invocations of the marshal and unmarshal methods. This is necessary to89* configure the datatype converter that will be used during these operations.</i>90*91* <a name="Unmarshalling"></a>92* <h3>Unmarshalling</h3>93* <p>94* The {@link Unmarshaller} class provides the client application the ability95* to convert XML data into a tree of Java content objects.96* The unmarshal method allows for97* any global XML element declared in the schema to be unmarshalled as98* the root of an instance document.99* Additionally, the unmarshal method allows for an unrecognized root element that100* has an xsi:type attribute's value that references a type definition declared in101* the schema to be unmarshalled as the root of an instance document.102* The <tt>JAXBContext</tt> object103* allows the merging of global elements and type definitions across a set of schemas (listed104* in the <tt>contextPath</tt>). Since each schema in the schema set can belong105* to distinct namespaces, the unification of schemas to an unmarshalling106* context should be namespace independent. This means that a client107* application is able to unmarshal XML documents that are instances of108* any of the schemas listed in the <tt>contextPath</tt>. For example:109*110* <pre>111* JAXBContext jc = JAXBContext.newInstance( "com.acme.foo:com.acme.bar" );112* Unmarshaller u = jc.createUnmarshaller();113* FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) ); // ok114* BarObject barObj = (BarObject)u.unmarshal( new File( "bar.xml" ) ); // ok115* BazObject bazObj = (BazObject)u.unmarshal( new File( "baz.xml" ) ); // error, "com.acme.baz" not in contextPath116* </pre>117*118* <p>119* The client application may also generate Java content trees explicitly rather120* than unmarshalling existing XML data. For all JAXB-annotated value classes,121* an application can create content using constructors.122* For schema-derived interface/implementation classes and for the123* creation of elements that are not bound to a JAXB-annotated124* class, an application needs to have access and knowledge about each of125* the schema derived <tt> ObjectFactory</tt> classes that exist in each of126* java packages contained in the <tt>contextPath</tt>. For each schema127* derived java class, there is a static factory method that produces objects128* of that type. For example,129* assume that after compiling a schema, you have a package <tt>com.acme.foo</tt>130* that contains a schema derived interface named <tt>PurchaseOrder</tt>. In131* order to create objects of that type, the client application would use the132* factory method like this:133*134* <pre>135* com.acme.foo.PurchaseOrder po =136* com.acme.foo.ObjectFactory.createPurchaseOrder();137* </pre>138*139* <p>140* Once the client application has an instance of the the schema derived object,141* it can use the mutator methods to set content on it.142*143* <p>144* For more information on the generated <tt>ObjectFactory</tt> classes, see145* Section 4.2 <i>Java Package</i> of the specification.146*147* <p>148* <i><B>SPEC REQUIREMENT:</B> the provider must generate a class in each149* package that contains all of the necessary object factory methods for that150* package named ObjectFactory as well as the static151* <tt>newInstance( javaContentInterface )</tt> method</i>152*153* <h3>Marshalling</h3>154* <p>155* The {@link Marshaller} class provides the client application the ability156* to convert a Java content tree back into XML data. There is no difference157* between marshalling a content tree that is created manually using the factory158* methods and marshalling a content tree that is the result an <tt>unmarshal159* </tt> operation. Clients can marshal a java content tree back to XML data160* to a <tt>java.io.OutputStream</tt> or a <tt>java.io.Writer</tt>. The161* marshalling process can alternatively produce SAX2 event streams to a162* registered <tt>ContentHandler</tt> or produce a DOM Node object.163* Client applications have control over the output encoding as well as164* whether or not to marshal the XML data as a complete document or165* as a fragment.166*167* <p>168* Here is a simple example that unmarshals an XML document and then marshals169* it back out:170*171* <pre>172* JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );173*174* // unmarshal from foo.xml175* Unmarshaller u = jc.createUnmarshaller();176* FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) );177*178* // marshal to System.out179* Marshaller m = jc.createMarshaller();180* m.marshal( fooObj, System.out );181* </pre>182*183*184* <h3>Validation</h3>185* <p>186* Validation has been changed significantly since JAXB 1.0. The {@link Validator}187* class has been deprecated and made optional. This means that you are advised188* not to use this class and, in fact, it may not even be available depending on189* your JAXB provider. JAXB 1.0 client applications that rely on <tt>Validator</tt>190* will still work properly when deployed with the JAXB 1.0 runtime system.191*192* In JAXB 2.0, the {@link Unmarshaller} has included convenince methods that expose193* the JAXP 1.3 {@link javax.xml.validation} framework. Please refer to the194* {@link Unmarshaller#setSchema(javax.xml.validation.Schema)} API for more195* information.196*197*198* <h3>JAXB Runtime Binding Framework Compatibility</h3>199* <p>200* The following JAXB 1.0 restriction only applies to binding schema to201* interfaces/implementation classes.202* Since this binding does not require a common runtime system, a JAXB203* client application must not attempt to mix runtime objects (<tt>JAXBContext,204* Marshaller</tt>, etc. ) from different providers. This does not205* mean that the client application isn't portable, it simply means that a206* client has to use a runtime system provided by the same provider that was207* used to compile the schema.208*209*210* <h3>Discovery of JAXB implementation</h3>211* <p>212* When one of the <tt>newInstance</tt> methods is called, a JAXB implementation is discovered213* by the following steps.214*215* <ol>216* <li>217* For each package/class explicitly passed in to the {@link #newInstance} method, in the order they are specified,218* <tt>jaxb.properties</tt> file is looked up in its package, by using the associated classloader —219* this is {@link Class#getClassLoader() the owner class loader} for a {@link Class} argument, and for a package220* the specified {@link ClassLoader}.221*222* <p>223* If such a file is discovered, it is {@link Properties#load(InputStream) loaded} as a property file, and224* the value of the {@link #JAXB_CONTEXT_FACTORY} key will be assumed to be the provider factory class.225* This class is then loaded by the associated classloader discussed above.226*227* <p>228* This phase of the look up allows some packages to force the use of a certain JAXB implementation.229* (For example, perhaps the schema compiler has generated some vendor extension in the code.)230*231* <li>232* If the system property {@link #JAXB_CONTEXT_FACTORY} exists, then its value is assumed to be the provider233* factory class. This phase of the look up enables per-JVM override of the JAXB implementation.234*235* <li>236* Look for <tt>/META-INF/services/javax.xml.bind.JAXBContext</tt> file in the associated classloader.237* This file follows the standard service descriptor convention, and if such a file exists, its content238* is assumed to be the provider factory class. This phase of the look up is for automatic discovery.239* It allows users to just put a JAXB implementation in a classpath and use it without any furhter configuration.240*241* <li>242* Finally, if all the steps above fail, then the rest of the look up is unspecified. That said,243* the recommended behavior is to simply look for some hard-coded platform default JAXB implementation.244* This phase of the look up is so that JavaSE can have its own JAXB implementation as the last resort.245* </ol>246*247* <p>248* Once the provider factory class is discovered, its249* <tt>public static JAXBContext createContext(String,ClassLoader,Map)</tt> method250* (see {@link #newInstance(String, ClassLoader, Map)} for the parameter semantics.)251* or <tt>public static JAXBContext createContet(Class[],Map)</tt> method252* (see {@link #newInstance(Class[], Map)} for the parameter semantics) are invoked253* to create a {@link JAXBContext}.254*255* @author <ul><li>Ryan Shoemaker, Sun Microsystems, Inc.</li><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li><li>Joe Fialli, Sun Microsystems, Inc.</li></ul>256* @see Marshaller257* @see Unmarshaller258* @see S 7.4.1 "Named Packages" in Java Language Specification</a>259* @since JAXB1.0260*/261public abstract class JAXBContext {262263/**264* The name of the property that contains the name of the class capable265* of creating new <tt>JAXBContext</tt> objects.266*/267public static final String JAXB_CONTEXT_FACTORY =268"javax.xml.bind.context.factory";269270271protected JAXBContext() {272}273274275/**276* <p>277* Obtain a new instance of a <tt>JAXBContext</tt> class.278*279* <p>280* This is a convenience method to invoke the281* {@link #newInstance(String,ClassLoader)} method with282* the context class loader of the current thread.283*284* @throws JAXBException if an error was encountered while creating the285* <tt>JAXBContext</tt> such as286* <ol>287* <li>failure to locate either ObjectFactory.class or jaxb.index in the packages</li>288* <li>an ambiguity among global elements contained in the contextPath</li>289* <li>failure to locate a value for the context factory provider property</li>290* <li>mixing schema derived packages from different providers on the same contextPath</li>291* </ol>292*/293public static JAXBContext newInstance( String contextPath )294throws JAXBException {295296//return newInstance( contextPath, JAXBContext.class.getClassLoader() );297return newInstance( contextPath, getContextClassLoader());298}299300/**301* <p>302* Obtain a new instance of a <tt>JAXBContext</tt> class.303*304* <p>305* The client application must supply a context path which is a list of306* colon (':', \u005Cu003A) separated java package names that contain307* schema-derived classes and/or fully qualified JAXB-annotated classes.308* Schema-derived309* code is registered with the JAXBContext by the310* ObjectFactory.class generated per package.311* Alternatively than being listed in the context path, programmer312* annotated JAXB mapped classes can be listed in a313* <tt>jaxb.index</tt> resource file, format described below.314* Note that a java package can contain both schema-derived classes and315* user annotated JAXB classes. Additionally, the java package may316* contain JAXB package annotations that must be processed. (see JLS,317* Section 7.4.1 "Named Packages").318* </p>319*320* <p>321* Every package listed on the contextPath must meet <b>one or both</b> of the322* following conditions otherwise a <tt>JAXBException</tt> will be thrown:323* </p>324* <ol>325* <li>it must contain ObjectFactory.class</li>326* <li>it must contain jaxb.index</li>327* </ol>328*329* <p>330* <b>Format for jaxb.index</b>331* <p>332* The file contains a newline-separated list of class names.333* Space and tab characters, as well as blank334* lines, are ignored. The comment character335* is '#' (0x23); on each line all characters following the first comment336* character are ignored. The file must be encoded in UTF-8. Classes that337* are reachable, as defined in {@link #newInstance(Class...)}, from the338* listed classes are also registered with JAXBContext.339* <p>340* Constraints on class name occuring in a <tt>jaxb.index</tt> file are:341* <ul>342* <li>Must not end with ".class".</li>343* <li>Class names are resolved relative to package containing344* <tt>jaxb.index</tt> file. Only classes occuring directly in package345* containing <tt>jaxb.index</tt> file are allowed.</li>346* <li>Fully qualified class names are not allowed.347* A qualified class name,relative to current package,348* is only allowed to specify a nested or inner class.</li>349* </ul>350*351* <p>352* To maintain compatibility with JAXB 1.0 schema to java353* interface/implementation binding, enabled by schema customization354* <tt><jaxb:globalBindings valueClass="false"></tt>,355* the JAXB provider will ensure that each package on the context path356* has a <tt>jaxb.properties</tt> file which contains a value for the357* <tt>javax.xml.bind.context.factory</tt> property and that all values358* resolve to the same provider. This requirement does not apply to359* JAXB annotated classes.360*361* <p>362* If there are any global XML element name collisions across the various363* packages listed on the <tt>contextPath</tt>, a <tt>JAXBException</tt>364* will be thrown.365*366* <p>367* Mixing generated interface/impl bindings from multiple JAXB Providers368* in the same context path may result in a <tt>JAXBException</tt>369* being thrown.370*371* <p>372* The steps involved in discovering the JAXB implementation is discussed in the class javadoc.373*374* @param contextPath list of java package names that contain schema375* derived class and/or java to schema (JAXB-annotated)376* mapped classes377* @param classLoader378* This class loader will be used to locate the implementation379* classes.380*381* @return a new instance of a <tt>JAXBContext</tt>382* @throws JAXBException if an error was encountered while creating the383* <tt>JAXBContext</tt> such as384* <ol>385* <li>failure to locate either ObjectFactory.class or jaxb.index in the packages</li>386* <li>an ambiguity among global elements contained in the contextPath</li>387* <li>failure to locate a value for the context factory provider property</li>388* <li>mixing schema derived packages from different providers on the same contextPath</li>389* </ol>390*/391public static JAXBContext newInstance( String contextPath, ClassLoader classLoader ) throws JAXBException {392393return newInstance(contextPath,classLoader,Collections.<String,Object>emptyMap());394}395396/**397* <p>398* Obtain a new instance of a <tt>JAXBContext</tt> class.399*400* <p>401* This is mostly the same as {@link JAXBContext#newInstance(String, ClassLoader)},402* but this version allows you to pass in provider-specific properties to configure403* the instantiation of {@link JAXBContext}.404*405* <p>406* The interpretation of properties is up to implementations. Implementations should407* throw <tt>JAXBException</tt> if it finds properties that it doesn't understand.408*409* @param contextPath list of java package names that contain schema derived classes410* @param classLoader411* This class loader will be used to locate the implementation classes.412* @param properties413* provider-specific properties. Can be null, which means the same thing as passing414* in an empty map.415*416* @return a new instance of a <tt>JAXBContext</tt>417* @throws JAXBException if an error was encountered while creating the418* <tt>JAXBContext</tt> such as419* <ol>420* <li>failure to locate either ObjectFactory.class or jaxb.index in the packages</li>421* <li>an ambiguity among global elements contained in the contextPath</li>422* <li>failure to locate a value for the context factory provider property</li>423* <li>mixing schema derived packages from different providers on the same contextPath</li>424* </ol>425* @since JAXB2.0426*/427public static JAXBContext newInstance( String contextPath, ClassLoader classLoader, Map<String,?> properties )428throws JAXBException {429430return ContextFinder.find(431/* The default property name according to the JAXB spec */432JAXB_CONTEXT_FACTORY,433434/* the context path supplied by the client app */435contextPath,436437/* class loader to be used */438classLoader,439properties );440}441442// TODO: resurrect this once we introduce external annotations443// /**444// * <p>445// * Obtain a new instance of a <tt>JAXBContext</tt> class.446// *447// * <p>448// * The client application must supply a list of classes that the new449// * context object needs to recognize.450// *451// * Not only the new context will recognize all the classes specified,452// * but it will also recognize any classes that are directly/indirectly453// * referenced statically from the specified classes.454// *455// * For example, in the following Java code, if you do456// * <tt>newInstance(Foo.class)</tt>, the newly created {@link JAXBContext}457// * will recognize both <tt>Foo</tt> and <tt>Bar</tt>, but not <tt>Zot</tt>:458// * <pre>459// * class Foo {460// * Bar b;461// * }462// * class Bar { int x; }463// * class Zot extends Bar { int y; }464// * </pre>465// *466// * Therefore, a typical client application only needs to specify the467// * top-level classes, but it needs to be careful.468// *469// * TODO: if we are to define other mechanisms, refer to them.470// *471// * @param externalBindings472// * list of external binding files. Can be null or empty if none is used.473// * when specified, those files determine how the classes are bound.474// *475// * @param classesToBeBound476// * list of java classes to be recognized by the new {@link JAXBContext}.477// * Can be empty, in which case a {@link JAXBContext} that only knows about478// * spec-defined classes will be returned.479// *480// * @return481// * A new instance of a <tt>JAXBContext</tt>. Always non-null valid object.482// *483// * @throws JAXBException484// * if an error was encountered while creating the485// * <tt>JAXBContext</tt>, such as (but not limited to):486// * <ol>487// * <li>No JAXB implementation was discovered488// * <li>Classes use JAXB annotations incorrectly489// * <li>Classes have colliding annotations (i.e., two classes with the same type name)490// * <li>Specified external bindings are incorrect491// * <li>The JAXB implementation was unable to locate492// * provider-specific out-of-band information (such as additional493// * files generated at the development time.)494// * </ol>495// *496// * @throws IllegalArgumentException497// * if the parameter contains {@code null} (i.e., {@code newInstance(null);})498// *499// * @since JAXB2.0500// */501// public static JAXBContext newInstance( Source[] externalBindings, Class... classesToBeBound )502// throws JAXBException {503//504// // empty class list is not an error, because the context will still include505// // spec-specified classes like String and Integer.506// // if(classesToBeBound.length==0)507// // throw new IllegalArgumentException();508//509// // but it is an error to have nulls in it.510// for( int i=classesToBeBound.length-1; i>=0; i-- )511// if(classesToBeBound[i]==null)512// throw new IllegalArgumentException();513//514// return ContextFinder.find(externalBindings,classesToBeBound);515// }516517/**518* <p>519* Obtain a new instance of a <tt>JAXBContext</tt> class.520*521* <p>522* The client application must supply a list of classes that the new523* context object needs to recognize.524*525* Not only the new context will recognize all the classes specified,526* but it will also recognize any classes that are directly/indirectly527* referenced statically from the specified classes. Subclasses of528* referenced classes nor <tt>@XmlTransient</tt> referenced classes529* are not registered with JAXBContext.530*531* For example, in the following Java code, if you do532* <tt>newInstance(Foo.class)</tt>, the newly created {@link JAXBContext}533* will recognize both <tt>Foo</tt> and <tt>Bar</tt>, but not <tt>Zot</tt> or <tt>FooBar</tt>:534* <pre>535* class Foo {536* @XmlTransient FooBar c;537* Bar b;538* }539* class Bar { int x; }540* class Zot extends Bar { int y; }541* class FooBar { }542* </pre>543*544* Therefore, a typical client application only needs to specify the545* top-level classes, but it needs to be careful.546*547* <p>548* Note that for each java package registered with JAXBContext,549* when the optional package annotations exist, they must be processed.550* (see JLS, Section 7.4.1 "Named Packages").551*552* <p>553* The steps involved in discovering the JAXB implementation is discussed in the class javadoc.554*555* @param classesToBeBound556* list of java classes to be recognized by the new {@link JAXBContext}.557* Can be empty, in which case a {@link JAXBContext} that only knows about558* spec-defined classes will be returned.559*560* @return561* A new instance of a <tt>JAXBContext</tt>. Always non-null valid object.562*563* @throws JAXBException564* if an error was encountered while creating the565* <tt>JAXBContext</tt>, such as (but not limited to):566* <ol>567* <li>No JAXB implementation was discovered568* <li>Classes use JAXB annotations incorrectly569* <li>Classes have colliding annotations (i.e., two classes with the same type name)570* <li>The JAXB implementation was unable to locate571* provider-specific out-of-band information (such as additional572* files generated at the development time.)573* </ol>574*575* @throws IllegalArgumentException576* if the parameter contains {@code null} (i.e., {@code newInstance(null);})577*578* @since JAXB2.0579*/580public static JAXBContext newInstance( Class... classesToBeBound )581throws JAXBException {582583return newInstance(classesToBeBound,Collections.<String,Object>emptyMap());584}585586/**587* <p>588* Obtain a new instance of a <tt>JAXBContext</tt> class.589*590* <p>591* An overloading of {@link JAXBContext#newInstance(Class...)}592* to configure 'properties' for this instantiation of {@link JAXBContext}.593*594* <p>595* The interpretation of properties is up to implementations. Implementations should596* throw <tt>JAXBException</tt> if it finds properties that it doesn't understand.597*598* @param classesToBeBound599* list of java classes to be recognized by the new {@link JAXBContext}.600* Can be empty, in which case a {@link JAXBContext} that only knows about601* spec-defined classes will be returned.602* @param properties603* provider-specific properties. Can be null, which means the same thing as passing604* in an empty map.605*606* @return607* A new instance of a <tt>JAXBContext</tt>. Always non-null valid object.608*609* @throws JAXBException610* if an error was encountered while creating the611* <tt>JAXBContext</tt>, such as (but not limited to):612* <ol>613* <li>No JAXB implementation was discovered614* <li>Classes use JAXB annotations incorrectly615* <li>Classes have colliding annotations (i.e., two classes with the same type name)616* <li>The JAXB implementation was unable to locate617* provider-specific out-of-band information (such as additional618* files generated at the development time.)619* </ol>620*621* @throws IllegalArgumentException622* if the parameter contains {@code null} (i.e., {@code newInstance(null,someMap);})623*624* @since JAXB2.0625*/626public static JAXBContext newInstance( Class[] classesToBeBound, Map<String,?> properties )627throws JAXBException {628629if (classesToBeBound == null) {630throw new IllegalArgumentException();631}632633// but it is an error to have nulls in it.634for (int i = classesToBeBound.length - 1; i >= 0; i--) {635if (classesToBeBound[i] == null) {636throw new IllegalArgumentException();637}638}639640return ContextFinder.find(classesToBeBound,properties);641}642643/**644* Create an <tt>Unmarshaller</tt> object that can be used to convert XML645* data into a java content tree.646*647* @return an <tt>Unmarshaller</tt> object648*649* @throws JAXBException if an error was encountered while creating the650* <tt>Unmarshaller</tt> object651*/652public abstract Unmarshaller createUnmarshaller() throws JAXBException;653654655/**656* Create a <tt>Marshaller</tt> object that can be used to convert a657* java content tree into XML data.658*659* @return a <tt>Marshaller</tt> object660*661* @throws JAXBException if an error was encountered while creating the662* <tt>Marshaller</tt> object663*/664public abstract Marshaller createMarshaller() throws JAXBException;665666667/**668* {@link Validator} has been made optional and deprecated in JAXB 2.0. Please669* refer to the javadoc for {@link Validator} for more detail.670* <p>671* Create a <tt>Validator</tt> object that can be used to validate a672* java content tree against its source schema.673*674* @return a <tt>Validator</tt> object675*676* @throws JAXBException if an error was encountered while creating the677* <tt>Validator</tt> object678* @deprecated since JAXB2.0679*/680public abstract Validator createValidator() throws JAXBException;681682/**683* Creates a <tt>Binder</tt> object that can be used for684* associative/in-place unmarshalling/marshalling.685*686* @param domType select the DOM API to use by passing in its DOM Node class.687*688* @return always a new valid <tt>Binder</tt> object.689*690* @throws UnsupportedOperationException691* if DOM API corresponding to <tt>domType</tt> is not supported by692* the implementation.693*694* @since JAXB2.0695*/696public <T> Binder<T> createBinder(Class<T> domType) {697// to make JAXB 1.0 implementations work, this method must not be698// abstract699throw new UnsupportedOperationException();700}701702/**703* Creates a <tt>Binder</tt> for W3C DOM.704*705* @return always a new valid <tt>Binder</tt> object.706*707* @since JAXB2.0708*/709public Binder<Node> createBinder() {710return createBinder(Node.class);711}712713/**714* Creates a <tt>JAXBIntrospector</tt> object that can be used to715* introspect JAXB objects.716*717* @return718* always return a non-null valid <tt>JAXBIntrospector</tt> object.719*720* @throws UnsupportedOperationException721* Calling this method on JAXB 1.0 implementations will throw722* an UnsupportedOperationException.723*724* @since JAXB2.0725*/726public JAXBIntrospector createJAXBIntrospector() {727// to make JAXB 1.0 implementations work, this method must not be728// abstract729throw new UnsupportedOperationException();730}731732/**733* Generates the schema documents for this context.734*735* @param outputResolver736* this object controls the output to which schemas737* will be sent.738*739* @throws IOException740* if {@link SchemaOutputResolver} throws an {@link IOException}.741*742* @throws UnsupportedOperationException743* Calling this method on JAXB 1.0 implementations will throw744* an UnsupportedOperationException.745*746* @since JAXB 2.0747*/748public void generateSchema(SchemaOutputResolver outputResolver) throws IOException {749// to make JAXB 1.0 implementations work, this method must not be750// abstract751throw new UnsupportedOperationException();752}753754private static ClassLoader getContextClassLoader() {755if (System.getSecurityManager() == null) {756return Thread.currentThread().getContextClassLoader();757} else {758return (ClassLoader) java.security.AccessController.doPrivileged(759new java.security.PrivilegedAction() {760public java.lang.Object run() {761return Thread.currentThread().getContextClassLoader();762}763});764}765}766767}768769770