0001: /*
0002: * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
0003: * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
0004: */
0005:
0006: package javax.xml.bind;
0007:
0008: import javax.xml.bind.annotation.adapters.XmlAdapter;
0009: import javax.xml.bind.attachment.AttachmentUnmarshaller;
0010: import javax.xml.validation.Schema;
0011: import java.io.Reader;
0012:
0013: /**
0014: * The <tt>Unmarshaller</tt> class governs the process of deserializing XML
0015: * data into newly created Java content trees, optionally validating the XML
0016: * data as it is unmarshalled. It provides an overloading of unmarshal methods
0017: * for many different input kinds.
0018: *
0019: * <p>
0020: * Unmarshalling from a File:
0021: * <blockquote>
0022: * <pre>
0023: * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
0024: * Unmarshaller u = jc.createUnmarshaller();
0025: * Object o = u.unmarshal( new File( "nosferatu.xml" ) );
0026: * </pre>
0027: * </blockquote>
0028: *
0029: *
0030: * <p>
0031: * Unmarshalling from an InputStream:
0032: * <blockquote>
0033: * <pre>
0034: * InputStream is = new FileInputStream( "nosferatu.xml" );
0035: * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
0036: * Unmarshaller u = jc.createUnmarshaller();
0037: * Object o = u.unmarshal( is );
0038: * </pre>
0039: * </blockquote>
0040: *
0041: * <p>
0042: * Unmarshalling from a URL:
0043: * <blockquote>
0044: * <pre>
0045: * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
0046: * Unmarshaller u = jc.createUnmarshaller();
0047: * URL url = new URL( "http://beaker.east/nosferatu.xml" );
0048: * Object o = u.unmarshal( url );
0049: * </pre>
0050: * </blockquote>
0051: *
0052: * <p>
0053: * Unmarshalling from a StringBuffer using a
0054: * <tt>javax.xml.transform.stream.StreamSource</tt>:
0055: * <blockquote>
0056: * <pre>
0057: * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
0058: * Unmarshaller u = jc.createUnmarshaller();
0059: * StringBuffer xmlStr = new StringBuffer( "<?xml version="1.0"?>..." );
0060: * Object o = u.unmarshal( new StreamSource( new StringReader( xmlStr.toString() ) ) );
0061: * </pre>
0062: * </blockquote>
0063: *
0064: * <p>
0065: * Unmarshalling from a <tt>org.w3c.dom.Node</tt>:
0066: * <blockquote>
0067: * <pre>
0068: * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
0069: * Unmarshaller u = jc.createUnmarshaller();
0070: *
0071: * DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
0072: * dbf.setNamespaceAware(true);
0073: * DocumentBuilder db = dbf.newDocumentBuilder();
0074: * Document doc = db.parse(new File( "nosferatu.xml"));
0075:
0076: * Object o = u.unmarshal( doc );
0077: * </pre>
0078: * </blockquote>
0079: *
0080: * <p>
0081: * Unmarshalling from a <tt>javax.xml.transform.sax.SAXSource</tt> using a
0082: * client specified validating SAX2.0 parser:
0083: * <blockquote>
0084: * <pre>
0085: * // configure a validating SAX2.0 parser (Xerces2)
0086: * static final String JAXP_SCHEMA_LANGUAGE =
0087: * "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
0088: * static final String JAXP_SCHEMA_LOCATION =
0089: * "http://java.sun.com/xml/jaxp/properties/schemaSource";
0090: * static final String W3C_XML_SCHEMA =
0091: * "http://www.w3.org/2001/XMLSchema";
0092: *
0093: * System.setProperty( "javax.xml.parsers.SAXParserFactory",
0094: * "org.apache.xerces.jaxp.SAXParserFactoryImpl" );
0095: *
0096: * SAXParserFactory spf = SAXParserFactory.newInstance();
0097: * spf.setNamespaceAware(true);
0098: * spf.setValidating(true);
0099: * SAXParser saxParser = spf.newSAXParser();
0100: *
0101: * try {
0102: * saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
0103: * saxParser.setProperty(JAXP_SCHEMA_LOCATION, "http://....");
0104: * } catch (SAXNotRecognizedException x) {
0105: * // exception handling omitted
0106: * }
0107: *
0108: * XMLReader xmlReader = saxParser.getXMLReader();
0109: * SAXSource source =
0110: * new SAXSource( xmlReader, new InputSource( "http://..." ) );
0111: *
0112: * // Setup JAXB to unmarshal
0113: * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
0114: * Unmarshaller u = jc.createUnmarshaller();
0115: * ValidationEventCollector vec = new ValidationEventCollector();
0116: * u.setEventHandler( vec );
0117: *
0118: * // turn off the JAXB provider's default validation mechanism to
0119: * // avoid duplicate validation
0120: * u.setValidating( false )
0121: *
0122: * // unmarshal
0123: * Object o = u.unmarshal( source );
0124: *
0125: * // check for events
0126: * if( vec.hasEvents() ) {
0127: * // iterate over events
0128: * }
0129: * </pre>
0130: * </blockquote>
0131: *
0132: * <p>
0133: * Unmarshalling from a StAX XMLStreamReader:
0134: * <blockquote>
0135: * <pre>
0136: * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
0137: * Unmarshaller u = jc.createUnmarshaller();
0138: *
0139: * javax.xml.stream.XMLStreamReader xmlStreamReader =
0140: * javax.xml.stream.XMLInputFactory().newInstance().createXMLStreamReader( ... );
0141: *
0142: * Object o = u.unmarshal( xmlStreamReader );
0143: * </pre>
0144: * </blockquote>
0145: *
0146: * <p>
0147: * Unmarshalling from a StAX XMLEventReader:
0148: * <blockquote>
0149: * <pre>
0150: * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
0151: * Unmarshaller u = jc.createUnmarshaller();
0152: *
0153: * javax.xml.stream.XMLEventReader xmlEventReader =
0154: * javax.xml.stream.XMLInputFactory().newInstance().createXMLEventReader( ... );
0155: *
0156: * Object o = u.unmarshal( xmlEventReader );
0157: * </pre>
0158: * </blockquote>
0159: *
0160: * <p>
0161: * <a name="unmarshalEx"></a>
0162: * <b>Unmarshalling XML Data</b><br>
0163: * <blockquote>
0164: * Unmarshalling can deserialize XML data that represents either an entire XML document
0165: * or a subtree of an XML document. Typically, it is sufficient to use the
0166: * unmarshalling methods described by
0167: * <a href="#unmarshalGlobal">Unmarshal root element that is declared globally</a>.
0168: * These unmarshal methods utilize {@link JAXBContext}'s mapping of global XML element
0169: * declarations and type definitions to JAXB mapped classes to initiate the
0170: * unmarshalling of the root element of XML data. When the {@link JAXBContext}'s
0171: * mappings are not sufficient to unmarshal the root element of XML data,
0172: * the application can assist the unmarshalling process by using the
0173: * <a href="#unmarshalByDeclaredType">unmarshal by declaredType methods</a>.
0174: * These methods are useful for unmarshalling XML data where
0175: * the root element corresponds to a local element declaration in the schema.
0176: * </blockquote>
0177: *
0178: * <blockquote>
0179: * An unmarshal method never returns null. If the unmarshal process is unable to unmarshal
0180: * the root of XML content to a JAXB mapped object, a fatal error is reported that
0181: * terminates processing by throwing JAXBException.
0182: * </blockquote>
0183: *
0184: * <p>
0185: * <a name="unmarshalGlobal"></a>
0186: * <b>Unmarshal a root element that is globally declared</b><br>
0187: * <blockquote>
0188: * The unmarshal methods that do not have an <tt>declaredType</tt> parameter use
0189: * {@link JAXBContext} to unmarshal the root element of an XML data. The {@link JAXBContext}
0190: * instance is the one that was used to create this <tt>Unmarshaller</tt>. The {@link JAXBContext}
0191: * instance maintains a mapping of globally declared XML element and type definition names to
0192: * JAXB mapped classes. The unmarshal method checks if {@link JAXBContext} has a mapping
0193: * from the root element's XML name and/or <tt>@xsi:type</tt> to a JAXB mapped class. If it does, it umarshalls the
0194: * XML data using the appropriate JAXB mapped class. Note that when the root element name is unknown and the root
0195: * element has an <tt>@xsi:type</tt>, the XML data is unmarshalled
0196: * using that JAXB mapped class as the value of a {@link JAXBElement}.
0197: * When the {@link JAXBContext} object does not have a mapping for the root element's name
0198: * nor its <tt>@xsi:type</tt>, if it exists,
0199: * then the unmarshal operation will abort immediately by throwing a {@link UnmarshalException
0200: * UnmarshalException}. This exception scenario can be worked around by using the unmarshal by
0201: * declaredType methods described in the next subsection.
0202: * </blockquote>
0203: *
0204: * <p>
0205: * <a name="unmarshalByDeclaredType"></a>
0206: * <b>Unmarshal by Declared Type</b><br>
0207: * <blockquote>
0208: * The unmarshal methods with a <code>declaredType</code> parameter enable an
0209: * application to deserialize a root element of XML data, even when
0210: * there is no mapping in {@link JAXBContext} of the root element's XML name.
0211: * The unmarshaller unmarshals the root element using the application provided
0212: * mapping specified as the <tt>declaredType</tt> parameter.
0213: * Note that even when the root element's element name is mapped by {@link JAXBContext},
0214: * the <code>declaredType</code> parameter overrides that mapping for
0215: * deserializing the root element when using these unmarshal methods.
0216: * Additionally, when the root element of XML data has an <tt>xsi:type</tt> attribute and
0217: * that attribute's value references a type definition that is mapped
0218: * to a JAXB mapped class by {@link JAXBContext}, that the root
0219: * element's <tt>xsi:type</tt> attribute takes
0220: * precedence over the unmarshal methods <tt>declaredType</tt> parameter.
0221: * These methods always return a <tt>JAXBElement<declaredType></tt>
0222: * instance. The table below shows how the properties of the returned JAXBElement
0223: * instance are set.
0224: *
0225: * <a name="unmarshalDeclaredTypeReturn"></a>
0226: * <p>
0227: * <table border="2" rules="all" cellpadding="4">
0228: * <thead>
0229: * <tr>
0230: * <th align="center" colspan="2">
0231: * Unmarshal By Declared Type returned JAXBElement
0232: * </tr>
0233: * <tr>
0234: * <th>JAXBElement Property</th>
0235: * <th>Value</th>
0236: * </tr>
0237: * </tr>
0238: * <tr>
0239: * <td>name</td>
0240: * <td><code>xml element name</code></td>
0241: * </tr>
0242: * </thead>
0243: * <tbody>
0244: * <tr>
0245: * <td>value</td>
0246: * <td><code>instanceof declaredType</code></td>
0247: * </tr>
0248: * <tr>
0249: * <td>declaredType</td>
0250: * <td>unmarshal method <code>declaredType</code> parameter</td>
0251: * </tr>
0252: * <tr>
0253: * <td>scope</td>
0254: * <td><code>null</code> <i>(actual scope is unknown)</td>
0255: * </tr>
0256: * </tbody>
0257: * </table>
0258: * </blockquote>
0259: *
0260: * <p>
0261: * The following is an example of
0262: * <a href="#unmarshalByDeclaredType">unmarshal by declaredType method</a>.
0263: * <p>
0264: * Unmarshal by declaredType from a <tt>org.w3c.dom.Node</tt>:
0265: * <blockquote>
0266: * <pre>
0267: * Schema fragment for example
0268: * <xs:schema>
0269: * <xs:complexType name="FooType">...<\xs:complexType>
0270: * <!-- global element declaration "PurchaseOrder" -->
0271: * <xs:element name="PurchaseOrder">
0272: * <xs:complexType>
0273: * <xs:sequence>
0274: * <!-- local element declaration "foo" -->
0275: * <xs:element name="foo" type="FooType"/>
0276: * ...
0277: * </xs:sequence>
0278: * </xs:complexType>
0279: * </xs:element>
0280: * </xs:schema>
0281: *
0282: * JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
0283: * Unmarshaller u = jc.createUnmarshaller();
0284: *
0285: * DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
0286: * dbf.setNamespaceAware(true);
0287: * DocumentBuilder db = dbf.newDocumentBuilder();
0288: * Document doc = db.parse(new File( "nosferatu.xml"));
0289: * Element fooSubtree = ...; // traverse DOM till reach xml element foo, constrained by a
0290: * // local element declaration in schema.
0291: *
0292: * // FooType is the JAXB mapping of the type of local element declaration foo.
0293: * JAXBElement<FooType> foo = u.unmarshal( fooSubtree, FooType.class);
0294: * </pre>
0295: * </blockquote>
0296: *
0297: * <p>
0298: * <b>Support for SAX2.0 Compliant Parsers</b><br>
0299: * <blockquote>
0300: * A client application has the ability to select the SAX2.0 compliant parser
0301: * of their choice. If a SAX parser is not selected, then the JAXB Provider's
0302: * default parser will be used. Even though the JAXB Provider's default parser
0303: * is not required to be SAX2.0 compliant, all providers are required to allow
0304: * a client application to specify their own SAX2.0 parser. Some providers may
0305: * require the client application to specify the SAX2.0 parser at schema compile
0306: * time. See {@link #unmarshal(javax.xml.transform.Source) unmarshal(Source)}
0307: * for more detail.
0308: * </blockquote>
0309: *
0310: * <p>
0311: * <b>Validation and Well-Formedness</b><br>
0312: * <blockquote>
0313: * <p>
0314: * A client application can enable or disable JAXP 1.3 validation
0315: * mechanism via the <tt>setSchema(javax.xml.validation.Schema)</tt> API.
0316: * Sophisticated clients can specify their own validating SAX 2.0 compliant
0317: * parser and bypass the JAXP 1.3 validation mechanism using the
0318: * {@link #unmarshal(javax.xml.transform.Source) unmarshal(Source)} API.
0319: *
0320: * <p>
0321: * Since unmarshalling invalid XML content is defined in JAXB 2.0,
0322: * the Unmarshaller default validation event handler was made more lenient
0323: * than in JAXB 1.0. When schema-derived code generated
0324: * by JAXB 1.0 binding compiler is registered with {@link JAXBContext},
0325: * the default unmarshal validation handler is
0326: * {@link javax.xml.bind.helpers.DefaultValidationEventHandler} and it
0327: * terminates the marshal operation after encountering either a fatal error or an error.
0328: * For a JAXB 2.0 client application, there is no explicitly defined default
0329: * validation handler and the default event handling only
0330: * terminates the marshal operation after encountering a fatal error.
0331: *
0332: * </blockquote>
0333: *
0334: * <p>
0335: * <a name="supportedProps"></a>
0336: * <b>Supported Properties</b><br>
0337: * <blockquote>
0338: * <p>
0339: * There currently are not any properties required to be supported by all
0340: * JAXB Providers on Unmarshaller. However, some providers may support
0341: * their own set of provider specific properties.
0342: * </blockquote>
0343: *
0344: * <p>
0345: * <a name="unmarshalEventCallback"></a>
0346: * <b>Unmarshal Event Callbacks</b><br>
0347: * <blockquote>
0348: * The {@link Unmarshaller} provides two styles of callback mechanisms
0349: * that allow application specific processing during key points in the
0350: * unmarshalling process. In 'class defined' event callbacks, application
0351: * specific code placed in JAXB mapped classes is triggered during
0352: * unmarshalling. 'External listeners' allow for centralized processing
0353: * of unmarshal events in one callback method rather than by type event callbacks.
0354: * <p>
0355: * 'Class defined' event callback methods allow any JAXB mapped class to specify
0356: * its own specific callback methods by defining methods with the following method signature:
0357: * <blockquote>
0358: * <pre>
0359: * // This method is called immediately after the object is created and before the unmarshalling of this
0360: * // object begins. The callback provides an opportunity to initialize JavaBean properties prior to unmarshalling.
0361: * void beforeUnmarshal(Unmarshaller, Object parent);
0362: *
0363: * //This method is called after all the properties (except IDREF) are unmarshalled for this object,
0364: * //but before this object is set to the parent object.
0365: * void afterUnmarshal(Unmarshaller, Object parent);
0366: * </pre>
0367: * </blockquote>
0368: * The class defined callback methods should be used when the callback method requires
0369: * access to non-public methods and/or fields of the class.
0370: * <p>
0371: * The external listener callback mechanism enables the registration of a {@link Listener}
0372: * instance with an {@link Unmarshaller#setListener(Listener)}. The external listener receives all callback events,
0373: * allowing for more centralized processing than per class defined callback methods. The external listener
0374: * receives events when unmarshalling proces is marshalling to a JAXB element or to JAXB mapped class.
0375: * <p>
0376: * The 'class defined' and external listener event callback methods are independent of each other,
0377: * both can be called for one event. The invocation ordering when both listener callback methods exist is
0378: * defined in {@link Listener#beforeUnmarshal(Object, Object)} and {@link Listener#afterUnmarshal(Object, Object)}.
0379: * <p>
0380: * An event callback method throwing an exception terminates the current unmarshal process.
0381: *
0382: * </blockquote>
0383: *
0384: * @author <ul><li>Ryan Shoemaker, Sun Microsystems, Inc.</li><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li><li>Joe Fialli, Sun Microsystems, Inc.</li></ul>
0385: * @version $Revision: 1.32 $ $Date: 2005/08/18 15:18:26 $
0386: * @see JAXBContext
0387: * @see Marshaller
0388: * @see Validator
0389: * @since JAXB1.0
0390: */
0391: public interface Unmarshaller {
0392:
0393: /**
0394: * Unmarshal XML data from the specified file and return the resulting
0395: * content tree.
0396: *
0397: * <p>
0398: * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
0399: *
0400: * @param f the file to unmarshal XML data from
0401: * @return the newly created root object of the java content tree
0402: *
0403: * @throws JAXBException
0404: * If any unexpected errors occur while unmarshalling
0405: * @throws UnmarshalException
0406: * If the {@link ValidationEventHandler ValidationEventHandler}
0407: * returns false from its <tt>handleEvent</tt> method or the
0408: * <tt>Unmarshaller</tt> is unable to perform the XML to Java
0409: * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
0410: * @throws IllegalArgumentException
0411: * If the file parameter is null
0412: */
0413: public Object unmarshal(java.io.File f) throws JAXBException;
0414:
0415: /**
0416: * Unmarshal XML data from the specified InputStream and return the
0417: * resulting content tree. Validation event location information may
0418: * be incomplete when using this form of the unmarshal API.
0419: *
0420: * <p>
0421: * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
0422: *
0423: * @param is the InputStream to unmarshal XML data from
0424: * @return the newly created root object of the java content tree
0425: *
0426: * @throws JAXBException
0427: * If any unexpected errors occur while unmarshalling
0428: * @throws UnmarshalException
0429: * If the {@link ValidationEventHandler ValidationEventHandler}
0430: * returns false from its <tt>handleEvent</tt> method or the
0431: * <tt>Unmarshaller</tt> is unable to perform the XML to Java
0432: * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
0433: * @throws IllegalArgumentException
0434: * If the InputStream parameter is null
0435: */
0436: public Object unmarshal(java.io.InputStream is)
0437: throws JAXBException;
0438:
0439: /**
0440: * Unmarshal XML data from the specified Reader and return the
0441: * resulting content tree. Validation event location information may
0442: * be incomplete when using this form of the unmarshal API,
0443: * because a Reader does not provide the system ID.
0444: *
0445: * <p>
0446: * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
0447: *
0448: * @param reader the Reader to unmarshal XML data from
0449: * @return the newly created root object of the java content tree
0450: *
0451: * @throws JAXBException
0452: * If any unexpected errors occur while unmarshalling
0453: * @throws UnmarshalException
0454: * If the {@link ValidationEventHandler ValidationEventHandler}
0455: * returns false from its <tt>handleEvent</tt> method or the
0456: * <tt>Unmarshaller</tt> is unable to perform the XML to Java
0457: * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
0458: * @throws IllegalArgumentException
0459: * If the InputStream parameter is null
0460: * @since JAXB2.0
0461: */
0462: public Object unmarshal(Reader reader) throws JAXBException;
0463:
0464: /**
0465: * Unmarshal XML data from the specified URL and return the resulting
0466: * content tree.
0467: *
0468: * <p>
0469: * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
0470: *
0471: * @param url the url to unmarshal XML data from
0472: * @return the newly created root object of the java content tree
0473: *
0474: * @throws JAXBException
0475: * If any unexpected errors occur while unmarshalling
0476: * @throws UnmarshalException
0477: * If the {@link ValidationEventHandler ValidationEventHandler}
0478: * returns false from its <tt>handleEvent</tt> method or the
0479: * <tt>Unmarshaller</tt> is unable to perform the XML to Java
0480: * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
0481: * @throws IllegalArgumentException
0482: * If the URL parameter is null
0483: */
0484: public Object unmarshal(java.net.URL url) throws JAXBException;
0485:
0486: /**
0487: * Unmarshal XML data from the specified SAX InputSource and return the
0488: * resulting content tree.
0489: *
0490: * <p>
0491: * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
0492: *
0493: * @param source the input source to unmarshal XML data from
0494: * @return the newly created root object of the java content tree
0495: *
0496: * @throws JAXBException
0497: * If any unexpected errors occur while unmarshalling
0498: * @throws UnmarshalException
0499: * If the {@link ValidationEventHandler ValidationEventHandler}
0500: * returns false from its <tt>handleEvent</tt> method or the
0501: * <tt>Unmarshaller</tt> is unable to perform the XML to Java
0502: * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
0503: * @throws IllegalArgumentException
0504: * If the InputSource parameter is null
0505: */
0506: public Object unmarshal(org.xml.sax.InputSource source)
0507: throws JAXBException;
0508:
0509: /**
0510: * Unmarshal global XML data from the specified DOM tree and return the resulting
0511: * content tree.
0512: *
0513: * <p>
0514: * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
0515: *
0516: * @param node
0517: * the document/element to unmarshal XML data from.
0518: * The caller must support at least Document and Element.
0519: * @return the newly created root object of the java content tree
0520: *
0521: * @throws JAXBException
0522: * If any unexpected errors occur while unmarshalling
0523: * @throws UnmarshalException
0524: * If the {@link ValidationEventHandler ValidationEventHandler}
0525: * returns false from its <tt>handleEvent</tt> method or the
0526: * <tt>Unmarshaller</tt> is unable to perform the XML to Java
0527: * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
0528: * @throws IllegalArgumentException
0529: * If the Node parameter is null
0530: * @see #unmarshal(org.w3c.dom.Node, Class)
0531: */
0532: public Object unmarshal(org.w3c.dom.Node node) throws JAXBException;
0533:
0534: /**
0535: * Unmarshal XML data by JAXB mapped <tt>declaredType</tt>
0536: * and return the resulting content tree.
0537: *
0538: * <p>
0539: * Implements <a href="#unmarshalByDeclaredType">Unmarshal by Declared Type</a>
0540: *
0541: * @param node
0542: * the document/element to unmarshal XML data from.
0543: * The caller must support at least Document and Element.
0544: * @param declaredType
0545: * appropriate JAXB mapped class to hold <tt>node</tt>'s XML data.
0546: *
0547: * @return <a href="#unmarshalDeclaredTypeReturn">JAXB Element</a> representation of <tt>node</tt>
0548: *
0549: * @throws JAXBException
0550: * If any unexpected errors occur while unmarshalling
0551: * @throws UnmarshalException
0552: * If the {@link ValidationEventHandler ValidationEventHandler}
0553: * returns false from its <tt>handleEvent</tt> method or the
0554: * <tt>Unmarshaller</tt> is unable to perform the XML to Java
0555: * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
0556: * @throws IllegalArgumentException
0557: * If any parameter is null
0558: * @since JAXB2.0
0559: */
0560: public <T> JAXBElement<T> unmarshal(org.w3c.dom.Node node,
0561: Class<T> declaredType) throws JAXBException;
0562:
0563: /**
0564: * Unmarshal XML data from the specified XML Source and return the
0565: * resulting content tree.
0566: *
0567: * <p>
0568: * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
0569: *
0570: * <p>
0571: * <a name="saxParserPlugable"></a>
0572: * <b>SAX 2.0 Parser Pluggability</b>
0573: * <p>
0574: * A client application can choose not to use the default parser mechanism
0575: * supplied with their JAXB provider. Any SAX 2.0 compliant parser can be
0576: * substituted for the JAXB provider's default mechanism. To do so, the
0577: * client application must properly configure a <tt>SAXSource</tt> containing
0578: * an <tt>XMLReader</tt> implemented by the SAX 2.0 parser provider. If the
0579: * <tt>XMLReader</tt> has an <tt>org.xml.sax.ErrorHandler</tt> registered
0580: * on it, it will be replaced by the JAXB Provider so that validation errors
0581: * can be reported via the <tt>ValidationEventHandler</tt> mechanism of
0582: * JAXB. If the <tt>SAXSource</tt> does not contain an <tt>XMLReader</tt>,
0583: * then the JAXB provider's default parser mechanism will be used.
0584: * <p>
0585: * This parser replacement mechanism can also be used to replace the JAXB
0586: * provider's unmarshal-time validation engine. The client application
0587: * must properly configure their SAX 2.0 compliant parser to perform
0588: * validation (as shown in the example above). Any <tt>SAXParserExceptions
0589: * </tt> encountered by the parser during the unmarshal operation will be
0590: * processed by the JAXB provider and converted into JAXB
0591: * <tt>ValidationEvent</tt> objects which will be reported back to the
0592: * client via the <tt>ValidationEventHandler</tt> registered with the
0593: * <tt>Unmarshaller</tt>. <i>Note:</i> specifying a substitute validating
0594: * SAX 2.0 parser for unmarshalling does not necessarily replace the
0595: * validation engine used by the JAXB provider for performing on-demand
0596: * validation.
0597: * <p>
0598: * The only way for a client application to specify an alternate parser
0599: * mechanism to be used during unmarshal is via the
0600: * <tt>unmarshal(SAXSource)</tt> API. All other forms of the unmarshal
0601: * method (File, URL, Node, etc) will use the JAXB provider's default
0602: * parser and validator mechanisms.
0603: *
0604: * @param source the XML Source to unmarshal XML data from (providers are
0605: * only required to support SAXSource, DOMSource, and StreamSource)
0606: * @return the newly created root object of the java content tree
0607: *
0608: * @throws JAXBException
0609: * If any unexpected errors occur while unmarshalling
0610: * @throws UnmarshalException
0611: * If the {@link ValidationEventHandler ValidationEventHandler}
0612: * returns false from its <tt>handleEvent</tt> method or the
0613: * <tt>Unmarshaller</tt> is unable to perform the XML to Java
0614: * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
0615: * @throws IllegalArgumentException
0616: * If the Source parameter is null
0617: * @see #unmarshal(javax.xml.transform.Source, Class)
0618: */
0619: public Object unmarshal(javax.xml.transform.Source source)
0620: throws JAXBException;
0621:
0622: /**
0623: * Unmarshal XML data from the specified XML Source by <tt>declaredType</tt> and return the
0624: * resulting content tree.
0625: *
0626: * <p>
0627: * Implements <a href="#unmarshalByDeclaredType">Unmarshal by Declared Type</a>
0628: *
0629: * <p>
0630: * See <a href="#saxParserPlugable">SAX 2.0 Parser Pluggability</a>
0631: *
0632: * @param source the XML Source to unmarshal XML data from (providers are
0633: * only required to support SAXSource, DOMSource, and StreamSource)
0634: * @param declaredType
0635: * appropriate JAXB mapped class to hold <tt>source</tt>'s xml root element
0636: * @return Java content rooted by <a href="#unmarshalDeclaredTypeReturn">JAXB Element</a>
0637: *
0638: * @throws JAXBException
0639: * If any unexpected errors occur while unmarshalling
0640: * @throws UnmarshalException
0641: * If the {@link ValidationEventHandler ValidationEventHandler}
0642: * returns false from its <tt>handleEvent</tt> method or the
0643: * <tt>Unmarshaller</tt> is unable to perform the XML to Java
0644: * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
0645: * @throws IllegalArgumentException
0646: * If any parameter is null
0647: * @since JAXB2.0
0648: */
0649: public <T> JAXBElement<T> unmarshal(
0650: javax.xml.transform.Source source, Class<T> declaredType)
0651: throws JAXBException;
0652:
0653: /**
0654: * Unmarshal XML data from the specified pull parser and return the
0655: * resulting content tree.
0656: *
0657: * <p>
0658: * Implements <a href="#unmarshalGlobal">Unmarshal Global Root Element</a>.
0659: *
0660: * <p>
0661: * This method assumes that the parser is on a START_DOCUMENT or
0662: * START_ELEMENT event. Unmarshalling will be done from this
0663: * start event to the corresponding end event. If this method
0664: * returns successfully, the <tt>reader</tt> will be pointing at
0665: * the token right after the end event.
0666: *
0667: * @param reader
0668: * The parser to be read.
0669: * @return
0670: * the newly created root object of the java content tree.
0671: *
0672: * @throws JAXBException
0673: * If any unexpected errors occur while unmarshalling
0674: * @throws UnmarshalException
0675: * If the {@link ValidationEventHandler ValidationEventHandler}
0676: * returns false from its <tt>handleEvent</tt> method or the
0677: * <tt>Unmarshaller</tt> is unable to perform the XML to Java
0678: * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
0679: * @throws IllegalArgumentException
0680: * If the <tt>reader</tt> parameter is null
0681: * @throws IllegalStateException
0682: * If <tt>reader</tt> is not pointing to a START_DOCUMENT or
0683: * START_ELEMENT event.
0684: * @since JAXB2.0
0685: * @see #unmarshal(javax.xml.stream.XMLStreamReader, Class)
0686: */
0687: public Object unmarshal(javax.xml.stream.XMLStreamReader reader)
0688: throws JAXBException;
0689:
0690: /**
0691: * Unmarshal root element to JAXB mapped <tt>declaredType</tt>
0692: * and return the resulting content tree.
0693: *
0694: * <p>
0695: * This method implements <a href="unmarshalByDeclaredType">unmarshal by declaredType</a>.
0696: * <p>
0697: * This method assumes that the parser is on a START_DOCUMENT or
0698: * START_ELEMENT event. Unmarshalling will be done from this
0699: * start event to the corresponding end event. If this method
0700: * returns successfully, the <tt>reader</tt> will be pointing at
0701: * the token right after the end event.
0702: *
0703: * @param reader
0704: * The parser to be read.
0705: * @param declaredType
0706: * appropriate JAXB mapped class to hold <tt>reader</tt>'s START_ELEMENT XML data.
0707: *
0708: * @return content tree rooted by <a href="#unmarshalDeclaredTypeReturn">JAXB Element representation</a>
0709: *
0710: * @throws JAXBException
0711: * If any unexpected errors occur while unmarshalling
0712: * @throws UnmarshalException
0713: * If the {@link ValidationEventHandler ValidationEventHandler}
0714: * returns false from its <tt>handleEvent</tt> method or the
0715: * <tt>Unmarshaller</tt> is unable to perform the XML to Java
0716: * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
0717: * @throws IllegalArgumentException
0718: * If any parameter is null
0719: * @since JAXB2.0
0720: */
0721: public <T> JAXBElement<T> unmarshal(
0722: javax.xml.stream.XMLStreamReader reader,
0723: Class<T> declaredType) throws JAXBException;
0724:
0725: /**
0726: * Unmarshal XML data from the specified pull parser and return the
0727: * resulting content tree.
0728: *
0729: * <p>
0730: * This method is an <a href="#unmarshalGlobal">Unmarshal Global Root method</a>.
0731: *
0732: * <p>
0733: * This method assumes that the parser is on a START_DOCUMENT or
0734: * START_ELEMENT event. Unmarshalling will be done from this
0735: * start event to the corresponding end event. If this method
0736: * returns successfully, the <tt>reader</tt> will be pointing at
0737: * the token right after the end event.
0738: *
0739: * @param reader
0740: * The parser to be read.
0741: * @return
0742: * the newly created root object of the java content tree.
0743: *
0744: * @throws JAXBException
0745: * If any unexpected errors occur while unmarshalling
0746: * @throws UnmarshalException
0747: * If the {@link ValidationEventHandler ValidationEventHandler}
0748: * returns false from its <tt>handleEvent</tt> method or the
0749: * <tt>Unmarshaller</tt> is unable to perform the XML to Java
0750: * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
0751: * @throws IllegalArgumentException
0752: * If the <tt>reader</tt> parameter is null
0753: * @throws IllegalStateException
0754: * If <tt>reader</tt> is not pointing to a START_DOCUMENT or
0755: * START_ELEMENT event.
0756: * @since JAXB2.0
0757: * @see #unmarshal(javax.xml.stream.XMLEventReader, Class)
0758: */
0759: public Object unmarshal(javax.xml.stream.XMLEventReader reader)
0760: throws JAXBException;
0761:
0762: /**
0763: * Unmarshal root element to JAXB mapped <tt>declaredType</tt>
0764: * and return the resulting content tree.
0765: *
0766: * <p>
0767: * This method implements <a href="unmarshalByDeclaredType">unmarshal by declaredType</a>.
0768: *
0769: * <p>
0770: * This method assumes that the parser is on a START_DOCUMENT or
0771: * START_ELEMENT event. Unmarshalling will be done from this
0772: * start event to the corresponding end event. If this method
0773: * returns successfully, the <tt>reader</tt> will be pointing at
0774: * the token right after the end event.
0775: *
0776: * @param reader
0777: * The parser to be read.
0778: * @param declaredType
0779: * appropriate JAXB mapped class to hold <tt>reader</tt>'s START_ELEMENT XML data.
0780: *
0781: * @return content tree rooted by <a href="#unmarshalDeclaredTypeReturn">JAXB Element representation</a>
0782: *
0783: * @throws JAXBException
0784: * If any unexpected errors occur while unmarshalling
0785: * @throws UnmarshalException
0786: * If the {@link ValidationEventHandler ValidationEventHandler}
0787: * returns false from its <tt>handleEvent</tt> method or the
0788: * <tt>Unmarshaller</tt> is unable to perform the XML to Java
0789: * binding. See <a href="#unmarshalEx">Unmarshalling XML Data</a>
0790: * @throws IllegalArgumentException
0791: * If any parameter is null
0792: * @since JAXB2.0
0793: */
0794: public <T> JAXBElement<T> unmarshal(
0795: javax.xml.stream.XMLEventReader reader,
0796: Class<T> declaredType) throws JAXBException;
0797:
0798: /**
0799: * Get an unmarshaller handler object that can be used as a component in
0800: * an XML pipeline.
0801: *
0802: * <p>
0803: * The JAXB Provider can return the same handler object for multiple
0804: * invocations of this method. In other words, this method does not
0805: * necessarily create a new instance of <tt>UnmarshallerHandler</tt>. If the
0806: * application needs to use more than one <tt>UnmarshallerHandler</tt>, it
0807: * should create more than one <tt>Unmarshaller</tt>.
0808: *
0809: * @return the unmarshaller handler object
0810: * @see UnmarshallerHandler
0811: */
0812: public UnmarshallerHandler getUnmarshallerHandler();
0813:
0814: /**
0815: * Specifies whether or not the default validation mechanism of the
0816: * <tt>Unmarshaller</tt> should validate during unmarshal operations.
0817: * By default, the <tt>Unmarshaller</tt> does not validate.
0818: * <p>
0819: * This method may only be invoked before or after calling one of the
0820: * unmarshal methods.
0821: * <p>
0822: * This method only controls the JAXB Provider's default unmarshal-time
0823: * validation mechanism - it has no impact on clients that specify their
0824: * own validating SAX 2.0 compliant parser. Clients that specify their
0825: * own unmarshal-time validation mechanism may wish to turn off the JAXB
0826: * Provider's default validation mechanism via this API to avoid "double
0827: * validation".
0828: * <p>
0829: * This method is deprecated as of JAXB 2.0 - please use the new
0830: * {@link #setSchema(javax.xml.validation.Schema)} API.
0831: *
0832: * @param validating true if the Unmarshaller should validate during
0833: * unmarshal, false otherwise
0834: * @throws JAXBException if an error occurred while enabling or disabling
0835: * validation at unmarshal time
0836: * @throws UnsupportedOperationException could be thrown if this method is
0837: * invoked on an Unmarshaller created from a JAXBContext referencing
0838: * JAXB 2.0 mapped classes
0839: * @deprecated since JAXB2.0, please see {@link #setSchema(javax.xml.validation.Schema)}
0840: */
0841: public void setValidating(boolean validating) throws JAXBException;
0842:
0843: /**
0844: * Indicates whether or not the <tt>Unmarshaller</tt> is configured to
0845: * validate during unmarshal operations.
0846: * <p>
0847: * This API returns the state of the JAXB Provider's default unmarshal-time
0848: * validation mechanism.
0849: * <p>
0850: * This method is deprecated as of JAXB 2.0 - please use the new
0851: * {@link #getSchema()} API.
0852: *
0853: * @return true if the Unmarshaller is configured to validate during
0854: * unmarshal operations, false otherwise
0855: * @throws JAXBException if an error occurs while retrieving the validating
0856: * flag
0857: * @throws UnsupportedOperationException could be thrown if this method is
0858: * invoked on an Unmarshaller created from a JAXBContext referencing
0859: * JAXB 2.0 mapped classes
0860: * @deprecated since JAXB2.0, please see {@link #getSchema()}
0861: */
0862: public boolean isValidating() throws JAXBException;
0863:
0864: /**
0865: * Allow an application to register a <tt>ValidationEventHandler</tt>.
0866: * <p>
0867: * The <tt>ValidationEventHandler</tt> will be called by the JAXB Provider
0868: * if any validation errors are encountered during calls to any of the
0869: * unmarshal methods. If the client application does not register a
0870: * <tt>ValidationEventHandler</tt> before invoking the unmarshal methods,
0871: * then <tt>ValidationEvents</tt> will be handled by the default event
0872: * handler which will terminate the unmarshal operation after the first
0873: * error or fatal error is encountered.
0874: * <p>
0875: * Calling this method with a null parameter will cause the Unmarshaller
0876: * to revert back to the default event handler.
0877: *
0878: * @param handler the validation event handler
0879: * @throws JAXBException if an error was encountered while setting the
0880: * event handler
0881: */
0882: public void setEventHandler(ValidationEventHandler handler)
0883: throws JAXBException;
0884:
0885: /**
0886: * Return the current event handler or the default event handler if one
0887: * hasn't been set.
0888: *
0889: * @return the current ValidationEventHandler or the default event handler
0890: * if it hasn't been set
0891: * @throws JAXBException if an error was encountered while getting the
0892: * current event handler
0893: */
0894: public ValidationEventHandler getEventHandler()
0895: throws JAXBException;
0896:
0897: /**
0898: * Set the particular property in the underlying implementation of
0899: * <tt>Unmarshaller</tt>. This method can only be used to set one of
0900: * the standard JAXB defined properties above or a provider specific
0901: * property. Attempting to set an undefined property will result in
0902: * a PropertyException being thrown. See <a href="#supportedProps">
0903: * Supported Properties</a>.
0904: *
0905: * @param name the name of the property to be set. This value can either
0906: * be specified using one of the constant fields or a user
0907: * supplied string.
0908: * @param value the value of the property to be set
0909: *
0910: * @throws PropertyException when there is an error processing the given
0911: * property or value
0912: * @throws IllegalArgumentException
0913: * If the name parameter is null
0914: */
0915: public void setProperty(String name, Object value)
0916: throws PropertyException;
0917:
0918: /**
0919: * Get the particular property in the underlying implementation of
0920: * <tt>Unmarshaller</tt>. This method can only be used to get one of
0921: * the standard JAXB defined properties above or a provider specific
0922: * property. Attempting to get an undefined property will result in
0923: * a PropertyException being thrown. See <a href="#supportedProps">
0924: * Supported Properties</a>.
0925: *
0926: * @param name the name of the property to retrieve
0927: * @return the value of the requested property
0928: *
0929: * @throws PropertyException
0930: * when there is an error retrieving the given property or value
0931: * property name
0932: * @throws IllegalArgumentException
0933: * If the name parameter is null
0934: */
0935: public Object getProperty(String name) throws PropertyException;
0936:
0937: /**
0938: * Specify the JAXP 1.3 {@link javax.xml.validation.Schema Schema}
0939: * object that should be used to validate subsequent unmarshal operations
0940: * against. Passing null into this method will disable validation.
0941: * <p>
0942: * This method replaces the deprecated {@link #setValidating(boolean) setValidating(boolean)}
0943: * API.
0944: *
0945: * <p>
0946: * Initially this property is set to <tt>null</tt>.
0947: *
0948: * @param schema Schema object to validate unmarshal operations against or null to disable validation
0949: * @throws UnsupportedOperationException could be thrown if this method is
0950: * invoked on an Unmarshaller created from a JAXBContext referencing
0951: * JAXB 1.0 mapped classes
0952: * @since JAXB2.0
0953: */
0954: public void setSchema(javax.xml.validation.Schema schema);
0955:
0956: /**
0957: * Get the JAXP 1.3 {@link javax.xml.validation.Schema Schema} object
0958: * being used to perform unmarshal-time validation. If there is no
0959: * Schema set on the unmarshaller, then this method will return null
0960: * indicating that unmarshal-time validation will not be performed.
0961: * <p>
0962: * This method provides replacement functionality for the deprecated
0963: * {@link #isValidating()} API as well as access to the Schema object.
0964: * To determine if the Unmarshaller has validation enabled, simply
0965: * test the return type for null:
0966: * <p>
0967: * <code>
0968: * boolean isValidating = u.getSchema()!=null;
0969: * </code>
0970: *
0971: * @return the Schema object being used to perform unmarshal-time
0972: * validation or null if not present
0973: * @throws UnsupportedOperationException could be thrown if this method is
0974: * invoked on an Unmarshaller created from a JAXBContext referencing
0975: * JAXB 1.0 mapped classes
0976: * @since JAXB2.0
0977: */
0978: public javax.xml.validation.Schema getSchema();
0979:
0980: /**
0981: * Associates a configured instance of {@link XmlAdapter} with this unmarshaller.
0982: *
0983: * <p>
0984: * This is a convenience method that invokes <code>setAdapter(adapter.getClass(),adapter);</code>.
0985: *
0986: * @see #setAdapter(Class,XmlAdapter)
0987: * @throws IllegalArgumentException
0988: * if the adapter parameter is null.
0989: * @throws UnsupportedOperationException
0990: * if invoked agains a JAXB 1.0 implementation.
0991: * @since JAXB2.0
0992: */
0993: public void setAdapter(XmlAdapter adapter);
0994:
0995: /**
0996: * Associates a configured instance of {@link XmlAdapter} with this unmarshaller.
0997: *
0998: * <p>
0999: * Every unmarshaller internally maintains a
1000: * {@link java.util.Map}<{@link Class},{@link XmlAdapter}>,
1001: * which it uses for unmarshalling classes whose fields/methods are annotated
1002: * with {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter}.
1003: *
1004: * <p>
1005: * This method allows applications to use a configured instance of {@link XmlAdapter}.
1006: * When an instance of an adapter is not given, an unmarshaller will create
1007: * one by invoking its default constructor.
1008: *
1009: * @param type
1010: * The type of the adapter. The specified instance will be used when
1011: * {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter#value()}
1012: * refers to this type.
1013: * @param adapter
1014: * The instance of the adapter to be used. If null, it will un-register
1015: * the current adapter set for this type.
1016: * @throws IllegalArgumentException
1017: * if the type parameter is null.
1018: * @throws UnsupportedOperationException
1019: * if invoked agains a JAXB 1.0 implementation.
1020: * @since JAXB2.0
1021: */
1022: public <A extends XmlAdapter> void setAdapter(Class<A> type,
1023: A adapter);
1024:
1025: /**
1026: * Gets the adapter associated with the specified type.
1027: *
1028: * This is the reverse operation of the {@link #setAdapter} method.
1029: *
1030: * @throws IllegalArgumentException
1031: * if the type parameter is null.
1032: * @throws UnsupportedOperationException
1033: * if invoked agains a JAXB 1.0 implementation.
1034: * @since JAXB2.0
1035: */
1036: public <A extends XmlAdapter> A getAdapter(Class<A> type);
1037:
1038: /**
1039: * <p>Associate a context that resolves cid's, content-id URIs, to
1040: * binary data passed as attachments.</p>
1041: * <p/>
1042: * <p>Unmarshal time validation, enabled via {@link #setSchema(Schema)},
1043: * must be supported even when unmarshaller is performing XOP processing.
1044: * </p>
1045: *
1046: * @throws IllegalStateException if attempt to concurrently call this
1047: * method during a unmarshal operation.
1048: */
1049: void setAttachmentUnmarshaller(AttachmentUnmarshaller au);
1050:
1051: AttachmentUnmarshaller getAttachmentUnmarshaller();
1052:
1053: /**
1054: * <p/>
1055: * Register an instance of an implementation of this class with {@link Unmarshaller} to externally listen
1056: * for unmarshal events.
1057: * <p/>
1058: * <p/>
1059: * This class enables pre and post processing of an instance of a JAXB mapped class
1060: * as XML data is unmarshalled into it. The event callbacks are called when unmarshalling
1061: * XML content into a JAXBElement instance or a JAXB mapped class that represents a complex type definition.
1062: * The event callbacks are not called when unmarshalling to an instance of a
1063: * Java datatype that represents a simple type definition.
1064: * <p/>
1065: * <p/>
1066: * External listener is one of two different mechanisms for defining unmarshal event callbacks.
1067: * See <a href="Unmarshaller.html#unmarshalEventCallback">Unmarshal Event Callbacks</a> for an overview.
1068: * <p/>
1069: * (@link #setListener(Listener)}
1070: * (@link #getListener()}
1071: *
1072: * @since JAXB2.0
1073: */
1074: public static abstract class Listener {
1075: /**
1076: * <p/>
1077: * Callback method invoked before unmarshalling into <tt>target</tt>.
1078: * <p/>
1079: * <p/>
1080: * This method is invoked immediately after <tt>target</tt> was created and
1081: * before the unmarshalling of this object begins. Note that
1082: * if the class of <tt>target</tt> defines its own <tt>beforeUnmarshal</tt> method,
1083: * the class specific callback method is invoked before this method is invoked.
1084: *
1085: * @param target non-null instance of JAXB mapped class prior to unmarshalling into it.
1086: * @param parent instance of JAXB mapped class that will eventually reference <tt>target</tt>.
1087: * <tt>null</tt> when <tt>target</tt> is root element.
1088: */
1089: public void beforeUnmarshal(Object target, Object parent) {
1090: }
1091:
1092: /**
1093: * <p/>
1094: * Callback method invoked after unmarshalling XML data into <tt>target</tt>.
1095: * <p/>
1096: * <p/>
1097: * This method is invoked after all the properties (except IDREF) are unmarshalled into <tt>target</tt>,
1098: * but before <tt>target</tt> is set into its <tt>parent</tt> object.
1099: * Note that if the class of <tt>target</tt> defines its own <tt>afterUnmarshal</tt> method,
1100: * the class specific callback method is invoked before this method is invoked.
1101: *
1102: * @param target non-null instance of JAXB mapped class prior to unmarshalling into it.
1103: * @param parent instance of JAXB mapped class that will reference <tt>target</tt>.
1104: * <tt>null</tt> when <tt>target</tt> is root element.
1105: */
1106: public void afterUnmarshal(Object target, Object parent) {
1107: }
1108: }
1109:
1110: /**
1111: * <p>
1112: * Register unmarshal event callback {@link Listener} with this {@link Unmarshaller}.
1113: *
1114: * <p>
1115: * There is only one Listener per Unmarshaller. Setting a Listener replaces the previous set Listener.
1116: * One can unregister current Listener by setting listener to <tt>null</tt>.
1117: *
1118: * @param listener provides unmarshal event callbacks for this {@link Unmarshaller}
1119: * @since JAXB2.0
1120: */
1121: public void setListener(Listener listener);
1122:
1123: /**
1124: * <p>Return {@link Listener} registered with this {@link Unmarshaller}.
1125: *
1126: * @return registered {@link Listener} or <code>null</code> if no Listener is registered with this Unmarshaller.
1127: * @since JAXB2.0
1128: */
1129: public Listener getListener();
1130: }
|