aoqi@0: /* aoqi@0: * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package javax.xml.bind; aoqi@0: aoqi@0: import javax.xml.bind.annotation.adapters.XmlAdapter; aoqi@0: import javax.xml.bind.attachment.AttachmentUnmarshaller; aoqi@0: import javax.xml.validation.Schema; aoqi@0: import java.io.Reader; aoqi@0: aoqi@0: /** aoqi@0: * The Unmarshaller class governs the process of deserializing XML aoqi@0: * data into newly created Java content trees, optionally validating the XML aoqi@0: * data as it is unmarshalled. It provides an overloading of unmarshal methods aoqi@0: * for many different input kinds. aoqi@0: * aoqi@0: *

aoqi@0: * Unmarshalling from a File: aoqi@0: *

aoqi@0: *
aoqi@0:  *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0:  *       Unmarshaller u = jc.createUnmarshaller();
aoqi@0:  *       Object o = u.unmarshal( new File( "nosferatu.xml" ) );
aoqi@0:  *    
aoqi@0: *
aoqi@0: * aoqi@0: * aoqi@0: *

aoqi@0: * Unmarshalling from an InputStream: aoqi@0: *

aoqi@0: *
aoqi@0:  *       InputStream is = new FileInputStream( "nosferatu.xml" );
aoqi@0:  *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0:  *       Unmarshaller u = jc.createUnmarshaller();
aoqi@0:  *       Object o = u.unmarshal( is );
aoqi@0:  *    
aoqi@0: *
aoqi@0: * aoqi@0: *

aoqi@0: * Unmarshalling from a URL: aoqi@0: *

aoqi@0: *
aoqi@0:  *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0:  *       Unmarshaller u = jc.createUnmarshaller();
aoqi@0:  *       URL url = new URL( "http://beaker.east/nosferatu.xml" );
aoqi@0:  *       Object o = u.unmarshal( url );
aoqi@0:  *    
aoqi@0: *
aoqi@0: * aoqi@0: *

aoqi@0: * Unmarshalling from a StringBuffer using a aoqi@0: * javax.xml.transform.stream.StreamSource: aoqi@0: *

aoqi@0: *
aoqi@0:  *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0:  *       Unmarshaller u = jc.createUnmarshaller();
aoqi@0:  *       StringBuffer xmlStr = new StringBuffer( "<?xml version="1.0"?>..." );
aoqi@0:  *       Object o = u.unmarshal( new StreamSource( new StringReader( xmlStr.toString() ) ) );
aoqi@0:  *    
aoqi@0: *
aoqi@0: * aoqi@0: *

aoqi@0: * Unmarshalling from a org.w3c.dom.Node: aoqi@0: *

aoqi@0: *
aoqi@0:  *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0:  *       Unmarshaller u = jc.createUnmarshaller();
aoqi@0:  *
aoqi@0:  *       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
aoqi@0:  *       dbf.setNamespaceAware(true);
aoqi@0:  *       DocumentBuilder db = dbf.newDocumentBuilder();
aoqi@0:  *       Document doc = db.parse(new File( "nosferatu.xml"));
aoqi@0: 
aoqi@0:  *       Object o = u.unmarshal( doc );
aoqi@0:  *    
aoqi@0: *
aoqi@0: * aoqi@0: *

aoqi@0: * Unmarshalling from a javax.xml.transform.sax.SAXSource using a aoqi@0: * client specified validating SAX2.0 parser: aoqi@0: *

aoqi@0: *
aoqi@0:  *       // configure a validating SAX2.0 parser (Xerces2)
aoqi@0:  *       static final String JAXP_SCHEMA_LANGUAGE =
aoqi@0:  *           "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
aoqi@0:  *       static final String JAXP_SCHEMA_LOCATION =
aoqi@0:  *           "http://java.sun.com/xml/jaxp/properties/schemaSource";
aoqi@0:  *       static final String W3C_XML_SCHEMA =
aoqi@0:  *           "http://www.w3.org/2001/XMLSchema";
aoqi@0:  *
aoqi@0:  *       System.setProperty( "javax.xml.parsers.SAXParserFactory",
aoqi@0:  *                           "org.apache.xerces.jaxp.SAXParserFactoryImpl" );
aoqi@0:  *
aoqi@0:  *       SAXParserFactory spf = SAXParserFactory.newInstance();
aoqi@0:  *       spf.setNamespaceAware(true);
aoqi@0:  *       spf.setValidating(true);
aoqi@0:  *       SAXParser saxParser = spf.newSAXParser();
aoqi@0:  *
aoqi@0:  *       try {
aoqi@0:  *           saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
aoqi@0:  *           saxParser.setProperty(JAXP_SCHEMA_LOCATION, "http://....");
aoqi@0:  *       } catch (SAXNotRecognizedException x) {
aoqi@0:  *           // exception handling omitted
aoqi@0:  *       }
aoqi@0:  *
aoqi@0:  *       XMLReader xmlReader = saxParser.getXMLReader();
aoqi@0:  *       SAXSource source =
aoqi@0:  *           new SAXSource( xmlReader, new InputSource( "http://..." ) );
aoqi@0:  *
aoqi@0:  *       // Setup JAXB to unmarshal
aoqi@0:  *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0:  *       Unmarshaller u = jc.createUnmarshaller();
aoqi@0:  *       ValidationEventCollector vec = new ValidationEventCollector();
aoqi@0:  *       u.setEventHandler( vec );
aoqi@0:  *
aoqi@0:  *       // turn off the JAXB provider's default validation mechanism to
aoqi@0:  *       // avoid duplicate validation
aoqi@0:  *       u.setValidating( false )
aoqi@0:  *
aoqi@0:  *       // unmarshal
aoqi@0:  *       Object o = u.unmarshal( source );
aoqi@0:  *
aoqi@0:  *       // check for events
aoqi@0:  *       if( vec.hasEvents() ) {
aoqi@0:  *          // iterate over events
aoqi@0:  *       }
aoqi@0:  *    
aoqi@0: *
aoqi@0: * aoqi@0: *

aoqi@0: * Unmarshalling from a StAX XMLStreamReader: aoqi@0: *

aoqi@0: *
aoqi@0:  *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0:  *       Unmarshaller u = jc.createUnmarshaller();
aoqi@0:  *
aoqi@0:  *       javax.xml.stream.XMLStreamReader xmlStreamReader =
aoqi@0:  *           javax.xml.stream.XMLInputFactory().newInstance().createXMLStreamReader( ... );
aoqi@0:  *
aoqi@0:  *       Object o = u.unmarshal( xmlStreamReader );
aoqi@0:  *    
aoqi@0: *
aoqi@0: * aoqi@0: *

aoqi@0: * Unmarshalling from a StAX XMLEventReader: aoqi@0: *

aoqi@0: *
aoqi@0:  *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0:  *       Unmarshaller u = jc.createUnmarshaller();
aoqi@0:  *
aoqi@0:  *       javax.xml.stream.XMLEventReader xmlEventReader =
aoqi@0:  *           javax.xml.stream.XMLInputFactory().newInstance().createXMLEventReader( ... );
aoqi@0:  *
aoqi@0:  *       Object o = u.unmarshal( xmlEventReader );
aoqi@0:  *    
aoqi@0: *
aoqi@0: * aoqi@0: *

aoqi@0: * aoqi@0: * Unmarshalling XML Data
aoqi@0: *

aoqi@0: * Unmarshalling can deserialize XML data that represents either an entire XML document aoqi@0: * or a subtree of an XML document. Typically, it is sufficient to use the aoqi@0: * unmarshalling methods described by aoqi@0: * Unmarshal root element that is declared globally. aoqi@0: * These unmarshal methods utilize {@link JAXBContext}'s mapping of global XML element aoqi@0: * declarations and type definitions to JAXB mapped classes to initiate the aoqi@0: * unmarshalling of the root element of XML data. When the {@link JAXBContext}'s aoqi@0: * mappings are not sufficient to unmarshal the root element of XML data, aoqi@0: * the application can assist the unmarshalling process by using the aoqi@0: * unmarshal by declaredType methods. aoqi@0: * These methods are useful for unmarshalling XML data where aoqi@0: * the root element corresponds to a local element declaration in the schema. aoqi@0: *
aoqi@0: * aoqi@0: *
aoqi@0: * An unmarshal method never returns null. If the unmarshal process is unable to unmarshal aoqi@0: * the root of XML content to a JAXB mapped object, a fatal error is reported that aoqi@0: * terminates processing by throwing JAXBException. aoqi@0: *
aoqi@0: * aoqi@0: *

aoqi@0: * aoqi@0: * Unmarshal a root element that is globally declared
aoqi@0: *

aoqi@0: * The unmarshal methods that do not have an declaredType parameter use aoqi@0: * {@link JAXBContext} to unmarshal the root element of an XML data. The {@link JAXBContext} aoqi@0: * instance is the one that was used to create this Unmarshaller. The {@link JAXBContext} aoqi@0: * instance maintains a mapping of globally declared XML element and type definition names to aoqi@0: * JAXB mapped classes. The unmarshal method checks if {@link JAXBContext} has a mapping aoqi@0: * from the root element's XML name and/or @xsi:type to a JAXB mapped class. If it does, it umarshalls the aoqi@0: * XML data using the appropriate JAXB mapped class. Note that when the root element name is unknown and the root aoqi@0: * element has an @xsi:type, the XML data is unmarshalled aoqi@0: * using that JAXB mapped class as the value of a {@link JAXBElement}. aoqi@0: * When the {@link JAXBContext} object does not have a mapping for the root element's name aoqi@0: * nor its @xsi:type, if it exists, aoqi@0: * then the unmarshal operation will abort immediately by throwing a {@link UnmarshalException aoqi@0: * UnmarshalException}. This exception scenario can be worked around by using the unmarshal by aoqi@0: * declaredType methods described in the next subsection. aoqi@0: *
aoqi@0: * aoqi@0: *

aoqi@0: * aoqi@0: * Unmarshal by Declared Type
aoqi@0: *

aoqi@0: * The unmarshal methods with a declaredType parameter enable an aoqi@0: * application to deserialize a root element of XML data, even when aoqi@0: * there is no mapping in {@link JAXBContext} of the root element's XML name. aoqi@0: * The unmarshaller unmarshals the root element using the application provided aoqi@0: * mapping specified as the declaredType parameter. aoqi@0: * Note that even when the root element's element name is mapped by {@link JAXBContext}, aoqi@0: * the declaredType parameter overrides that mapping for aoqi@0: * deserializing the root element when using these unmarshal methods. aoqi@0: * Additionally, when the root element of XML data has an xsi:type attribute and aoqi@0: * that attribute's value references a type definition that is mapped aoqi@0: * to a JAXB mapped class by {@link JAXBContext}, that the root aoqi@0: * element's xsi:type attribute takes aoqi@0: * precedence over the unmarshal methods declaredType parameter. aoqi@0: * These methods always return a JAXBElement<declaredType> aoqi@0: * instance. The table below shows how the properties of the returned JAXBElement aoqi@0: * instance are set. aoqi@0: * aoqi@0: * aoqi@0: *

aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: * aoqi@0: *
aoqi@0: * Unmarshal By Declared Type returned JAXBElement aoqi@0: *
JAXBElement PropertyValue
namexml element name
valueinstanceof declaredType
declaredTypeunmarshal method declaredType parameter
scopenull (actual scope is unknown)
aoqi@0: *

aoqi@0: * aoqi@0: *

aoqi@0: * The following is an example of aoqi@0: * unmarshal by declaredType method. aoqi@0: *

aoqi@0: * Unmarshal by declaredType from a org.w3c.dom.Node: aoqi@0: *

aoqi@0: *
aoqi@0:  *       Schema fragment for example
aoqi@0:  *       <xs:schema>
aoqi@0:  *          <xs:complexType name="FooType">...<\xs:complexType>
aoqi@0:  *          <!-- global element declaration "PurchaseOrder" -->
aoqi@0:  *          <xs:element name="PurchaseOrder">
aoqi@0:  *              <xs:complexType>
aoqi@0:  *                 <xs:sequence>
aoqi@0:  *                    <!-- local element declaration "foo" -->
aoqi@0:  *                    <xs:element name="foo" type="FooType"/>
aoqi@0:  *                    ...
aoqi@0:  *                 </xs:sequence>
aoqi@0:  *              </xs:complexType>
aoqi@0:  *          </xs:element>
aoqi@0:  *       </xs:schema>
aoqi@0:  *
aoqi@0:  *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
aoqi@0:  *       Unmarshaller u = jc.createUnmarshaller();
aoqi@0:  *
aoqi@0:  *       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
aoqi@0:  *       dbf.setNamespaceAware(true);
aoqi@0:  *       DocumentBuilder db = dbf.newDocumentBuilder();
aoqi@0:  *       Document doc = db.parse(new File( "nosferatu.xml"));
aoqi@0:  *       Element  fooSubtree = ...; // traverse DOM till reach xml element foo, constrained by a
aoqi@0:  *                                  // local element declaration in schema.
aoqi@0:  *
aoqi@0:  *       // FooType is the JAXB mapping of the type of local element declaration foo.
aoqi@0:  *       JAXBElement<FooType> foo = u.unmarshal( fooSubtree, FooType.class);
aoqi@0:  *    
aoqi@0: *
aoqi@0: * aoqi@0: *

aoqi@0: * Support for SAX2.0 Compliant Parsers
aoqi@0: *

aoqi@0: * A client application has the ability to select the SAX2.0 compliant parser aoqi@0: * of their choice. If a SAX parser is not selected, then the JAXB Provider's aoqi@0: * default parser will be used. Even though the JAXB Provider's default parser aoqi@0: * is not required to be SAX2.0 compliant, all providers are required to allow aoqi@0: * a client application to specify their own SAX2.0 parser. Some providers may aoqi@0: * require the client application to specify the SAX2.0 parser at schema compile aoqi@0: * time. See {@link #unmarshal(javax.xml.transform.Source) unmarshal(Source)} aoqi@0: * for more detail. aoqi@0: *
aoqi@0: * aoqi@0: *

aoqi@0: * Validation and Well-Formedness
aoqi@0: *

aoqi@0: *

aoqi@0: * A client application can enable or disable JAXP 1.3 validation aoqi@0: * mechanism via the setSchema(javax.xml.validation.Schema) API. aoqi@0: * Sophisticated clients can specify their own validating SAX 2.0 compliant aoqi@0: * parser and bypass the JAXP 1.3 validation mechanism using the aoqi@0: * {@link #unmarshal(javax.xml.transform.Source) unmarshal(Source)} API. aoqi@0: * aoqi@0: *

aoqi@0: * Since unmarshalling invalid XML content is defined in JAXB 2.0, aoqi@0: * the Unmarshaller default validation event handler was made more lenient aoqi@0: * than in JAXB 1.0. When schema-derived code generated aoqi@0: * by JAXB 1.0 binding compiler is registered with {@link JAXBContext}, aoqi@0: * the default unmarshal validation handler is aoqi@0: * {@link javax.xml.bind.helpers.DefaultValidationEventHandler} and it aoqi@0: * terminates the marshal operation after encountering either a fatal error or an error. aoqi@0: * For a JAXB 2.0 client application, there is no explicitly defined default aoqi@0: * validation handler and the default event handling only aoqi@0: * terminates the unmarshal operation after encountering a fatal error. aoqi@0: * aoqi@0: *

aoqi@0: * aoqi@0: *

aoqi@0: * aoqi@0: * Supported Properties
aoqi@0: *

aoqi@0: *

aoqi@0: * There currently are not any properties required to be supported by all aoqi@0: * JAXB Providers on Unmarshaller. However, some providers may support aoqi@0: * their own set of provider specific properties. aoqi@0: *

aoqi@0: * aoqi@0: *

aoqi@0: * aoqi@0: * Unmarshal Event Callbacks
aoqi@0: *

aoqi@0: * The {@link Unmarshaller} provides two styles of callback mechanisms aoqi@0: * that allow application specific processing during key points in the aoqi@0: * unmarshalling process. In 'class defined' event callbacks, application aoqi@0: * specific code placed in JAXB mapped classes is triggered during aoqi@0: * unmarshalling. 'External listeners' allow for centralized processing aoqi@0: * of unmarshal events in one callback method rather than by type event callbacks. aoqi@0: *

aoqi@0: * 'Class defined' event callback methods allow any JAXB mapped class to specify aoqi@0: * its own specific callback methods by defining methods with the following method signature: aoqi@0: *

aoqi@0: *
aoqi@0:  *   // This method is called immediately after the object is created and before the unmarshalling of this
aoqi@0:  *   // object begins. The callback provides an opportunity to initialize JavaBean properties prior to unmarshalling.
aoqi@0:  *   void beforeUnmarshal(Unmarshaller, Object parent);
aoqi@0:  *
aoqi@0:  *   //This method is called after all the properties (except IDREF) are unmarshalled for this object,
aoqi@0:  *   //but before this object is set to the parent object.
aoqi@0:  *   void afterUnmarshal(Unmarshaller, Object parent);
aoqi@0:  * 
aoqi@0: *
aoqi@0: * The class defined callback methods should be used when the callback method requires aoqi@0: * access to non-public methods and/or fields of the class. aoqi@0: *

aoqi@0: * The external listener callback mechanism enables the registration of a {@link Listener} aoqi@0: * instance with an {@link Unmarshaller#setListener(Listener)}. The external listener receives all callback events, aoqi@0: * allowing for more centralized processing than per class defined callback methods. The external listener aoqi@0: * receives events when unmarshalling proces is marshalling to a JAXB element or to JAXB mapped class. aoqi@0: *

aoqi@0: * The 'class defined' and external listener event callback methods are independent of each other, aoqi@0: * both can be called for one event. The invocation ordering when both listener callback methods exist is aoqi@0: * defined in {@link Listener#beforeUnmarshal(Object, Object)} and {@link Listener#afterUnmarshal(Object, Object)}. aoqi@0: *

aoqi@0: * An event callback method throwing an exception terminates the current unmarshal process. aoqi@0: * aoqi@0: *

aoqi@0: * aoqi@0: * @author aoqi@0: * @see JAXBContext aoqi@0: * @see Marshaller aoqi@0: * @see Validator aoqi@0: * @since JAXB1.0 aoqi@0: */ aoqi@0: public interface Unmarshaller { aoqi@0: aoqi@0: /** aoqi@0: * Unmarshal XML data from the specified file and return the resulting aoqi@0: * content tree. aoqi@0: * aoqi@0: *

aoqi@0: * Implements Unmarshal Global Root Element. aoqi@0: * aoqi@0: * @param f the file to unmarshal XML data from aoqi@0: * @return the newly created root object of the java content tree aoqi@0: * aoqi@0: * @throws JAXBException aoqi@0: * If any unexpected errors occur while unmarshalling aoqi@0: * @throws UnmarshalException aoqi@0: * If the {@link ValidationEventHandler ValidationEventHandler} aoqi@0: * returns false from its handleEvent method or the aoqi@0: * Unmarshaller is unable to perform the XML to Java aoqi@0: * binding. See Unmarshalling XML Data aoqi@0: * @throws IllegalArgumentException aoqi@0: * If the file parameter is null aoqi@0: */ aoqi@0: public Object unmarshal( java.io.File f ) throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Unmarshal XML data from the specified InputStream and return the aoqi@0: * resulting content tree. Validation event location information may aoqi@0: * be incomplete when using this form of the unmarshal API. aoqi@0: * aoqi@0: *

aoqi@0: * Implements Unmarshal Global Root Element. aoqi@0: * aoqi@0: * @param is the InputStream to unmarshal XML data from aoqi@0: * @return the newly created root object of the java content tree aoqi@0: * aoqi@0: * @throws JAXBException aoqi@0: * If any unexpected errors occur while unmarshalling aoqi@0: * @throws UnmarshalException aoqi@0: * If the {@link ValidationEventHandler ValidationEventHandler} aoqi@0: * returns false from its handleEvent method or the aoqi@0: * Unmarshaller is unable to perform the XML to Java aoqi@0: * binding. See Unmarshalling XML Data aoqi@0: * @throws IllegalArgumentException aoqi@0: * If the InputStream parameter is null aoqi@0: */ aoqi@0: public Object unmarshal( java.io.InputStream is ) throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Unmarshal XML data from the specified Reader and return the aoqi@0: * resulting content tree. Validation event location information may aoqi@0: * be incomplete when using this form of the unmarshal API, aoqi@0: * because a Reader does not provide the system ID. aoqi@0: * aoqi@0: *

aoqi@0: * Implements Unmarshal Global Root Element. aoqi@0: * aoqi@0: * @param reader the Reader to unmarshal XML data from aoqi@0: * @return the newly created root object of the java content tree aoqi@0: * aoqi@0: * @throws JAXBException aoqi@0: * If any unexpected errors occur while unmarshalling aoqi@0: * @throws UnmarshalException aoqi@0: * If the {@link ValidationEventHandler ValidationEventHandler} aoqi@0: * returns false from its handleEvent method or the aoqi@0: * Unmarshaller is unable to perform the XML to Java aoqi@0: * binding. See Unmarshalling XML Data aoqi@0: * @throws IllegalArgumentException aoqi@0: * If the InputStream parameter is null aoqi@0: * @since JAXB2.0 aoqi@0: */ aoqi@0: public Object unmarshal( Reader reader ) throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Unmarshal XML data from the specified URL and return the resulting aoqi@0: * content tree. aoqi@0: * aoqi@0: *

aoqi@0: * Implements Unmarshal Global Root Element. aoqi@0: * aoqi@0: * @param url the url to unmarshal XML data from aoqi@0: * @return the newly created root object of the java content tree aoqi@0: * aoqi@0: * @throws JAXBException aoqi@0: * If any unexpected errors occur while unmarshalling aoqi@0: * @throws UnmarshalException aoqi@0: * If the {@link ValidationEventHandler ValidationEventHandler} aoqi@0: * returns false from its handleEvent method or the aoqi@0: * Unmarshaller is unable to perform the XML to Java aoqi@0: * binding. See Unmarshalling XML Data aoqi@0: * @throws IllegalArgumentException aoqi@0: * If the URL parameter is null aoqi@0: */ aoqi@0: public Object unmarshal( java.net.URL url ) throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Unmarshal XML data from the specified SAX InputSource and return the aoqi@0: * resulting content tree. aoqi@0: * aoqi@0: *

aoqi@0: * Implements Unmarshal Global Root Element. aoqi@0: * aoqi@0: * @param source the input source to unmarshal XML data from aoqi@0: * @return the newly created root object of the java content tree aoqi@0: * aoqi@0: * @throws JAXBException aoqi@0: * If any unexpected errors occur while unmarshalling aoqi@0: * @throws UnmarshalException aoqi@0: * If the {@link ValidationEventHandler ValidationEventHandler} aoqi@0: * returns false from its handleEvent method or the aoqi@0: * Unmarshaller is unable to perform the XML to Java aoqi@0: * binding. See Unmarshalling XML Data aoqi@0: * @throws IllegalArgumentException aoqi@0: * If the InputSource parameter is null aoqi@0: */ aoqi@0: public Object unmarshal( org.xml.sax.InputSource source ) throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Unmarshal global XML data from the specified DOM tree and return the resulting aoqi@0: * content tree. aoqi@0: * aoqi@0: *

aoqi@0: * Implements Unmarshal Global Root Element. aoqi@0: * aoqi@0: * @param node aoqi@0: * the document/element to unmarshal XML data from. aoqi@0: * The caller must support at least Document and Element. aoqi@0: * @return the newly created root object of the java content tree aoqi@0: * aoqi@0: * @throws JAXBException aoqi@0: * If any unexpected errors occur while unmarshalling aoqi@0: * @throws UnmarshalException aoqi@0: * If the {@link ValidationEventHandler ValidationEventHandler} aoqi@0: * returns false from its handleEvent method or the aoqi@0: * Unmarshaller is unable to perform the XML to Java aoqi@0: * binding. See Unmarshalling XML Data aoqi@0: * @throws IllegalArgumentException aoqi@0: * If the Node parameter is null aoqi@0: * @see #unmarshal(org.w3c.dom.Node, Class) aoqi@0: */ aoqi@0: public Object unmarshal( org.w3c.dom.Node node ) throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Unmarshal XML data by JAXB mapped declaredType aoqi@0: * and return the resulting content tree. aoqi@0: * aoqi@0: *

aoqi@0: * Implements Unmarshal by Declared Type aoqi@0: * aoqi@0: * @param node aoqi@0: * the document/element to unmarshal XML data from. aoqi@0: * The caller must support at least Document and Element. aoqi@0: * @param declaredType aoqi@0: * appropriate JAXB mapped class to hold node's XML data. aoqi@0: * aoqi@0: * @return JAXB Element representation of node aoqi@0: * aoqi@0: * @throws JAXBException aoqi@0: * If any unexpected errors occur while unmarshalling aoqi@0: * @throws UnmarshalException aoqi@0: * If the {@link ValidationEventHandler ValidationEventHandler} aoqi@0: * returns false from its handleEvent method or the aoqi@0: * Unmarshaller is unable to perform the XML to Java aoqi@0: * binding. See Unmarshalling XML Data aoqi@0: * @throws IllegalArgumentException aoqi@0: * If any parameter is null aoqi@0: * @since JAXB2.0 aoqi@0: */ aoqi@0: public JAXBElement unmarshal( org.w3c.dom.Node node, Class declaredType ) throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Unmarshal XML data from the specified XML Source and return the aoqi@0: * resulting content tree. aoqi@0: * aoqi@0: *

aoqi@0: * Implements Unmarshal Global Root Element. aoqi@0: * aoqi@0: *

aoqi@0: * aoqi@0: * SAX 2.0 Parser Pluggability aoqi@0: *

aoqi@0: * A client application can choose not to use the default parser mechanism aoqi@0: * supplied with their JAXB provider. Any SAX 2.0 compliant parser can be aoqi@0: * substituted for the JAXB provider's default mechanism. To do so, the aoqi@0: * client application must properly configure a SAXSource containing aoqi@0: * an XMLReader implemented by the SAX 2.0 parser provider. If the aoqi@0: * XMLReader has an org.xml.sax.ErrorHandler registered aoqi@0: * on it, it will be replaced by the JAXB Provider so that validation errors aoqi@0: * can be reported via the ValidationEventHandler mechanism of aoqi@0: * JAXB. If the SAXSource does not contain an XMLReader, aoqi@0: * then the JAXB provider's default parser mechanism will be used. aoqi@0: *

aoqi@0: * This parser replacement mechanism can also be used to replace the JAXB aoqi@0: * provider's unmarshal-time validation engine. The client application aoqi@0: * must properly configure their SAX 2.0 compliant parser to perform aoqi@0: * validation (as shown in the example above). Any SAXParserExceptions aoqi@0: * encountered by the parser during the unmarshal operation will be aoqi@0: * processed by the JAXB provider and converted into JAXB aoqi@0: * ValidationEvent objects which will be reported back to the aoqi@0: * client via the ValidationEventHandler registered with the aoqi@0: * Unmarshaller. Note: specifying a substitute validating aoqi@0: * SAX 2.0 parser for unmarshalling does not necessarily replace the aoqi@0: * validation engine used by the JAXB provider for performing on-demand aoqi@0: * validation. aoqi@0: *

aoqi@0: * The only way for a client application to specify an alternate parser aoqi@0: * mechanism to be used during unmarshal is via the aoqi@0: * unmarshal(SAXSource) API. All other forms of the unmarshal aoqi@0: * method (File, URL, Node, etc) will use the JAXB provider's default aoqi@0: * parser and validator mechanisms. aoqi@0: * aoqi@0: * @param source the XML Source to unmarshal XML data from (providers are aoqi@0: * only required to support SAXSource, DOMSource, and StreamSource) aoqi@0: * @return the newly created root object of the java content tree aoqi@0: * aoqi@0: * @throws JAXBException aoqi@0: * If any unexpected errors occur while unmarshalling aoqi@0: * @throws UnmarshalException aoqi@0: * If the {@link ValidationEventHandler ValidationEventHandler} aoqi@0: * returns false from its handleEvent method or the aoqi@0: * Unmarshaller is unable to perform the XML to Java aoqi@0: * binding. See Unmarshalling XML Data aoqi@0: * @throws IllegalArgumentException aoqi@0: * If the Source parameter is null aoqi@0: * @see #unmarshal(javax.xml.transform.Source, Class) aoqi@0: */ aoqi@0: public Object unmarshal( javax.xml.transform.Source source ) aoqi@0: throws JAXBException; aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Unmarshal XML data from the specified XML Source by declaredType and return the aoqi@0: * resulting content tree. aoqi@0: * aoqi@0: *

aoqi@0: * Implements Unmarshal by Declared Type aoqi@0: * aoqi@0: *

aoqi@0: * See SAX 2.0 Parser Pluggability aoqi@0: * aoqi@0: * @param source the XML Source to unmarshal XML data from (providers are aoqi@0: * only required to support SAXSource, DOMSource, and StreamSource) aoqi@0: * @param declaredType aoqi@0: * appropriate JAXB mapped class to hold source's xml root element aoqi@0: * @return Java content rooted by JAXB Element aoqi@0: * aoqi@0: * @throws JAXBException aoqi@0: * If any unexpected errors occur while unmarshalling aoqi@0: * @throws UnmarshalException aoqi@0: * If the {@link ValidationEventHandler ValidationEventHandler} aoqi@0: * returns false from its handleEvent method or the aoqi@0: * Unmarshaller is unable to perform the XML to Java aoqi@0: * binding. See Unmarshalling XML Data aoqi@0: * @throws IllegalArgumentException aoqi@0: * If any parameter is null aoqi@0: * @since JAXB2.0 aoqi@0: */ aoqi@0: public JAXBElement unmarshal( javax.xml.transform.Source source, Class declaredType ) aoqi@0: throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Unmarshal XML data from the specified pull parser and return the aoqi@0: * resulting content tree. aoqi@0: * aoqi@0: *

aoqi@0: * Implements Unmarshal Global Root Element. aoqi@0: * aoqi@0: *

aoqi@0: * This method assumes that the parser is on a START_DOCUMENT or aoqi@0: * START_ELEMENT event. Unmarshalling will be done from this aoqi@0: * start event to the corresponding end event. If this method aoqi@0: * returns successfully, the reader will be pointing at aoqi@0: * the token right after the end event. aoqi@0: * aoqi@0: * @param reader aoqi@0: * The parser to be read. aoqi@0: * @return aoqi@0: * the newly created root object of the java content tree. aoqi@0: * aoqi@0: * @throws JAXBException aoqi@0: * If any unexpected errors occur while unmarshalling aoqi@0: * @throws UnmarshalException aoqi@0: * If the {@link ValidationEventHandler ValidationEventHandler} aoqi@0: * returns false from its handleEvent method or the aoqi@0: * Unmarshaller is unable to perform the XML to Java aoqi@0: * binding. See Unmarshalling XML Data aoqi@0: * @throws IllegalArgumentException aoqi@0: * If the reader parameter is null aoqi@0: * @throws IllegalStateException aoqi@0: * If reader is not pointing to a START_DOCUMENT or aoqi@0: * START_ELEMENT event. aoqi@0: * @since JAXB2.0 aoqi@0: * @see #unmarshal(javax.xml.stream.XMLStreamReader, Class) aoqi@0: */ aoqi@0: public Object unmarshal( javax.xml.stream.XMLStreamReader reader ) aoqi@0: throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Unmarshal root element to JAXB mapped declaredType aoqi@0: * and return the resulting content tree. aoqi@0: * aoqi@0: *

aoqi@0: * This method implements unmarshal by declaredType. aoqi@0: *

aoqi@0: * This method assumes that the parser is on a START_DOCUMENT or aoqi@0: * START_ELEMENT event. Unmarshalling will be done from this aoqi@0: * start event to the corresponding end event. If this method aoqi@0: * returns successfully, the reader will be pointing at aoqi@0: * the token right after the end event. aoqi@0: * aoqi@0: * @param reader aoqi@0: * The parser to be read. aoqi@0: * @param declaredType aoqi@0: * appropriate JAXB mapped class to hold reader's START_ELEMENT XML data. aoqi@0: * aoqi@0: * @return content tree rooted by JAXB Element representation aoqi@0: * aoqi@0: * @throws JAXBException aoqi@0: * If any unexpected errors occur while unmarshalling aoqi@0: * @throws UnmarshalException aoqi@0: * If the {@link ValidationEventHandler ValidationEventHandler} aoqi@0: * returns false from its handleEvent method or the aoqi@0: * Unmarshaller is unable to perform the XML to Java aoqi@0: * binding. See Unmarshalling XML Data aoqi@0: * @throws IllegalArgumentException aoqi@0: * If any parameter is null aoqi@0: * @since JAXB2.0 aoqi@0: */ aoqi@0: public JAXBElement unmarshal( javax.xml.stream.XMLStreamReader reader, Class declaredType ) throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Unmarshal XML data from the specified pull parser and return the aoqi@0: * resulting content tree. aoqi@0: * aoqi@0: *

aoqi@0: * This method is an Unmarshal Global Root method. aoqi@0: * aoqi@0: *

aoqi@0: * This method assumes that the parser is on a START_DOCUMENT or aoqi@0: * START_ELEMENT event. Unmarshalling will be done from this aoqi@0: * start event to the corresponding end event. If this method aoqi@0: * returns successfully, the reader will be pointing at aoqi@0: * the token right after the end event. aoqi@0: * aoqi@0: * @param reader aoqi@0: * The parser to be read. aoqi@0: * @return aoqi@0: * the newly created root object of the java content tree. aoqi@0: * aoqi@0: * @throws JAXBException aoqi@0: * If any unexpected errors occur while unmarshalling aoqi@0: * @throws UnmarshalException aoqi@0: * If the {@link ValidationEventHandler ValidationEventHandler} aoqi@0: * returns false from its handleEvent method or the aoqi@0: * Unmarshaller is unable to perform the XML to Java aoqi@0: * binding. See Unmarshalling XML Data aoqi@0: * @throws IllegalArgumentException aoqi@0: * If the reader parameter is null aoqi@0: * @throws IllegalStateException aoqi@0: * If reader is not pointing to a START_DOCUMENT or aoqi@0: * START_ELEMENT event. aoqi@0: * @since JAXB2.0 aoqi@0: * @see #unmarshal(javax.xml.stream.XMLEventReader, Class) aoqi@0: */ aoqi@0: public Object unmarshal( javax.xml.stream.XMLEventReader reader ) aoqi@0: throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Unmarshal root element to JAXB mapped declaredType aoqi@0: * and return the resulting content tree. aoqi@0: * aoqi@0: *

aoqi@0: * This method implements unmarshal by declaredType. aoqi@0: * aoqi@0: *

aoqi@0: * This method assumes that the parser is on a START_DOCUMENT or aoqi@0: * START_ELEMENT event. Unmarshalling will be done from this aoqi@0: * start event to the corresponding end event. If this method aoqi@0: * returns successfully, the reader will be pointing at aoqi@0: * the token right after the end event. aoqi@0: * aoqi@0: * @param reader aoqi@0: * The parser to be read. aoqi@0: * @param declaredType aoqi@0: * appropriate JAXB mapped class to hold reader's START_ELEMENT XML data. aoqi@0: * aoqi@0: * @return content tree rooted by JAXB Element representation aoqi@0: * aoqi@0: * @throws JAXBException aoqi@0: * If any unexpected errors occur while unmarshalling aoqi@0: * @throws UnmarshalException aoqi@0: * If the {@link ValidationEventHandler ValidationEventHandler} aoqi@0: * returns false from its handleEvent method or the aoqi@0: * Unmarshaller is unable to perform the XML to Java aoqi@0: * binding. See Unmarshalling XML Data aoqi@0: * @throws IllegalArgumentException aoqi@0: * If any parameter is null aoqi@0: * @since JAXB2.0 aoqi@0: */ aoqi@0: public JAXBElement unmarshal( javax.xml.stream.XMLEventReader reader, Class declaredType ) throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Get an unmarshaller handler object that can be used as a component in aoqi@0: * an XML pipeline. aoqi@0: * aoqi@0: *

aoqi@0: * The JAXB Provider can return the same handler object for multiple aoqi@0: * invocations of this method. In other words, this method does not aoqi@0: * necessarily create a new instance of UnmarshallerHandler. If the aoqi@0: * application needs to use more than one UnmarshallerHandler, it aoqi@0: * should create more than one Unmarshaller. aoqi@0: * aoqi@0: * @return the unmarshaller handler object aoqi@0: * @see UnmarshallerHandler aoqi@0: */ aoqi@0: public UnmarshallerHandler getUnmarshallerHandler(); aoqi@0: aoqi@0: /** aoqi@0: * Specifies whether or not the default validation mechanism of the aoqi@0: * Unmarshaller should validate during unmarshal operations. aoqi@0: * By default, the Unmarshaller does not validate. aoqi@0: *

aoqi@0: * This method may only be invoked before or after calling one of the aoqi@0: * unmarshal methods. aoqi@0: *

aoqi@0: * This method only controls the JAXB Provider's default unmarshal-time aoqi@0: * validation mechanism - it has no impact on clients that specify their aoqi@0: * own validating SAX 2.0 compliant parser. Clients that specify their aoqi@0: * own unmarshal-time validation mechanism may wish to turn off the JAXB aoqi@0: * Provider's default validation mechanism via this API to avoid "double aoqi@0: * validation". aoqi@0: *

aoqi@0: * This method is deprecated as of JAXB 2.0 - please use the new aoqi@0: * {@link #setSchema(javax.xml.validation.Schema)} API. aoqi@0: * aoqi@0: * @param validating true if the Unmarshaller should validate during aoqi@0: * unmarshal, false otherwise aoqi@0: * @throws JAXBException if an error occurred while enabling or disabling aoqi@0: * validation at unmarshal time aoqi@0: * @throws UnsupportedOperationException could be thrown if this method is aoqi@0: * invoked on an Unmarshaller created from a JAXBContext referencing aoqi@0: * JAXB 2.0 mapped classes aoqi@0: * @deprecated since JAXB2.0, please see {@link #setSchema(javax.xml.validation.Schema)} aoqi@0: */ aoqi@0: public void setValidating( boolean validating ) aoqi@0: throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Indicates whether or not the Unmarshaller is configured to aoqi@0: * validate during unmarshal operations. aoqi@0: *

aoqi@0: * This API returns the state of the JAXB Provider's default unmarshal-time aoqi@0: * validation mechanism. aoqi@0: *

aoqi@0: * This method is deprecated as of JAXB 2.0 - please use the new aoqi@0: * {@link #getSchema()} API. aoqi@0: * aoqi@0: * @return true if the Unmarshaller is configured to validate during aoqi@0: * unmarshal operations, false otherwise aoqi@0: * @throws JAXBException if an error occurs while retrieving the validating aoqi@0: * flag aoqi@0: * @throws UnsupportedOperationException could be thrown if this method is aoqi@0: * invoked on an Unmarshaller created from a JAXBContext referencing aoqi@0: * JAXB 2.0 mapped classes aoqi@0: * @deprecated since JAXB2.0, please see {@link #getSchema()} aoqi@0: */ aoqi@0: public boolean isValidating() aoqi@0: throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Allow an application to register a ValidationEventHandler. aoqi@0: *

aoqi@0: * The ValidationEventHandler will be called by the JAXB Provider aoqi@0: * if any validation errors are encountered during calls to any of the aoqi@0: * unmarshal methods. If the client application does not register a aoqi@0: * ValidationEventHandler before invoking the unmarshal methods, aoqi@0: * then ValidationEvents will be handled by the default event aoqi@0: * handler which will terminate the unmarshal operation after the first aoqi@0: * error or fatal error is encountered. aoqi@0: *

aoqi@0: * Calling this method with a null parameter will cause the Unmarshaller aoqi@0: * to revert back to the default event handler. aoqi@0: * aoqi@0: * @param handler the validation event handler aoqi@0: * @throws JAXBException if an error was encountered while setting the aoqi@0: * event handler aoqi@0: */ aoqi@0: public void setEventHandler( ValidationEventHandler handler ) aoqi@0: throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Return the current event handler or the default event handler if one aoqi@0: * hasn't been set. aoqi@0: * aoqi@0: * @return the current ValidationEventHandler or the default event handler aoqi@0: * if it hasn't been set aoqi@0: * @throws JAXBException if an error was encountered while getting the aoqi@0: * current event handler aoqi@0: */ aoqi@0: public ValidationEventHandler getEventHandler() aoqi@0: throws JAXBException; aoqi@0: aoqi@0: /** aoqi@0: * Set the particular property in the underlying implementation of aoqi@0: * Unmarshaller. This method can only be used to set one of aoqi@0: * the standard JAXB defined properties above or a provider specific aoqi@0: * property. Attempting to set an undefined property will result in aoqi@0: * a PropertyException being thrown. See aoqi@0: * Supported Properties. aoqi@0: * aoqi@0: * @param name the name of the property to be set. This value can either aoqi@0: * be specified using one of the constant fields or a user aoqi@0: * supplied string. aoqi@0: * @param value the value of the property to be set aoqi@0: * aoqi@0: * @throws PropertyException when there is an error processing the given aoqi@0: * property or value aoqi@0: * @throws IllegalArgumentException aoqi@0: * If the name parameter is null aoqi@0: */ aoqi@0: public void setProperty( String name, Object value ) aoqi@0: throws PropertyException; aoqi@0: aoqi@0: /** aoqi@0: * Get the particular property in the underlying implementation of aoqi@0: * Unmarshaller. This method can only be used to get one of aoqi@0: * the standard JAXB defined properties above or a provider specific aoqi@0: * property. Attempting to get an undefined property will result in aoqi@0: * a PropertyException being thrown. See aoqi@0: * Supported Properties. aoqi@0: * aoqi@0: * @param name the name of the property to retrieve aoqi@0: * @return the value of the requested property aoqi@0: * aoqi@0: * @throws PropertyException aoqi@0: * when there is an error retrieving the given property or value aoqi@0: * property name aoqi@0: * @throws IllegalArgumentException aoqi@0: * If the name parameter is null aoqi@0: */ aoqi@0: public Object getProperty( String name ) throws PropertyException; aoqi@0: aoqi@0: /** aoqi@0: * Specify the JAXP 1.3 {@link javax.xml.validation.Schema Schema} aoqi@0: * object that should be used to validate subsequent unmarshal operations aoqi@0: * against. Passing null into this method will disable validation. aoqi@0: *

aoqi@0: * This method replaces the deprecated {@link #setValidating(boolean) setValidating(boolean)} aoqi@0: * API. aoqi@0: * aoqi@0: *

aoqi@0: * Initially this property is set to null. aoqi@0: * aoqi@0: * @param schema Schema object to validate unmarshal operations against or null to disable validation aoqi@0: * @throws UnsupportedOperationException could be thrown if this method is aoqi@0: * invoked on an Unmarshaller created from a JAXBContext referencing aoqi@0: * JAXB 1.0 mapped classes aoqi@0: * @since JAXB2.0 aoqi@0: */ aoqi@0: public void setSchema( javax.xml.validation.Schema schema ); aoqi@0: aoqi@0: /** aoqi@0: * Get the JAXP 1.3 {@link javax.xml.validation.Schema Schema} object aoqi@0: * being used to perform unmarshal-time validation. If there is no aoqi@0: * Schema set on the unmarshaller, then this method will return null aoqi@0: * indicating that unmarshal-time validation will not be performed. aoqi@0: *

aoqi@0: * This method provides replacement functionality for the deprecated aoqi@0: * {@link #isValidating()} API as well as access to the Schema object. aoqi@0: * To determine if the Unmarshaller has validation enabled, simply aoqi@0: * test the return type for null: aoqi@0: *

aoqi@0: * aoqi@0: * boolean isValidating = u.getSchema()!=null; aoqi@0: * aoqi@0: * aoqi@0: * @return the Schema object being used to perform unmarshal-time aoqi@0: * validation or null if not present aoqi@0: * @throws UnsupportedOperationException could be thrown if this method is aoqi@0: * invoked on an Unmarshaller created from a JAXBContext referencing aoqi@0: * JAXB 1.0 mapped classes aoqi@0: * @since JAXB2.0 aoqi@0: */ aoqi@0: public javax.xml.validation.Schema getSchema(); aoqi@0: aoqi@0: /** aoqi@0: * Associates a configured instance of {@link XmlAdapter} with this unmarshaller. aoqi@0: * aoqi@0: *

aoqi@0: * This is a convenience method that invokes setAdapter(adapter.getClass(),adapter);. aoqi@0: * aoqi@0: * @see #setAdapter(Class,XmlAdapter) aoqi@0: * @throws IllegalArgumentException aoqi@0: * if the adapter parameter is null. aoqi@0: * @throws UnsupportedOperationException aoqi@0: * if invoked agains a JAXB 1.0 implementation. aoqi@0: * @since JAXB2.0 aoqi@0: */ aoqi@0: public void setAdapter( XmlAdapter adapter ); aoqi@0: aoqi@0: /** aoqi@0: * Associates a configured instance of {@link XmlAdapter} with this unmarshaller. aoqi@0: * aoqi@0: *

aoqi@0: * Every unmarshaller internally maintains a aoqi@0: * {@link java.util.Map}<{@link Class},{@link XmlAdapter}>, aoqi@0: * which it uses for unmarshalling classes whose fields/methods are annotated aoqi@0: * with {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter}. aoqi@0: * aoqi@0: *

aoqi@0: * This method allows applications to use a configured instance of {@link XmlAdapter}. aoqi@0: * When an instance of an adapter is not given, an unmarshaller will create aoqi@0: * one by invoking its default constructor. aoqi@0: * aoqi@0: * @param type aoqi@0: * The type of the adapter. The specified instance will be used when aoqi@0: * {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter#value()} aoqi@0: * refers to this type. aoqi@0: * @param adapter aoqi@0: * The instance of the adapter to be used. If null, it will un-register aoqi@0: * the current adapter set for this type. aoqi@0: * @throws IllegalArgumentException aoqi@0: * if the type parameter is null. aoqi@0: * @throws UnsupportedOperationException aoqi@0: * if invoked agains a JAXB 1.0 implementation. aoqi@0: * @since JAXB2.0 aoqi@0: */ aoqi@0: public void setAdapter( Class type, A adapter ); aoqi@0: aoqi@0: /** aoqi@0: * Gets the adapter associated with the specified type. aoqi@0: * aoqi@0: * This is the reverse operation of the {@link #setAdapter} method. aoqi@0: * aoqi@0: * @throws IllegalArgumentException aoqi@0: * if the type parameter is null. aoqi@0: * @throws UnsupportedOperationException aoqi@0: * if invoked agains a JAXB 1.0 implementation. aoqi@0: * @since JAXB2.0 aoqi@0: */ aoqi@0: public A getAdapter( Class type ); aoqi@0: aoqi@0: /** aoqi@0: *

Associate a context that resolves cid's, content-id URIs, to aoqi@0: * binary data passed as attachments.

aoqi@0: *

aoqi@0: *

Unmarshal time validation, enabled via {@link #setSchema(Schema)}, aoqi@0: * must be supported even when unmarshaller is performing XOP processing. aoqi@0: *

aoqi@0: * aoqi@0: * @throws IllegalStateException if attempt to concurrently call this aoqi@0: * method during a unmarshal operation. aoqi@0: */ aoqi@0: void setAttachmentUnmarshaller(AttachmentUnmarshaller au); aoqi@0: aoqi@0: AttachmentUnmarshaller getAttachmentUnmarshaller(); aoqi@0: aoqi@0: /** aoqi@0: *

aoqi@0: * Register an instance of an implementation of this class with {@link Unmarshaller} to externally listen aoqi@0: * for unmarshal events. aoqi@0: *

aoqi@0: *

aoqi@0: * This class enables pre and post processing of an instance of a JAXB mapped class aoqi@0: * as XML data is unmarshalled into it. The event callbacks are called when unmarshalling aoqi@0: * XML content into a JAXBElement instance or a JAXB mapped class that represents a complex type definition. aoqi@0: * The event callbacks are not called when unmarshalling to an instance of a aoqi@0: * Java datatype that represents a simple type definition. aoqi@0: *

aoqi@0: *

aoqi@0: * External listener is one of two different mechanisms for defining unmarshal event callbacks. aoqi@0: * See Unmarshal Event Callbacks for an overview. aoqi@0: *

aoqi@0: * (@link #setListener(Listener)} aoqi@0: * (@link #getListener()} aoqi@0: * aoqi@0: * @since JAXB2.0 aoqi@0: */ aoqi@0: public static abstract class Listener { aoqi@0: /** aoqi@0: *

aoqi@0: * Callback method invoked before unmarshalling into target. aoqi@0: *

aoqi@0: *

aoqi@0: * This method is invoked immediately after target was created and aoqi@0: * before the unmarshalling of this object begins. Note that aoqi@0: * if the class of target defines its own beforeUnmarshal method, aoqi@0: * the class specific callback method is invoked before this method is invoked. aoqi@0: * aoqi@0: * @param target non-null instance of JAXB mapped class prior to unmarshalling into it. aoqi@0: * @param parent instance of JAXB mapped class that will eventually reference target. aoqi@0: * null when target is root element. aoqi@0: */ aoqi@0: public void beforeUnmarshal(Object target, Object parent) { aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: *

aoqi@0: * Callback method invoked after unmarshalling XML data into target. aoqi@0: *

aoqi@0: *

aoqi@0: * This method is invoked after all the properties (except IDREF) are unmarshalled into target, aoqi@0: * but before target is set into its parent object. aoqi@0: * Note that if the class of target defines its own afterUnmarshal method, aoqi@0: * the class specific callback method is invoked before this method is invoked. aoqi@0: * aoqi@0: * @param target non-null instance of JAXB mapped class prior to unmarshalling into it. aoqi@0: * @param parent instance of JAXB mapped class that will reference target. aoqi@0: * null when target is root element. aoqi@0: */ aoqi@0: public void afterUnmarshal(Object target, Object parent) { aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: *

aoqi@0: * Register unmarshal event callback {@link Listener} with this {@link Unmarshaller}. aoqi@0: * aoqi@0: *

aoqi@0: * There is only one Listener per Unmarshaller. Setting a Listener replaces the previous set Listener. aoqi@0: * One can unregister current Listener by setting listener to null. aoqi@0: * aoqi@0: * @param listener provides unmarshal event callbacks for this {@link Unmarshaller} aoqi@0: * @since JAXB2.0 aoqi@0: */ aoqi@0: public void setListener(Listener listener); aoqi@0: aoqi@0: /** aoqi@0: *

Return {@link Listener} registered with this {@link Unmarshaller}. aoqi@0: * aoqi@0: * @return registered {@link Listener} or null if no Listener is registered with this Unmarshaller. aoqi@0: * @since JAXB2.0 aoqi@0: */ aoqi@0: public Listener getListener(); aoqi@0: }