jaxws/src/java.xml.bind/share/classes/javax/xml/bind/Unmarshaller.java
changeset 29839 6d5d546e953b
parent 28887 88470f768658
child 32795 5a5710ee05a0
equal deleted inserted replaced
29838:fe5fd9871a13 29839:6d5d546e953b
    71  *
    71  *
    72  * <p>
    72  * <p>
    73  * Unmarshalling from a StringBuffer using a
    73  * Unmarshalling from a StringBuffer using a
    74  * <tt>javax.xml.transform.stream.StreamSource</tt>:
    74  * <tt>javax.xml.transform.stream.StreamSource</tt>:
    75  * <blockquote>
    75  * <blockquote>
    76  *    <pre>
    76  *    <pre>{@code
    77  *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
    77  *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
    78  *       Unmarshaller u = jc.createUnmarshaller();
    78  *       Unmarshaller u = jc.createUnmarshaller();
    79  *       StringBuffer xmlStr = new StringBuffer( "&lt;?xml version=&quot;1.0&quot;?&gt;..." );
    79  *       StringBuffer xmlStr = new StringBuffer( "<?xml version="1.0"?>..." );
    80  *       Object o = u.unmarshal( new StreamSource( new StringReader( xmlStr.toString() ) ) );
    80  *       Object o = u.unmarshal( new StreamSource( new StringReader( xmlStr.toString() ) ) );
    81  *    </pre>
    81  *    }</pre>
    82  * </blockquote>
    82  * </blockquote>
    83  *
    83  *
    84  * <p>
    84  * <p>
    85  * Unmarshalling from a <tt>org.w3c.dom.Node</tt>:
    85  * Unmarshalling from a <tt>org.w3c.dom.Node</tt>:
    86  * <blockquote>
    86  * <blockquote>
   236  * Additionally, when the root element of XML data has an <tt>xsi:type</tt> attribute and
   236  * Additionally, when the root element of XML data has an <tt>xsi:type</tt> attribute and
   237  * that attribute's value references a type definition that is mapped
   237  * that attribute's value references a type definition that is mapped
   238  * to a JAXB mapped class by {@link JAXBContext}, that the root
   238  * to a JAXB mapped class by {@link JAXBContext}, that the root
   239  * element's <tt>xsi:type</tt> attribute takes
   239  * element's <tt>xsi:type</tt> attribute takes
   240  * precedence over the unmarshal methods <tt>declaredType</tt> parameter.
   240  * precedence over the unmarshal methods <tt>declaredType</tt> parameter.
   241  * These methods always return a <tt>JAXBElement&lt;declaredType&gt;</tt>
   241  * These methods always return a <tt>{@literal JAXBElement<declaredType>}</tt>
   242  * instance. The table below shows how the properties of the returned JAXBElement
   242  * instance. The table below shows how the properties of the returned JAXBElement
   243  * instance are set.
   243  * instance are set.
   244  *
   244  *
   245  * <a name="unmarshalDeclaredTypeReturn"></a>
   245  * <a name="unmarshalDeclaredTypeReturn"></a>
   246  *   <table summary="" border="2" rules="all" cellpadding="4">
   246  *   <table summary="" border="2" rules="all" cellpadding="4">
   279  * The following is an example of
   279  * The following is an example of
   280  * <a href="#unmarshalByDeclaredType">unmarshal by declaredType method</a>.
   280  * <a href="#unmarshalByDeclaredType">unmarshal by declaredType method</a>.
   281  * <p>
   281  * <p>
   282  * Unmarshal by declaredType from a <tt>org.w3c.dom.Node</tt>:
   282  * Unmarshal by declaredType from a <tt>org.w3c.dom.Node</tt>:
   283  * <blockquote>
   283  * <blockquote>
   284  *    <pre>
   284  *    <pre>{@code
   285  *       Schema fragment for example
   285  *       Schema fragment for example
   286  *       &lt;xs:schema&gt;
   286  *       <xs:schema>
   287  *          &lt;xs:complexType name="FooType"&gt;...&lt;\xs:complexType&gt;
   287  *          <xs:complexType name="FooType">...<\xs:complexType>
   288  *          &lt;!-- global element declaration "PurchaseOrder" --&gt;
   288  *          <!-- global element declaration "PurchaseOrder" -->
   289  *          &lt;xs:element name="PurchaseOrder"&gt;
   289  *          <xs:element name="PurchaseOrder">
   290  *              &lt;xs:complexType&gt;
   290  *              <xs:complexType>
   291  *                 &lt;xs:sequence&gt;
   291  *                 <xs:sequence>
   292  *                    &lt;!-- local element declaration "foo" --&gt;
   292  *                    <!-- local element declaration "foo" -->
   293  *                    &lt;xs:element name="foo" type="FooType"/&gt;
   293  *                    <xs:element name="foo" type="FooType"/>
   294  *                    ...
   294  *                    ...
   295  *                 &lt;/xs:sequence&gt;
   295  *                 </xs:sequence>
   296  *              &lt;/xs:complexType&gt;
   296  *              </xs:complexType>
   297  *          &lt;/xs:element&gt;
   297  *          </xs:element>
   298  *       &lt;/xs:schema&gt;
   298  *       </xs:schema>
   299  *
   299  *
   300  *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
   300  *       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
   301  *       Unmarshaller u = jc.createUnmarshaller();
   301  *       Unmarshaller u = jc.createUnmarshaller();
   302  *
   302  *
   303  *       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
   303  *       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
   306  *       Document doc = db.parse(new File( "nosferatu.xml"));
   306  *       Document doc = db.parse(new File( "nosferatu.xml"));
   307  *       Element  fooSubtree = ...; // traverse DOM till reach xml element foo, constrained by a
   307  *       Element  fooSubtree = ...; // traverse DOM till reach xml element foo, constrained by a
   308  *                                  // local element declaration in schema.
   308  *                                  // local element declaration in schema.
   309  *
   309  *
   310  *       // FooType is the JAXB mapping of the type of local element declaration foo.
   310  *       // FooType is the JAXB mapping of the type of local element declaration foo.
   311  *       JAXBElement&lt;FooType&gt; foo = u.unmarshal( fooSubtree, FooType.class);
   311  *       JAXBElement<FooType> foo = u.unmarshal( fooSubtree, FooType.class);
   312  *    </pre>
   312  *    }</pre>
   313  * </blockquote>
   313  * </blockquote>
   314  *
   314  *
   315  * <p>
   315  * <p>
   316  * <b>Support for SAX2.0 Compliant Parsers</b><br>
   316  * <b>Support for SAX2.0 Compliant Parsers</b><br>
   317  * <blockquote>
   317  * <blockquote>