src/share/jaxws_classes/javax/xml/bind/Unmarshaller.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 397
b99d7e355d4b
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package javax.xml.bind;
aoqi@0 27
aoqi@0 28 import javax.xml.bind.annotation.adapters.XmlAdapter;
aoqi@0 29 import javax.xml.bind.attachment.AttachmentUnmarshaller;
aoqi@0 30 import javax.xml.validation.Schema;
aoqi@0 31 import java.io.Reader;
aoqi@0 32
aoqi@0 33 /**
aoqi@0 34 * The <tt>Unmarshaller</tt> class governs the process of deserializing XML
aoqi@0 35 * data into newly created Java content trees, optionally validating the XML
aoqi@0 36 * data as it is unmarshalled. It provides an overloading of unmarshal methods
aoqi@0 37 * for many different input kinds.
aoqi@0 38 *
aoqi@0 39 * <p>
aoqi@0 40 * Unmarshalling from a File:
aoqi@0 41 * <blockquote>
aoqi@0 42 * <pre>
aoqi@0 43 * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0 44 * Unmarshaller u = jc.createUnmarshaller();
aoqi@0 45 * Object o = u.unmarshal( new File( "nosferatu.xml" ) );
aoqi@0 46 * </pre>
aoqi@0 47 * </blockquote>
aoqi@0 48 *
aoqi@0 49 *
aoqi@0 50 * <p>
aoqi@0 51 * Unmarshalling from an InputStream:
aoqi@0 52 * <blockquote>
aoqi@0 53 * <pre>
aoqi@0 54 * InputStream is = new FileInputStream( "nosferatu.xml" );
aoqi@0 55 * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0 56 * Unmarshaller u = jc.createUnmarshaller();
aoqi@0 57 * Object o = u.unmarshal( is );
aoqi@0 58 * </pre>
aoqi@0 59 * </blockquote>
aoqi@0 60 *
aoqi@0 61 * <p>
aoqi@0 62 * Unmarshalling from a URL:
aoqi@0 63 * <blockquote>
aoqi@0 64 * <pre>
aoqi@0 65 * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0 66 * Unmarshaller u = jc.createUnmarshaller();
aoqi@0 67 * URL url = new URL( "http://beaker.east/nosferatu.xml" );
aoqi@0 68 * Object o = u.unmarshal( url );
aoqi@0 69 * </pre>
aoqi@0 70 * </blockquote>
aoqi@0 71 *
aoqi@0 72 * <p>
aoqi@0 73 * Unmarshalling from a StringBuffer using a
aoqi@0 74 * <tt>javax.xml.transform.stream.StreamSource</tt>:
aoqi@0 75 * <blockquote>
aoqi@0 76 * <pre>
aoqi@0 77 * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0 78 * Unmarshaller u = jc.createUnmarshaller();
aoqi@0 79 * StringBuffer xmlStr = new StringBuffer( "&lt;?xml version=&quot;1.0&quot;?&gt;..." );
aoqi@0 80 * Object o = u.unmarshal( new StreamSource( new StringReader( xmlStr.toString() ) ) );
aoqi@0 81 * </pre>
aoqi@0 82 * </blockquote>
aoqi@0 83 *
aoqi@0 84 * <p>
aoqi@0 85 * Unmarshalling from a <tt>org.w3c.dom.Node</tt>:
aoqi@0 86 * <blockquote>
aoqi@0 87 * <pre>
aoqi@0 88 * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0 89 * Unmarshaller u = jc.createUnmarshaller();
aoqi@0 90 *
aoqi@0 91 * DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
aoqi@0 92 * dbf.setNamespaceAware(true);
aoqi@0 93 * DocumentBuilder db = dbf.newDocumentBuilder();
aoqi@0 94 * Document doc = db.parse(new File( "nosferatu.xml"));
aoqi@0 95
aoqi@0 96 * Object o = u.unmarshal( doc );
aoqi@0 97 * </pre>
aoqi@0 98 * </blockquote>
aoqi@0 99 *
aoqi@0 100 * <p>
aoqi@0 101 * Unmarshalling from a <tt>javax.xml.transform.sax.SAXSource</tt> using a
aoqi@0 102 * client specified validating SAX2.0 parser:
aoqi@0 103 * <blockquote>
aoqi@0 104 * <pre>
aoqi@0 105 * // configure a validating SAX2.0 parser (Xerces2)
aoqi@0 106 * static final String JAXP_SCHEMA_LANGUAGE =
aoqi@0 107 * "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
aoqi@0 108 * static final String JAXP_SCHEMA_LOCATION =
aoqi@0 109 * "http://java.sun.com/xml/jaxp/properties/schemaSource";
aoqi@0 110 * static final String W3C_XML_SCHEMA =
aoqi@0 111 * "http://www.w3.org/2001/XMLSchema";
aoqi@0 112 *
aoqi@0 113 * System.setProperty( "javax.xml.parsers.SAXParserFactory",
aoqi@0 114 * "org.apache.xerces.jaxp.SAXParserFactoryImpl" );
aoqi@0 115 *
aoqi@0 116 * SAXParserFactory spf = SAXParserFactory.newInstance();
aoqi@0 117 * spf.setNamespaceAware(true);
aoqi@0 118 * spf.setValidating(true);
aoqi@0 119 * SAXParser saxParser = spf.newSAXParser();
aoqi@0 120 *
aoqi@0 121 * try {
aoqi@0 122 * saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
aoqi@0 123 * saxParser.setProperty(JAXP_SCHEMA_LOCATION, "http://....");
aoqi@0 124 * } catch (SAXNotRecognizedException x) {
aoqi@0 125 * // exception handling omitted
aoqi@0 126 * }
aoqi@0 127 *
aoqi@0 128 * XMLReader xmlReader = saxParser.getXMLReader();
aoqi@0 129 * SAXSource source =
aoqi@0 130 * new SAXSource( xmlReader, new InputSource( "http://..." ) );
aoqi@0 131 *
aoqi@0 132 * // Setup JAXB to unmarshal
aoqi@0 133 * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0 134 * Unmarshaller u = jc.createUnmarshaller();
aoqi@0 135 * ValidationEventCollector vec = new ValidationEventCollector();
aoqi@0 136 * u.setEventHandler( vec );
aoqi@0 137 *
aoqi@0 138 * // turn off the JAXB provider's default validation mechanism to
aoqi@0 139 * // avoid duplicate validation
aoqi@0 140 * u.setValidating( false )
aoqi@0 141 *
aoqi@0 142 * // unmarshal
aoqi@0 143 * Object o = u.unmarshal( source );
aoqi@0 144 *
aoqi@0 145 * // check for events
aoqi@0 146 * if( vec.hasEvents() ) {
aoqi@0 147 * // iterate over events
aoqi@0 148 * }
aoqi@0 149 * </pre>
aoqi@0 150 * </blockquote>
aoqi@0 151 *
aoqi@0 152 * <p>
aoqi@0 153 * Unmarshalling from a StAX XMLStreamReader:
aoqi@0 154 * <blockquote>
aoqi@0 155 * <pre>
aoqi@0 156 * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0 157 * Unmarshaller u = jc.createUnmarshaller();
aoqi@0 158 *
aoqi@0 159 * javax.xml.stream.XMLStreamReader xmlStreamReader =
aoqi@0 160 * javax.xml.stream.XMLInputFactory().newInstance().createXMLStreamReader( ... );
aoqi@0 161 *
aoqi@0 162 * Object o = u.unmarshal( xmlStreamReader );
aoqi@0 163 * </pre>
aoqi@0 164 * </blockquote>
aoqi@0 165 *
aoqi@0 166 * <p>
aoqi@0 167 * Unmarshalling from a StAX XMLEventReader:
aoqi@0 168 * <blockquote>
aoqi@0 169 * <pre>
aoqi@0 170 * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0 171 * Unmarshaller u = jc.createUnmarshaller();
aoqi@0 172 *
aoqi@0 173 * javax.xml.stream.XMLEventReader xmlEventReader =
aoqi@0 174 * javax.xml.stream.XMLInputFactory().newInstance().createXMLEventReader( ... );
aoqi@0 175 *
aoqi@0 176 * Object o = u.unmarshal( xmlEventReader );
aoqi@0 177 * </pre>
aoqi@0 178 * </blockquote>
aoqi@0 179 *
aoqi@0 180 * <p>
aoqi@0 181 * <a name="unmarshalEx"></a>
aoqi@0 182 * <b>Unmarshalling XML Data</b><br>
aoqi@0 183 * <blockquote>
aoqi@0 184 * Unmarshalling can deserialize XML data that represents either an entire XML document
aoqi@0 185 * or a subtree of an XML document. Typically, it is sufficient to use the
aoqi@0 186 * unmarshalling methods described by
aoqi@0 187 * <a href="#unmarshalGlobal">Unmarshal root element that is declared globally</a>.
aoqi@0 188 * These unmarshal methods utilize {@link JAXBContext}'s mapping of global XML element
aoqi@0 189 * declarations and type definitions to JAXB mapped classes to initiate the
aoqi@0 190 * unmarshalling of the root element of XML data. When the {@link JAXBContext}'s
aoqi@0 191 * mappings are not sufficient to unmarshal the root element of XML data,
aoqi@0 192 * the application can assist the unmarshalling process by using the
aoqi@0 193 * <a href="#unmarshalByDeclaredType">unmarshal by declaredType methods</a>.
aoqi@0 194 * These methods are useful for unmarshalling XML data where
aoqi@0 195 * the root element corresponds to a local element declaration in the schema.
aoqi@0 196 * </blockquote>
aoqi@0 197 *
aoqi@0 198 * <blockquote>
aoqi@0 199 * An unmarshal method never returns null. If the unmarshal process is unable to unmarshal
aoqi@0 200 * the root of XML content to a JAXB mapped object, a fatal error is reported that
aoqi@0 201 * terminates processing by throwing JAXBException.
aoqi@0 202 * </blockquote>
aoqi@0 203 *
aoqi@0 204 * <p>
aoqi@0 205 * <a name="unmarshalGlobal"></a>
aoqi@0 206 * <b>Unmarshal a root element that is globally declared</b><br>
aoqi@0 207 * <blockquote>
aoqi@0 208 * The unmarshal methods that do not have an <tt>declaredType</tt> parameter use
aoqi@0 209 * {@link JAXBContext} to unmarshal the root element of an XML data. The {@link JAXBContext}
aoqi@0 210 * instance is the one that was used to create this <tt>Unmarshaller</tt>. The {@link JAXBContext}
aoqi@0 211 * instance maintains a mapping of globally declared XML element and type definition names to
aoqi@0 212 * JAXB mapped classes. The unmarshal method checks if {@link JAXBContext} has a mapping
aoqi@0 213 * from the root element's XML name and/or <tt>@xsi:type</tt> to a JAXB mapped class. If it does, it umarshalls the
aoqi@0 214 * XML data using the appropriate JAXB mapped class. Note that when the root element name is unknown and the root
aoqi@0 215 * element has an <tt>@xsi:type</tt>, the XML data is unmarshalled
aoqi@0 216 * using that JAXB mapped class as the value of a {@link JAXBElement}.
aoqi@0 217 * When the {@link JAXBContext} object does not have a mapping for the root element's name
aoqi@0 218 * nor its <tt>@xsi:type</tt>, if it exists,
aoqi@0 219 * then the unmarshal operation will abort immediately by throwing a {@link UnmarshalException
aoqi@0 220 * UnmarshalException}. This exception scenario can be worked around by using the unmarshal by
aoqi@0 221 * declaredType methods described in the next subsection.
aoqi@0 222 * </blockquote>
aoqi@0 223 *
aoqi@0 224 * <p>
aoqi@0 225 * <a name="unmarshalByDeclaredType"></a>
aoqi@0 226 * <b>Unmarshal by Declared Type</b><br>
aoqi@0 227 * <blockquote>
aoqi@0 228 * The unmarshal methods with a <code>declaredType</code> parameter enable an
aoqi@0 229 * application to deserialize a root element of XML data, even when
aoqi@0 230 * there is no mapping in {@link JAXBContext} of the root element's XML name.
aoqi@0 231 * The unmarshaller unmarshals the root element using the application provided
aoqi@0 232 * mapping specified as the <tt>declaredType</tt> parameter.
aoqi@0 233 * Note that even when the root element's element name is mapped by {@link JAXBContext},
aoqi@0 234 * the <code>declaredType</code> parameter overrides that mapping for
aoqi@0 235 * deserializing the root element when using these unmarshal methods.
aoqi@0 236 * Additionally, when the root element of XML data has an <tt>xsi:type</tt> attribute and
aoqi@0 237 * that attribute's value references a type definition that is mapped
aoqi@0 238 * to a JAXB mapped class by {@link JAXBContext}, that the root
aoqi@0 239 * element's <tt>xsi:type</tt> attribute takes
aoqi@0 240 * precedence over the unmarshal methods <tt>declaredType</tt> parameter.
aoqi@0 241 * These methods always return a <tt>JAXBElement&lt;declaredType></tt>
aoqi@0 242 * instance. The table below shows how the properties of the returned JAXBElement
aoqi@0 243 * instance are set.
aoqi@0 244 *
aoqi@0 245 * <a name="unmarshalDeclaredTypeReturn"></a>
aoqi@0 246 * <p>
aoqi@0 247 * <table border="2" rules="all" cellpadding="4">
aoqi@0 248 * <thead>
aoqi@0 249 * <tr>
aoqi@0 250 * <th align="center" colspan="2">
aoqi@0 251 * Unmarshal By Declared Type returned JAXBElement
aoqi@0 252 * </tr>
aoqi@0 253 * <tr>
aoqi@0 254 * <th>JAXBElement Property</th>
aoqi@0 255 * <th>Value</th>
aoqi@0 256 * </tr>
aoqi@0 257 * <tr>
aoqi@0 258 * <td>name</td>
aoqi@0 259 * <td><code>xml element name</code></td>
aoqi@0 260 * </tr>
aoqi@0 261 * </thead>
aoqi@0 262 * <tbody>
aoqi@0 263 * <tr>
aoqi@0 264 * <td>value</td>
aoqi@0 265 * <td><code>instanceof declaredType</code></td>
aoqi@0 266 * </tr>
aoqi@0 267 * <tr>
aoqi@0 268 * <td>declaredType</td>
aoqi@0 269 * <td>unmarshal method <code>declaredType</code> parameter</td>
aoqi@0 270 * </tr>
aoqi@0 271 * <tr>
aoqi@0 272 * <td>scope</td>
aoqi@0 273 * <td><code>null</code> <i>(actual scope is unknown)</i></td>
aoqi@0 274 * </tr>
aoqi@0 275 * </tbody>
aoqi@0 276 * </table>
aoqi@0 277 * </blockquote>
aoqi@0 278 *
aoqi@0 279 * <p>
aoqi@0 280 * The following is an example of
aoqi@0 281 * <a href="#unmarshalByDeclaredType">unmarshal by declaredType method</a>.
aoqi@0 282 * <p>
aoqi@0 283 * Unmarshal by declaredType from a <tt>org.w3c.dom.Node</tt>:
aoqi@0 284 * <blockquote>
aoqi@0 285 * <pre>
aoqi@0 286 * Schema fragment for example
aoqi@0 287 * &lt;xs:schema>
aoqi@0 288 * &lt;xs:complexType name="FooType">...&lt;\xs:complexType>
aoqi@0 289 * &lt;!-- global element declaration "PurchaseOrder" -->
aoqi@0 290 * &lt;xs:element name="PurchaseOrder">
aoqi@0 291 * &lt;xs:complexType>
aoqi@0 292 * &lt;xs:sequence>
aoqi@0 293 * &lt;!-- local element declaration "foo" -->
aoqi@0 294 * &lt;xs:element name="foo" type="FooType"/>
aoqi@0 295 * ...
aoqi@0 296 * &lt;/xs:sequence>
aoqi@0 297 * &lt;/xs:complexType>
aoqi@0 298 * &lt;/xs:element>
aoqi@0 299 * &lt;/xs:schema>
aoqi@0 300 *
aoqi@0 301 * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0 302 * Unmarshaller u = jc.createUnmarshaller();
aoqi@0 303 *
aoqi@0 304 * DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
aoqi@0 305 * dbf.setNamespaceAware(true);
aoqi@0 306 * DocumentBuilder db = dbf.newDocumentBuilder();
aoqi@0 307 * Document doc = db.parse(new File( "nosferatu.xml"));
aoqi@0 308 * Element fooSubtree = ...; // traverse DOM till reach xml element foo, constrained by a
aoqi@0 309 * // local element declaration in schema.
aoqi@0 310 *
aoqi@0 311 * // FooType is the JAXB mapping of the type of local element declaration foo.
aoqi@0 312 * JAXBElement&lt;FooType> foo = u.unmarshal( fooSubtree, FooType.class);
aoqi@0 313 * </pre>
aoqi@0 314 * </blockquote>
aoqi@0 315 *
aoqi@0 316 * <p>
aoqi@0 317 * <b>Support for SAX2.0 Compliant Parsers</b><br>
aoqi@0 318 * <blockquote>
aoqi@0 319 * A client application has the ability to select the SAX2.0 compliant parser
aoqi@0 320 * of their choice. If a SAX parser is not selected, then the JAXB Provider's
aoqi@0 321 * default parser will be used. Even though the JAXB Provider's default parser
aoqi@0 322 * is not required to be SAX2.0 compliant, all providers are required to allow
aoqi@0 323 * a client application to specify their own SAX2.0 parser. Some providers may
aoqi@0 324 * require the client application to specify the SAX2.0 parser at schema compile
aoqi@0 325 * time. See {@link #unmarshal(javax.xml.transform.Source) unmarshal(Source)}
aoqi@0 326 * for more detail.
aoqi@0 327 * </blockquote>
aoqi@0 328 *
aoqi@0 329 * <p>
aoqi@0 330 * <b>Validation and Well-Formedness</b><br>
aoqi@0 331 * <blockquote>
aoqi@0 332 * <p>
aoqi@0 333 * A client application can enable or disable JAXP 1.3 validation
aoqi@0 334 * mechanism via the <tt>setSchema(javax.xml.validation.Schema)</tt> API.
aoqi@0 335 * Sophisticated clients can specify their own validating SAX 2.0 compliant
aoqi@0 336 * parser and bypass the JAXP 1.3 validation mechanism using the
aoqi@0 337 * {@link #unmarshal(javax.xml.transform.Source) unmarshal(Source)} API.
aoqi@0 338 *
aoqi@0 339 * <p>
aoqi@0 340 * Since unmarshalling invalid XML content is defined in JAXB 2.0,
aoqi@0 341 * the Unmarshaller default validation event handler was made more lenient
aoqi@0 342 * than in JAXB 1.0. When schema-derived code generated
aoqi@0 343 * by JAXB 1.0 binding compiler is registered with {@link JAXBContext},
aoqi@0 344 * the default unmarshal validation handler is
aoqi@0 345 * {@link javax.xml.bind.helpers.DefaultValidationEventHandler} and it
aoqi@0 346 * terminates the marshal operation after encountering either a fatal error or an error.
aoqi@0 347 * For a JAXB 2.0 client application, there is no explicitly defined default
aoqi@0 348 * validation handler and the default event handling only
aoqi@0 349 * terminates the unmarshal operation after encountering a fatal error.
aoqi@0 350 *
aoqi@0 351 * </blockquote>
aoqi@0 352 *
aoqi@0 353 * <p>
aoqi@0 354 * <a name="supportedProps"></a>
aoqi@0 355 * <b>Supported Properties</b><br>
aoqi@0 356 * <blockquote>
aoqi@0 357 * <p>
aoqi@0 358 * There currently are not any properties required to be supported by all
aoqi@0 359 * JAXB Providers on Unmarshaller. However, some providers may support
aoqi@0 360 * their own set of provider specific properties.
aoqi@0 361 * </blockquote>
aoqi@0 362 *
aoqi@0 363 * <p>
aoqi@0 364 * <a name="unmarshalEventCallback"></a>
aoqi@0 365 * <b>Unmarshal Event Callbacks</b><br>
aoqi@0 366 * <blockquote>
aoqi@0 367 * The {@link Unmarshaller} provides two styles of callback mechanisms
aoqi@0 368 * that allow application specific processing during key points in the
aoqi@0 369 * unmarshalling process. In 'class defined' event callbacks, application
aoqi@0 370 * specific code placed in JAXB mapped classes is triggered during
aoqi@0 371 * unmarshalling. 'External listeners' allow for centralized processing
aoqi@0 372 * of unmarshal events in one callback method rather than by type event callbacks.
aoqi@0 373 * <p>
aoqi@0 374 * 'Class defined' event callback methods allow any JAXB mapped class to specify
aoqi@0 375 * its own specific callback methods by defining methods with the following method signature:
aoqi@0 376 * <blockquote>
aoqi@0 377 * <pre>
aoqi@0 378 * // This method is called immediately after the object is created and before the unmarshalling of this
aoqi@0 379 * // object begins. The callback provides an opportunity to initialize JavaBean properties prior to unmarshalling.
aoqi@0 380 * void beforeUnmarshal(Unmarshaller, Object parent);
aoqi@0 381 *
aoqi@0 382 * //This method is called after all the properties (except IDREF) are unmarshalled for this object,
aoqi@0 383 * //but before this object is set to the parent object.
aoqi@0 384 * void afterUnmarshal(Unmarshaller, Object parent);
aoqi@0 385 * </pre>
aoqi@0 386 * </blockquote>
aoqi@0 387 * The class defined callback methods should be used when the callback method requires
aoqi@0 388 * access to non-public methods and/or fields of the class.
aoqi@0 389 * <p>
aoqi@0 390 * The external listener callback mechanism enables the registration of a {@link Listener}
aoqi@0 391 * instance with an {@link Unmarshaller#setListener(Listener)}. The external listener receives all callback events,
aoqi@0 392 * allowing for more centralized processing than per class defined callback methods. The external listener
aoqi@0 393 * receives events when unmarshalling proces is marshalling to a JAXB element or to JAXB mapped class.
aoqi@0 394 * <p>
aoqi@0 395 * The 'class defined' and external listener event callback methods are independent of each other,
aoqi@0 396 * both can be called for one event. The invocation ordering when both listener callback methods exist is
aoqi@0 397 * defined in {@link Listener#beforeUnmarshal(Object, Object)} and {@link Listener#afterUnmarshal(Object, Object)}.
aoqi@0 398 * <p>
aoqi@0 399 * An event callback method throwing an exception terminates the current unmarshal process.
aoqi@0 400 *
aoqi@0 401 * </blockquote>
aoqi@0 402 *
aoqi@0 403 * @author <ul><li>Ryan Shoemaker, Sun Microsystems, Inc.</li><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li><li>Joe Fialli, Sun Microsystems, Inc.</li></ul>
aoqi@0 404 * @see JAXBContext
aoqi@0 405 * @see Marshaller
aoqi@0 406 * @see Validator
aoqi@0 407 * @since JAXB1.0
aoqi@0 408 */
aoqi@0 409 public interface Unmarshaller {
aoqi@0 410
aoqi@0 411 /**
aoqi@0 412 * Unmarshal XML data from the specified file and return the resulting
aoqi@0 413 * content tree.
aoqi@0 414 *
aoqi@0 415 * <p>
aoqi@0 416 * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
aoqi@0 417 *
aoqi@0 418 * @param f the file to unmarshal XML data from
aoqi@0 419 * @return the newly created root object of the java content tree
aoqi@0 420 *
aoqi@0 421 * @throws JAXBException
aoqi@0 422 * If any unexpected errors occur while unmarshalling
aoqi@0 423 * @throws UnmarshalException
aoqi@0 424 * If the {@link ValidationEventHandler ValidationEventHandler}
aoqi@0 425 * returns false from its <tt>handleEvent</tt> method or the
aoqi@0 426 * <tt>Unmarshaller</tt> is unable to perform the XML to Java
aoqi@0 427 * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
aoqi@0 428 * @throws IllegalArgumentException
aoqi@0 429 * If the file parameter is null
aoqi@0 430 */
aoqi@0 431 public Object unmarshal( java.io.File f ) throws JAXBException;
aoqi@0 432
aoqi@0 433 /**
aoqi@0 434 * Unmarshal XML data from the specified InputStream and return the
aoqi@0 435 * resulting content tree. Validation event location information may
aoqi@0 436 * be incomplete when using this form of the unmarshal API.
aoqi@0 437 *
aoqi@0 438 * <p>
aoqi@0 439 * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
aoqi@0 440 *
aoqi@0 441 * @param is the InputStream to unmarshal XML data from
aoqi@0 442 * @return the newly created root object of the java content tree
aoqi@0 443 *
aoqi@0 444 * @throws JAXBException
aoqi@0 445 * If any unexpected errors occur while unmarshalling
aoqi@0 446 * @throws UnmarshalException
aoqi@0 447 * If the {@link ValidationEventHandler ValidationEventHandler}
aoqi@0 448 * returns false from its <tt>handleEvent</tt> method or the
aoqi@0 449 * <tt>Unmarshaller</tt> is unable to perform the XML to Java
aoqi@0 450 * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
aoqi@0 451 * @throws IllegalArgumentException
aoqi@0 452 * If the InputStream parameter is null
aoqi@0 453 */
aoqi@0 454 public Object unmarshal( java.io.InputStream is ) throws JAXBException;
aoqi@0 455
aoqi@0 456 /**
aoqi@0 457 * Unmarshal XML data from the specified Reader and return the
aoqi@0 458 * resulting content tree. Validation event location information may
aoqi@0 459 * be incomplete when using this form of the unmarshal API,
aoqi@0 460 * because a Reader does not provide the system ID.
aoqi@0 461 *
aoqi@0 462 * <p>
aoqi@0 463 * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
aoqi@0 464 *
aoqi@0 465 * @param reader the Reader to unmarshal XML data from
aoqi@0 466 * @return the newly created root object of the java content tree
aoqi@0 467 *
aoqi@0 468 * @throws JAXBException
aoqi@0 469 * If any unexpected errors occur while unmarshalling
aoqi@0 470 * @throws UnmarshalException
aoqi@0 471 * If the {@link ValidationEventHandler ValidationEventHandler}
aoqi@0 472 * returns false from its <tt>handleEvent</tt> method or the
aoqi@0 473 * <tt>Unmarshaller</tt> is unable to perform the XML to Java
aoqi@0 474 * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
aoqi@0 475 * @throws IllegalArgumentException
aoqi@0 476 * If the InputStream parameter is null
aoqi@0 477 * @since JAXB2.0
aoqi@0 478 */
aoqi@0 479 public Object unmarshal( Reader reader ) throws JAXBException;
aoqi@0 480
aoqi@0 481 /**
aoqi@0 482 * Unmarshal XML data from the specified URL and return the resulting
aoqi@0 483 * content tree.
aoqi@0 484 *
aoqi@0 485 * <p>
aoqi@0 486 * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
aoqi@0 487 *
aoqi@0 488 * @param url the url to unmarshal XML data from
aoqi@0 489 * @return the newly created root object of the java content tree
aoqi@0 490 *
aoqi@0 491 * @throws JAXBException
aoqi@0 492 * If any unexpected errors occur while unmarshalling
aoqi@0 493 * @throws UnmarshalException
aoqi@0 494 * If the {@link ValidationEventHandler ValidationEventHandler}
aoqi@0 495 * returns false from its <tt>handleEvent</tt> method or the
aoqi@0 496 * <tt>Unmarshaller</tt> is unable to perform the XML to Java
aoqi@0 497 * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
aoqi@0 498 * @throws IllegalArgumentException
aoqi@0 499 * If the URL parameter is null
aoqi@0 500 */
aoqi@0 501 public Object unmarshal( java.net.URL url ) throws JAXBException;
aoqi@0 502
aoqi@0 503 /**
aoqi@0 504 * Unmarshal XML data from the specified SAX InputSource and return the
aoqi@0 505 * resulting content tree.
aoqi@0 506 *
aoqi@0 507 * <p>
aoqi@0 508 * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
aoqi@0 509 *
aoqi@0 510 * @param source the input source to unmarshal XML data from
aoqi@0 511 * @return the newly created root object of the java content tree
aoqi@0 512 *
aoqi@0 513 * @throws JAXBException
aoqi@0 514 * If any unexpected errors occur while unmarshalling
aoqi@0 515 * @throws UnmarshalException
aoqi@0 516 * If the {@link ValidationEventHandler ValidationEventHandler}
aoqi@0 517 * returns false from its <tt>handleEvent</tt> method or the
aoqi@0 518 * <tt>Unmarshaller</tt> is unable to perform the XML to Java
aoqi@0 519 * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
aoqi@0 520 * @throws IllegalArgumentException
aoqi@0 521 * If the InputSource parameter is null
aoqi@0 522 */
aoqi@0 523 public Object unmarshal( org.xml.sax.InputSource source ) throws JAXBException;
aoqi@0 524
aoqi@0 525 /**
aoqi@0 526 * Unmarshal global XML data from the specified DOM tree and return the resulting
aoqi@0 527 * content tree.
aoqi@0 528 *
aoqi@0 529 * <p>
aoqi@0 530 * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
aoqi@0 531 *
aoqi@0 532 * @param node
aoqi@0 533 * the document/element to unmarshal XML data from.
aoqi@0 534 * The caller must support at least Document and Element.
aoqi@0 535 * @return the newly created root object of the java content tree
aoqi@0 536 *
aoqi@0 537 * @throws JAXBException
aoqi@0 538 * If any unexpected errors occur while unmarshalling
aoqi@0 539 * @throws UnmarshalException
aoqi@0 540 * If the {@link ValidationEventHandler ValidationEventHandler}
aoqi@0 541 * returns false from its <tt>handleEvent</tt> method or the
aoqi@0 542 * <tt>Unmarshaller</tt> is unable to perform the XML to Java
aoqi@0 543 * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
aoqi@0 544 * @throws IllegalArgumentException
aoqi@0 545 * If the Node parameter is null
aoqi@0 546 * @see #unmarshal(org.w3c.dom.Node, Class)
aoqi@0 547 */
aoqi@0 548 public Object unmarshal( org.w3c.dom.Node node ) throws JAXBException;
aoqi@0 549
aoqi@0 550 /**
aoqi@0 551 * Unmarshal XML data by JAXB mapped <tt>declaredType</tt>
aoqi@0 552 * and return the resulting content tree.
aoqi@0 553 *
aoqi@0 554 * <p>
aoqi@0 555 * Implements <a href="#unmarshalByDeclaredType">Unmarshal by Declared Type</a>
aoqi@0 556 *
aoqi@0 557 * @param node
aoqi@0 558 * the document/element to unmarshal XML data from.
aoqi@0 559 * The caller must support at least Document and Element.
aoqi@0 560 * @param declaredType
aoqi@0 561 * appropriate JAXB mapped class to hold <tt>node</tt>'s XML data.
aoqi@0 562 *
aoqi@0 563 * @return <a href="#unmarshalDeclaredTypeReturn">JAXB Element</a> representation of <tt>node</tt>
aoqi@0 564 *
aoqi@0 565 * @throws JAXBException
aoqi@0 566 * If any unexpected errors occur while unmarshalling
aoqi@0 567 * @throws UnmarshalException
aoqi@0 568 * If the {@link ValidationEventHandler ValidationEventHandler}
aoqi@0 569 * returns false from its <tt>handleEvent</tt> method or the
aoqi@0 570 * <tt>Unmarshaller</tt> is unable to perform the XML to Java
aoqi@0 571 * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
aoqi@0 572 * @throws IllegalArgumentException
aoqi@0 573 * If any parameter is null
aoqi@0 574 * @since JAXB2.0
aoqi@0 575 */
aoqi@0 576 public <T> JAXBElement<T> unmarshal( org.w3c.dom.Node node, Class<T> declaredType ) throws JAXBException;
aoqi@0 577
aoqi@0 578 /**
aoqi@0 579 * Unmarshal XML data from the specified XML Source and return the
aoqi@0 580 * resulting content tree.
aoqi@0 581 *
aoqi@0 582 * <p>
aoqi@0 583 * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
aoqi@0 584 *
aoqi@0 585 * <p>
aoqi@0 586 * <a name="saxParserPlugable"></a>
aoqi@0 587 * <b>SAX 2.0 Parser Pluggability</b>
aoqi@0 588 * <p>
aoqi@0 589 * A client application can choose not to use the default parser mechanism
aoqi@0 590 * supplied with their JAXB provider. Any SAX 2.0 compliant parser can be
aoqi@0 591 * substituted for the JAXB provider's default mechanism. To do so, the
aoqi@0 592 * client application must properly configure a <tt>SAXSource</tt> containing
aoqi@0 593 * an <tt>XMLReader</tt> implemented by the SAX 2.0 parser provider. If the
aoqi@0 594 * <tt>XMLReader</tt> has an <tt>org.xml.sax.ErrorHandler</tt> registered
aoqi@0 595 * on it, it will be replaced by the JAXB Provider so that validation errors
aoqi@0 596 * can be reported via the <tt>ValidationEventHandler</tt> mechanism of
aoqi@0 597 * JAXB. If the <tt>SAXSource</tt> does not contain an <tt>XMLReader</tt>,
aoqi@0 598 * then the JAXB provider's default parser mechanism will be used.
aoqi@0 599 * <p>
aoqi@0 600 * This parser replacement mechanism can also be used to replace the JAXB
aoqi@0 601 * provider's unmarshal-time validation engine. The client application
aoqi@0 602 * must properly configure their SAX 2.0 compliant parser to perform
aoqi@0 603 * validation (as shown in the example above). Any <tt>SAXParserExceptions
aoqi@0 604 * </tt> encountered by the parser during the unmarshal operation will be
aoqi@0 605 * processed by the JAXB provider and converted into JAXB
aoqi@0 606 * <tt>ValidationEvent</tt> objects which will be reported back to the
aoqi@0 607 * client via the <tt>ValidationEventHandler</tt> registered with the
aoqi@0 608 * <tt>Unmarshaller</tt>. <i>Note:</i> specifying a substitute validating
aoqi@0 609 * SAX 2.0 parser for unmarshalling does not necessarily replace the
aoqi@0 610 * validation engine used by the JAXB provider for performing on-demand
aoqi@0 611 * validation.
aoqi@0 612 * <p>
aoqi@0 613 * The only way for a client application to specify an alternate parser
aoqi@0 614 * mechanism to be used during unmarshal is via the
aoqi@0 615 * <tt>unmarshal(SAXSource)</tt> API. All other forms of the unmarshal
aoqi@0 616 * method (File, URL, Node, etc) will use the JAXB provider's default
aoqi@0 617 * parser and validator mechanisms.
aoqi@0 618 *
aoqi@0 619 * @param source the XML Source to unmarshal XML data from (providers are
aoqi@0 620 * only required to support SAXSource, DOMSource, and StreamSource)
aoqi@0 621 * @return the newly created root object of the java content tree
aoqi@0 622 *
aoqi@0 623 * @throws JAXBException
aoqi@0 624 * If any unexpected errors occur while unmarshalling
aoqi@0 625 * @throws UnmarshalException
aoqi@0 626 * If the {@link ValidationEventHandler ValidationEventHandler}
aoqi@0 627 * returns false from its <tt>handleEvent</tt> method or the
aoqi@0 628 * <tt>Unmarshaller</tt> is unable to perform the XML to Java
aoqi@0 629 * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
aoqi@0 630 * @throws IllegalArgumentException
aoqi@0 631 * If the Source parameter is null
aoqi@0 632 * @see #unmarshal(javax.xml.transform.Source, Class)
aoqi@0 633 */
aoqi@0 634 public Object unmarshal( javax.xml.transform.Source source )
aoqi@0 635 throws JAXBException;
aoqi@0 636
aoqi@0 637
aoqi@0 638 /**
aoqi@0 639 * Unmarshal XML data from the specified XML Source by <tt>declaredType</tt> and return the
aoqi@0 640 * resulting content tree.
aoqi@0 641 *
aoqi@0 642 * <p>
aoqi@0 643 * Implements <a href="#unmarshalByDeclaredType">Unmarshal by Declared Type</a>
aoqi@0 644 *
aoqi@0 645 * <p>
aoqi@0 646 * See <a href="#saxParserPlugable">SAX 2.0 Parser Pluggability</a>
aoqi@0 647 *
aoqi@0 648 * @param source the XML Source to unmarshal XML data from (providers are
aoqi@0 649 * only required to support SAXSource, DOMSource, and StreamSource)
aoqi@0 650 * @param declaredType
aoqi@0 651 * appropriate JAXB mapped class to hold <tt>source</tt>'s xml root element
aoqi@0 652 * @return Java content rooted by <a href="#unmarshalDeclaredTypeReturn">JAXB Element</a>
aoqi@0 653 *
aoqi@0 654 * @throws JAXBException
aoqi@0 655 * If any unexpected errors occur while unmarshalling
aoqi@0 656 * @throws UnmarshalException
aoqi@0 657 * If the {@link ValidationEventHandler ValidationEventHandler}
aoqi@0 658 * returns false from its <tt>handleEvent</tt> method or the
aoqi@0 659 * <tt>Unmarshaller</tt> is unable to perform the XML to Java
aoqi@0 660 * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
aoqi@0 661 * @throws IllegalArgumentException
aoqi@0 662 * If any parameter is null
aoqi@0 663 * @since JAXB2.0
aoqi@0 664 */
aoqi@0 665 public <T> JAXBElement<T> unmarshal( javax.xml.transform.Source source, Class<T> declaredType )
aoqi@0 666 throws JAXBException;
aoqi@0 667
aoqi@0 668 /**
aoqi@0 669 * Unmarshal XML data from the specified pull parser and return the
aoqi@0 670 * resulting content tree.
aoqi@0 671 *
aoqi@0 672 * <p>
aoqi@0 673 * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
aoqi@0 674 *
aoqi@0 675 * <p>
aoqi@0 676 * This method assumes that the parser is on a START_DOCUMENT or
aoqi@0 677 * START_ELEMENT event. Unmarshalling will be done from this
aoqi@0 678 * start event to the corresponding end event. If this method
aoqi@0 679 * returns successfully, the <tt>reader</tt> will be pointing at
aoqi@0 680 * the token right after the end event.
aoqi@0 681 *
aoqi@0 682 * @param reader
aoqi@0 683 * The parser to be read.
aoqi@0 684 * @return
aoqi@0 685 * the newly created root object of the java content tree.
aoqi@0 686 *
aoqi@0 687 * @throws JAXBException
aoqi@0 688 * If any unexpected errors occur while unmarshalling
aoqi@0 689 * @throws UnmarshalException
aoqi@0 690 * If the {@link ValidationEventHandler ValidationEventHandler}
aoqi@0 691 * returns false from its <tt>handleEvent</tt> method or the
aoqi@0 692 * <tt>Unmarshaller</tt> is unable to perform the XML to Java
aoqi@0 693 * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
aoqi@0 694 * @throws IllegalArgumentException
aoqi@0 695 * If the <tt>reader</tt> parameter is null
aoqi@0 696 * @throws IllegalStateException
aoqi@0 697 * If <tt>reader</tt> is not pointing to a START_DOCUMENT or
aoqi@0 698 * START_ELEMENT event.
aoqi@0 699 * @since JAXB2.0
aoqi@0 700 * @see #unmarshal(javax.xml.stream.XMLStreamReader, Class)
aoqi@0 701 */
aoqi@0 702 public Object unmarshal( javax.xml.stream.XMLStreamReader reader )
aoqi@0 703 throws JAXBException;
aoqi@0 704
aoqi@0 705 /**
aoqi@0 706 * Unmarshal root element to JAXB mapped <tt>declaredType</tt>
aoqi@0 707 * and return the resulting content tree.
aoqi@0 708 *
aoqi@0 709 * <p>
aoqi@0 710 * This method implements <a href="#unmarshalByDeclaredType">unmarshal by declaredType</a>.
aoqi@0 711 * <p>
aoqi@0 712 * This method assumes that the parser is on a START_DOCUMENT or
aoqi@0 713 * START_ELEMENT event. Unmarshalling will be done from this
aoqi@0 714 * start event to the corresponding end event. If this method
aoqi@0 715 * returns successfully, the <tt>reader</tt> will be pointing at
aoqi@0 716 * the token right after the end event.
aoqi@0 717 *
aoqi@0 718 * @param reader
aoqi@0 719 * The parser to be read.
aoqi@0 720 * @param declaredType
aoqi@0 721 * appropriate JAXB mapped class to hold <tt>reader</tt>'s START_ELEMENT XML data.
aoqi@0 722 *
aoqi@0 723 * @return content tree rooted by <a href="#unmarshalDeclaredTypeReturn">JAXB Element representation</a>
aoqi@0 724 *
aoqi@0 725 * @throws JAXBException
aoqi@0 726 * If any unexpected errors occur while unmarshalling
aoqi@0 727 * @throws UnmarshalException
aoqi@0 728 * If the {@link ValidationEventHandler ValidationEventHandler}
aoqi@0 729 * returns false from its <tt>handleEvent</tt> method or the
aoqi@0 730 * <tt>Unmarshaller</tt> is unable to perform the XML to Java
aoqi@0 731 * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
aoqi@0 732 * @throws IllegalArgumentException
aoqi@0 733 * If any parameter is null
aoqi@0 734 * @since JAXB2.0
aoqi@0 735 */
aoqi@0 736 public <T> JAXBElement<T> unmarshal( javax.xml.stream.XMLStreamReader reader, Class<T> declaredType ) throws JAXBException;
aoqi@0 737
aoqi@0 738 /**
aoqi@0 739 * Unmarshal XML data from the specified pull parser and return the
aoqi@0 740 * resulting content tree.
aoqi@0 741 *
aoqi@0 742 * <p>
aoqi@0 743 * This method is an <a href="#unmarshalGlobal">Unmarshal Global Root method</a>.
aoqi@0 744 *
aoqi@0 745 * <p>
aoqi@0 746 * This method assumes that the parser is on a START_DOCUMENT or
aoqi@0 747 * START_ELEMENT event. Unmarshalling will be done from this
aoqi@0 748 * start event to the corresponding end event. If this method
aoqi@0 749 * returns successfully, the <tt>reader</tt> will be pointing at
aoqi@0 750 * the token right after the end event.
aoqi@0 751 *
aoqi@0 752 * @param reader
aoqi@0 753 * The parser to be read.
aoqi@0 754 * @return
aoqi@0 755 * the newly created root object of the java content tree.
aoqi@0 756 *
aoqi@0 757 * @throws JAXBException
aoqi@0 758 * If any unexpected errors occur while unmarshalling
aoqi@0 759 * @throws UnmarshalException
aoqi@0 760 * If the {@link ValidationEventHandler ValidationEventHandler}
aoqi@0 761 * returns false from its <tt>handleEvent</tt> method or the
aoqi@0 762 * <tt>Unmarshaller</tt> is unable to perform the XML to Java
aoqi@0 763 * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
aoqi@0 764 * @throws IllegalArgumentException
aoqi@0 765 * If the <tt>reader</tt> parameter is null
aoqi@0 766 * @throws IllegalStateException
aoqi@0 767 * If <tt>reader</tt> is not pointing to a START_DOCUMENT or
aoqi@0 768 * START_ELEMENT event.
aoqi@0 769 * @since JAXB2.0
aoqi@0 770 * @see #unmarshal(javax.xml.stream.XMLEventReader, Class)
aoqi@0 771 */
aoqi@0 772 public Object unmarshal( javax.xml.stream.XMLEventReader reader )
aoqi@0 773 throws JAXBException;
aoqi@0 774
aoqi@0 775 /**
aoqi@0 776 * Unmarshal root element to JAXB mapped <tt>declaredType</tt>
aoqi@0 777 * and return the resulting content tree.
aoqi@0 778 *
aoqi@0 779 * <p>
aoqi@0 780 * This method implements <a href="#unmarshalByDeclaredType">unmarshal by declaredType</a>.
aoqi@0 781 *
aoqi@0 782 * <p>
aoqi@0 783 * This method assumes that the parser is on a START_DOCUMENT or
aoqi@0 784 * START_ELEMENT event. Unmarshalling will be done from this
aoqi@0 785 * start event to the corresponding end event. If this method
aoqi@0 786 * returns successfully, the <tt>reader</tt> will be pointing at
aoqi@0 787 * the token right after the end event.
aoqi@0 788 *
aoqi@0 789 * @param reader
aoqi@0 790 * The parser to be read.
aoqi@0 791 * @param declaredType
aoqi@0 792 * appropriate JAXB mapped class to hold <tt>reader</tt>'s START_ELEMENT XML data.
aoqi@0 793 *
aoqi@0 794 * @return content tree rooted by <a href="#unmarshalDeclaredTypeReturn">JAXB Element representation</a>
aoqi@0 795 *
aoqi@0 796 * @throws JAXBException
aoqi@0 797 * If any unexpected errors occur while unmarshalling
aoqi@0 798 * @throws UnmarshalException
aoqi@0 799 * If the {@link ValidationEventHandler ValidationEventHandler}
aoqi@0 800 * returns false from its <tt>handleEvent</tt> method or the
aoqi@0 801 * <tt>Unmarshaller</tt> is unable to perform the XML to Java
aoqi@0 802 * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
aoqi@0 803 * @throws IllegalArgumentException
aoqi@0 804 * If any parameter is null
aoqi@0 805 * @since JAXB2.0
aoqi@0 806 */
aoqi@0 807 public <T> JAXBElement<T> unmarshal( javax.xml.stream.XMLEventReader reader, Class<T> declaredType ) throws JAXBException;
aoqi@0 808
aoqi@0 809 /**
aoqi@0 810 * Get an unmarshaller handler object that can be used as a component in
aoqi@0 811 * an XML pipeline.
aoqi@0 812 *
aoqi@0 813 * <p>
aoqi@0 814 * The JAXB Provider can return the same handler object for multiple
aoqi@0 815 * invocations of this method. In other words, this method does not
aoqi@0 816 * necessarily create a new instance of <tt>UnmarshallerHandler</tt>. If the
aoqi@0 817 * application needs to use more than one <tt>UnmarshallerHandler</tt>, it
aoqi@0 818 * should create more than one <tt>Unmarshaller</tt>.
aoqi@0 819 *
aoqi@0 820 * @return the unmarshaller handler object
aoqi@0 821 * @see UnmarshallerHandler
aoqi@0 822 */
aoqi@0 823 public UnmarshallerHandler getUnmarshallerHandler();
aoqi@0 824
aoqi@0 825 /**
aoqi@0 826 * Specifies whether or not the default validation mechanism of the
aoqi@0 827 * <tt>Unmarshaller</tt> should validate during unmarshal operations.
aoqi@0 828 * By default, the <tt>Unmarshaller</tt> does not validate.
aoqi@0 829 * <p>
aoqi@0 830 * This method may only be invoked before or after calling one of the
aoqi@0 831 * unmarshal methods.
aoqi@0 832 * <p>
aoqi@0 833 * This method only controls the JAXB Provider's default unmarshal-time
aoqi@0 834 * validation mechanism - it has no impact on clients that specify their
aoqi@0 835 * own validating SAX 2.0 compliant parser. Clients that specify their
aoqi@0 836 * own unmarshal-time validation mechanism may wish to turn off the JAXB
aoqi@0 837 * Provider's default validation mechanism via this API to avoid "double
aoqi@0 838 * validation".
aoqi@0 839 * <p>
aoqi@0 840 * This method is deprecated as of JAXB 2.0 - please use the new
aoqi@0 841 * {@link #setSchema(javax.xml.validation.Schema)} API.
aoqi@0 842 *
aoqi@0 843 * @param validating true if the Unmarshaller should validate during
aoqi@0 844 * unmarshal, false otherwise
aoqi@0 845 * @throws JAXBException if an error occurred while enabling or disabling
aoqi@0 846 * validation at unmarshal time
aoqi@0 847 * @throws UnsupportedOperationException could be thrown if this method is
aoqi@0 848 * invoked on an Unmarshaller created from a JAXBContext referencing
aoqi@0 849 * JAXB 2.0 mapped classes
aoqi@0 850 * @deprecated since JAXB2.0, please see {@link #setSchema(javax.xml.validation.Schema)}
aoqi@0 851 */
aoqi@0 852 public void setValidating( boolean validating )
aoqi@0 853 throws JAXBException;
aoqi@0 854
aoqi@0 855 /**
aoqi@0 856 * Indicates whether or not the <tt>Unmarshaller</tt> is configured to
aoqi@0 857 * validate during unmarshal operations.
aoqi@0 858 * <p>
aoqi@0 859 * This API returns the state of the JAXB Provider's default unmarshal-time
aoqi@0 860 * validation mechanism.
aoqi@0 861 * <p>
aoqi@0 862 * This method is deprecated as of JAXB 2.0 - please use the new
aoqi@0 863 * {@link #getSchema()} API.
aoqi@0 864 *
aoqi@0 865 * @return true if the Unmarshaller is configured to validate during
aoqi@0 866 * unmarshal operations, false otherwise
aoqi@0 867 * @throws JAXBException if an error occurs while retrieving the validating
aoqi@0 868 * flag
aoqi@0 869 * @throws UnsupportedOperationException could be thrown if this method is
aoqi@0 870 * invoked on an Unmarshaller created from a JAXBContext referencing
aoqi@0 871 * JAXB 2.0 mapped classes
aoqi@0 872 * @deprecated since JAXB2.0, please see {@link #getSchema()}
aoqi@0 873 */
aoqi@0 874 public boolean isValidating()
aoqi@0 875 throws JAXBException;
aoqi@0 876
aoqi@0 877 /**
aoqi@0 878 * Allow an application to register a <tt>ValidationEventHandler</tt>.
aoqi@0 879 * <p>
aoqi@0 880 * The <tt>ValidationEventHandler</tt> will be called by the JAXB Provider
aoqi@0 881 * if any validation errors are encountered during calls to any of the
aoqi@0 882 * unmarshal methods. If the client application does not register a
aoqi@0 883 * <tt>ValidationEventHandler</tt> before invoking the unmarshal methods,
aoqi@0 884 * then <tt>ValidationEvents</tt> will be handled by the default event
aoqi@0 885 * handler which will terminate the unmarshal operation after the first
aoqi@0 886 * error or fatal error is encountered.
aoqi@0 887 * <p>
aoqi@0 888 * Calling this method with a null parameter will cause the Unmarshaller
aoqi@0 889 * to revert back to the default event handler.
aoqi@0 890 *
aoqi@0 891 * @param handler the validation event handler
aoqi@0 892 * @throws JAXBException if an error was encountered while setting the
aoqi@0 893 * event handler
aoqi@0 894 */
aoqi@0 895 public void setEventHandler( ValidationEventHandler handler )
aoqi@0 896 throws JAXBException;
aoqi@0 897
aoqi@0 898 /**
aoqi@0 899 * Return the current event handler or the default event handler if one
aoqi@0 900 * hasn't been set.
aoqi@0 901 *
aoqi@0 902 * @return the current ValidationEventHandler or the default event handler
aoqi@0 903 * if it hasn't been set
aoqi@0 904 * @throws JAXBException if an error was encountered while getting the
aoqi@0 905 * current event handler
aoqi@0 906 */
aoqi@0 907 public ValidationEventHandler getEventHandler()
aoqi@0 908 throws JAXBException;
aoqi@0 909
aoqi@0 910 /**
aoqi@0 911 * Set the particular property in the underlying implementation of
aoqi@0 912 * <tt>Unmarshaller</tt>. This method can only be used to set one of
aoqi@0 913 * the standard JAXB defined properties above or a provider specific
aoqi@0 914 * property. Attempting to set an undefined property will result in
aoqi@0 915 * a PropertyException being thrown. See <a href="#supportedProps">
aoqi@0 916 * Supported Properties</a>.
aoqi@0 917 *
aoqi@0 918 * @param name the name of the property to be set. This value can either
aoqi@0 919 * be specified using one of the constant fields or a user
aoqi@0 920 * supplied string.
aoqi@0 921 * @param value the value of the property to be set
aoqi@0 922 *
aoqi@0 923 * @throws PropertyException when there is an error processing the given
aoqi@0 924 * property or value
aoqi@0 925 * @throws IllegalArgumentException
aoqi@0 926 * If the name parameter is null
aoqi@0 927 */
aoqi@0 928 public void setProperty( String name, Object value )
aoqi@0 929 throws PropertyException;
aoqi@0 930
aoqi@0 931 /**
aoqi@0 932 * Get the particular property in the underlying implementation of
aoqi@0 933 * <tt>Unmarshaller</tt>. This method can only be used to get one of
aoqi@0 934 * the standard JAXB defined properties above or a provider specific
aoqi@0 935 * property. Attempting to get an undefined property will result in
aoqi@0 936 * a PropertyException being thrown. See <a href="#supportedProps">
aoqi@0 937 * Supported Properties</a>.
aoqi@0 938 *
aoqi@0 939 * @param name the name of the property to retrieve
aoqi@0 940 * @return the value of the requested property
aoqi@0 941 *
aoqi@0 942 * @throws PropertyException
aoqi@0 943 * when there is an error retrieving the given property or value
aoqi@0 944 * property name
aoqi@0 945 * @throws IllegalArgumentException
aoqi@0 946 * If the name parameter is null
aoqi@0 947 */
aoqi@0 948 public Object getProperty( String name ) throws PropertyException;
aoqi@0 949
aoqi@0 950 /**
aoqi@0 951 * Specify the JAXP 1.3 {@link javax.xml.validation.Schema Schema}
aoqi@0 952 * object that should be used to validate subsequent unmarshal operations
aoqi@0 953 * against. Passing null into this method will disable validation.
aoqi@0 954 * <p>
aoqi@0 955 * This method replaces the deprecated {@link #setValidating(boolean) setValidating(boolean)}
aoqi@0 956 * API.
aoqi@0 957 *
aoqi@0 958 * <p>
aoqi@0 959 * Initially this property is set to <tt>null</tt>.
aoqi@0 960 *
aoqi@0 961 * @param schema Schema object to validate unmarshal operations against or null to disable validation
aoqi@0 962 * @throws UnsupportedOperationException could be thrown if this method is
aoqi@0 963 * invoked on an Unmarshaller created from a JAXBContext referencing
aoqi@0 964 * JAXB 1.0 mapped classes
aoqi@0 965 * @since JAXB2.0
aoqi@0 966 */
aoqi@0 967 public void setSchema( javax.xml.validation.Schema schema );
aoqi@0 968
aoqi@0 969 /**
aoqi@0 970 * Get the JAXP 1.3 {@link javax.xml.validation.Schema Schema} object
aoqi@0 971 * being used to perform unmarshal-time validation. If there is no
aoqi@0 972 * Schema set on the unmarshaller, then this method will return null
aoqi@0 973 * indicating that unmarshal-time validation will not be performed.
aoqi@0 974 * <p>
aoqi@0 975 * This method provides replacement functionality for the deprecated
aoqi@0 976 * {@link #isValidating()} API as well as access to the Schema object.
aoqi@0 977 * To determine if the Unmarshaller has validation enabled, simply
aoqi@0 978 * test the return type for null:
aoqi@0 979 * <p>
aoqi@0 980 * <code>
aoqi@0 981 * boolean isValidating = u.getSchema()!=null;
aoqi@0 982 * </code>
aoqi@0 983 *
aoqi@0 984 * @return the Schema object being used to perform unmarshal-time
aoqi@0 985 * validation or null if not present
aoqi@0 986 * @throws UnsupportedOperationException could be thrown if this method is
aoqi@0 987 * invoked on an Unmarshaller created from a JAXBContext referencing
aoqi@0 988 * JAXB 1.0 mapped classes
aoqi@0 989 * @since JAXB2.0
aoqi@0 990 */
aoqi@0 991 public javax.xml.validation.Schema getSchema();
aoqi@0 992
aoqi@0 993 /**
aoqi@0 994 * Associates a configured instance of {@link XmlAdapter} with this unmarshaller.
aoqi@0 995 *
aoqi@0 996 * <p>
aoqi@0 997 * This is a convenience method that invokes <code>setAdapter(adapter.getClass(),adapter);</code>.
aoqi@0 998 *
aoqi@0 999 * @see #setAdapter(Class,XmlAdapter)
aoqi@0 1000 * @throws IllegalArgumentException
aoqi@0 1001 * if the adapter parameter is null.
aoqi@0 1002 * @throws UnsupportedOperationException
aoqi@0 1003 * if invoked agains a JAXB 1.0 implementation.
aoqi@0 1004 * @since JAXB2.0
aoqi@0 1005 */
aoqi@0 1006 public void setAdapter( XmlAdapter adapter );
aoqi@0 1007
aoqi@0 1008 /**
aoqi@0 1009 * Associates a configured instance of {@link XmlAdapter} with this unmarshaller.
aoqi@0 1010 *
aoqi@0 1011 * <p>
aoqi@0 1012 * Every unmarshaller internally maintains a
aoqi@0 1013 * {@link java.util.Map}&lt;{@link Class},{@link XmlAdapter}>,
aoqi@0 1014 * which it uses for unmarshalling classes whose fields/methods are annotated
aoqi@0 1015 * with {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter}.
aoqi@0 1016 *
aoqi@0 1017 * <p>
aoqi@0 1018 * This method allows applications to use a configured instance of {@link XmlAdapter}.
aoqi@0 1019 * When an instance of an adapter is not given, an unmarshaller will create
aoqi@0 1020 * one by invoking its default constructor.
aoqi@0 1021 *
aoqi@0 1022 * @param type
aoqi@0 1023 * The type of the adapter. The specified instance will be used when
aoqi@0 1024 * {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter#value()}
aoqi@0 1025 * refers to this type.
aoqi@0 1026 * @param adapter
aoqi@0 1027 * The instance of the adapter to be used. If null, it will un-register
aoqi@0 1028 * the current adapter set for this type.
aoqi@0 1029 * @throws IllegalArgumentException
aoqi@0 1030 * if the type parameter is null.
aoqi@0 1031 * @throws UnsupportedOperationException
aoqi@0 1032 * if invoked agains a JAXB 1.0 implementation.
aoqi@0 1033 * @since JAXB2.0
aoqi@0 1034 */
aoqi@0 1035 public <A extends XmlAdapter> void setAdapter( Class<A> type, A adapter );
aoqi@0 1036
aoqi@0 1037 /**
aoqi@0 1038 * Gets the adapter associated with the specified type.
aoqi@0 1039 *
aoqi@0 1040 * This is the reverse operation of the {@link #setAdapter} method.
aoqi@0 1041 *
aoqi@0 1042 * @throws IllegalArgumentException
aoqi@0 1043 * if the type parameter is null.
aoqi@0 1044 * @throws UnsupportedOperationException
aoqi@0 1045 * if invoked agains a JAXB 1.0 implementation.
aoqi@0 1046 * @since JAXB2.0
aoqi@0 1047 */
aoqi@0 1048 public <A extends XmlAdapter> A getAdapter( Class<A> type );
aoqi@0 1049
aoqi@0 1050 /**
aoqi@0 1051 * <p>Associate a context that resolves cid's, content-id URIs, to
aoqi@0 1052 * binary data passed as attachments.</p>
aoqi@0 1053 * <p/>
aoqi@0 1054 * <p>Unmarshal time validation, enabled via {@link #setSchema(Schema)},
aoqi@0 1055 * must be supported even when unmarshaller is performing XOP processing.
aoqi@0 1056 * </p>
aoqi@0 1057 *
aoqi@0 1058 * @throws IllegalStateException if attempt to concurrently call this
aoqi@0 1059 * method during a unmarshal operation.
aoqi@0 1060 */
aoqi@0 1061 void setAttachmentUnmarshaller(AttachmentUnmarshaller au);
aoqi@0 1062
aoqi@0 1063 AttachmentUnmarshaller getAttachmentUnmarshaller();
aoqi@0 1064
aoqi@0 1065 /**
aoqi@0 1066 * <p/>
aoqi@0 1067 * Register an instance of an implementation of this class with {@link Unmarshaller} to externally listen
aoqi@0 1068 * for unmarshal events.
aoqi@0 1069 * <p/>
aoqi@0 1070 * <p/>
aoqi@0 1071 * This class enables pre and post processing of an instance of a JAXB mapped class
aoqi@0 1072 * as XML data is unmarshalled into it. The event callbacks are called when unmarshalling
aoqi@0 1073 * XML content into a JAXBElement instance or a JAXB mapped class that represents a complex type definition.
aoqi@0 1074 * The event callbacks are not called when unmarshalling to an instance of a
aoqi@0 1075 * Java datatype that represents a simple type definition.
aoqi@0 1076 * <p/>
aoqi@0 1077 * <p/>
aoqi@0 1078 * External listener is one of two different mechanisms for defining unmarshal event callbacks.
aoqi@0 1079 * See <a href="Unmarshaller.html#unmarshalEventCallback">Unmarshal Event Callbacks</a> for an overview.
aoqi@0 1080 * <p/>
aoqi@0 1081 * (@link #setListener(Listener)}
aoqi@0 1082 * (@link #getListener()}
aoqi@0 1083 *
aoqi@0 1084 * @since JAXB2.0
aoqi@0 1085 */
aoqi@0 1086 public static abstract class Listener {
aoqi@0 1087 /**
aoqi@0 1088 * <p/>
aoqi@0 1089 * Callback method invoked before unmarshalling into <tt>target</tt>.
aoqi@0 1090 * <p/>
aoqi@0 1091 * <p/>
aoqi@0 1092 * This method is invoked immediately after <tt>target</tt> was created and
aoqi@0 1093 * before the unmarshalling of this object begins. Note that
aoqi@0 1094 * if the class of <tt>target</tt> defines its own <tt>beforeUnmarshal</tt> method,
aoqi@0 1095 * the class specific callback method is invoked before this method is invoked.
aoqi@0 1096 *
aoqi@0 1097 * @param target non-null instance of JAXB mapped class prior to unmarshalling into it.
aoqi@0 1098 * @param parent instance of JAXB mapped class that will eventually reference <tt>target</tt>.
aoqi@0 1099 * <tt>null</tt> when <tt>target</tt> is root element.
aoqi@0 1100 */
aoqi@0 1101 public void beforeUnmarshal(Object target, Object parent) {
aoqi@0 1102 }
aoqi@0 1103
aoqi@0 1104 /**
aoqi@0 1105 * <p/>
aoqi@0 1106 * Callback method invoked after unmarshalling XML data into <tt>target</tt>.
aoqi@0 1107 * <p/>
aoqi@0 1108 * <p/>
aoqi@0 1109 * This method is invoked after all the properties (except IDREF) are unmarshalled into <tt>target</tt>,
aoqi@0 1110 * but before <tt>target</tt> is set into its <tt>parent</tt> object.
aoqi@0 1111 * Note that if the class of <tt>target</tt> defines its own <tt>afterUnmarshal</tt> method,
aoqi@0 1112 * the class specific callback method is invoked before this method is invoked.
aoqi@0 1113 *
aoqi@0 1114 * @param target non-null instance of JAXB mapped class prior to unmarshalling into it.
aoqi@0 1115 * @param parent instance of JAXB mapped class that will reference <tt>target</tt>.
aoqi@0 1116 * <tt>null</tt> when <tt>target</tt> is root element.
aoqi@0 1117 */
aoqi@0 1118 public void afterUnmarshal(Object target, Object parent) {
aoqi@0 1119 }
aoqi@0 1120 }
aoqi@0 1121
aoqi@0 1122 /**
aoqi@0 1123 * <p>
aoqi@0 1124 * Register unmarshal event callback {@link Listener} with this {@link Unmarshaller}.
aoqi@0 1125 *
aoqi@0 1126 * <p>
aoqi@0 1127 * There is only one Listener per Unmarshaller. Setting a Listener replaces the previous set Listener.
aoqi@0 1128 * One can unregister current Listener by setting listener to <tt>null</tt>.
aoqi@0 1129 *
aoqi@0 1130 * @param listener provides unmarshal event callbacks for this {@link Unmarshaller}
aoqi@0 1131 * @since JAXB2.0
aoqi@0 1132 */
aoqi@0 1133 public void setListener(Listener listener);
aoqi@0 1134
aoqi@0 1135 /**
aoqi@0 1136 * <p>Return {@link Listener} registered with this {@link Unmarshaller}.
aoqi@0 1137 *
aoqi@0 1138 * @return registered {@link Listener} or <code>null</code> if no Listener is registered with this Unmarshaller.
aoqi@0 1139 * @since JAXB2.0
aoqi@0 1140 */
aoqi@0 1141 public Listener getListener();
aoqi@0 1142 }

mercurial