jaxws/src/java.xml.bind/share/classes/javax/xml/bind/JAXB.java
changeset 32795 5a5710ee05a0
parent 25871 b80b84e87032
equal deleted inserted replaced
32712:f61a63b7d1e5 32795:5a5710ee05a0
    66  *      people who prefer the checked exception would use
    66  *      people who prefer the checked exception would use
    67  *      the rest of the JAXB API directly.
    67  *      the rest of the JAXB API directly.
    68  * </ol>
    68  * </ol>
    69  *
    69  *
    70  * <p>
    70  * <p>
    71  * In addition, the <tt>unmarshal</tt> methods have the following characteristic:
    71  * In addition, the {@code unmarshal} methods have the following characteristic:
    72  *
    72  *
    73  * <ol>
    73  * <ol>
    74  *  <li>Schema validation is not performed on the input XML.
    74  *  <li>Schema validation is not performed on the input XML.
    75  *      The processing will try to continue even if there
    75  *      The processing will try to continue even if there
    76  *      are errors in the XML, as much as possible. Only as
    76  *      are errors in the XML, as much as possible. Only as
    77  *      the last resort, this method fails with {@link DataBindingException}.
    77  *      the last resort, this method fails with {@link DataBindingException}.
    78  * </ol>
    78  * </ol>
    79  *
    79  *
    80  * <p>
    80  * <p>
    81  * Similarly, the <tt>marshal</tt> methods have the following characteristic:
    81  * Similarly, the {@code marshal} methods have the following characteristic:
    82  * <ol>
    82  * <ol>
    83  *  <li>The processing will try to continue even if the Java object tree
    83  *  <li>The processing will try to continue even if the Java object tree
    84  *      does not meet the validity requirement. Only as
    84  *      does not meet the validity requirement. Only as
    85  *      the last resort, this method fails with {@link DataBindingException}.
    85  *      the last resort, this method fails with {@link DataBindingException}.
    86  * </ol>
    86  * </ol>
    87  *
    87  *
    88  *
    88  *
    89  * <p>
    89  * <p>
    90  * All the methods on this class require non-null arguments to all parameters.
    90  * All the methods on this class require non-null arguments to all parameters.
    91  * The <tt>unmarshal</tt> methods either fail with an exception or return
    91  * The {@code unmarshal} methods either fail with an exception or return
    92  * a non-null value.
    92  * a non-null value.
    93  *
    93  *
    94  * @author Kohsuke Kawaguchi
    94  * @author Kohsuke Kawaguchi
    95  * @since 1.6, JAXB 2.1
    95  * @since 1.6, JAXB 2.1
    96  */
    96  */
   177     /**
   177     /**
   178      * Reads in a Java object tree from the given XML input.
   178      * Reads in a Java object tree from the given XML input.
   179      *
   179      *
   180      * @param xml
   180      * @param xml
   181      *      The URI is {@link URI#toURL() turned into URL} and then
   181      *      The URI is {@link URI#toURL() turned into URL} and then
   182      *      follows the handling of <tt>URL</tt>.
   182      *      follows the handling of {@code URL}.
   183      */
   183      */
   184     public static <T> T unmarshal( URI xml, Class<T> type ) {
   184     public static <T> T unmarshal( URI xml, Class<T> type ) {
   185         try {
   185         try {
   186             JAXBElement<T> item = getContext(type).createUnmarshaller().unmarshal(toSource(xml), type);
   186             JAXBElement<T> item = getContext(type).createUnmarshaller().unmarshal(toSource(xml), type);
   187             return item.getValue();
   187             return item.getValue();
   194 
   194 
   195     /**
   195     /**
   196      * Reads in a Java object tree from the given XML input.
   196      * Reads in a Java object tree from the given XML input.
   197      *
   197      *
   198      * @param xml
   198      * @param xml
   199      *      The string is first interpreted as an absolute <tt>URI</tt>.
   199      *      The string is first interpreted as an absolute {@code URI}.
   200      *      If it's not {@link URI#isAbsolute() a valid absolute URI},
   200      *      If it's not {@link URI#isAbsolute() a valid absolute URI},
   201      *      then it's interpreted as a <tt>File</tt>
   201      *      then it's interpreted as a {@code File}
   202      */
   202      */
   203     public static <T> T unmarshal( String xml, Class<T> type ) {
   203     public static <T> T unmarshal( String xml, Class<T> type ) {
   204         try {
   204         try {
   205             JAXBElement<T> item = getContext(type).createUnmarshaller().unmarshal(toSource(xml), type);
   205             JAXBElement<T> item = getContext(type).createUnmarshaller().unmarshal(toSource(xml), type);
   206             return item.getValue();
   206             return item.getValue();
   345      *      {@link Class#getSimpleName() the short class name}.
   345      *      {@link Class#getSimpleName() the short class name}.
   346      *      This parameter must not be null.
   346      *      This parameter must not be null.
   347      *
   347      *
   348      * @param xml
   348      * @param xml
   349      *      The XML will be {@link URLConnection#getOutputStream() sent} to the
   349      *      The XML will be {@link URLConnection#getOutputStream() sent} to the
   350      *      resource pointed by this URL. Note that not all <tt>URL</tt>s support
   350      *      resource pointed by this URL. Note that not all {@code URL}s support
   351      *      such operation, and exact semantics depends on the <tt>URL</tt>
   351      *      such operation, and exact semantics depends on the {@code URL}
   352      *      implementations. In case of {@link HttpURLConnection HTTP URLs},
   352      *      implementations. In case of {@link HttpURLConnection HTTP URLs},
   353      *      this will perform HTTP POST.
   353      *      this will perform HTTP POST.
   354      *
   354      *
   355      * @throws DataBindingException
   355      * @throws DataBindingException
   356      *      If the operation fails, such as due to I/O error, unbindable classes.
   356      *      If the operation fails, such as due to I/O error, unbindable classes.
   372      *      {@link Class#getSimpleName() the short class name}.
   372      *      {@link Class#getSimpleName() the short class name}.
   373      *      This parameter must not be null.
   373      *      This parameter must not be null.
   374      *
   374      *
   375      * @param xml
   375      * @param xml
   376      *      The URI is {@link URI#toURL() turned into URL} and then
   376      *      The URI is {@link URI#toURL() turned into URL} and then
   377      *      follows the handling of <tt>URL</tt>. See above.
   377      *      follows the handling of {@code URL}. See above.
   378      *
   378      *
   379      * @throws DataBindingException
   379      * @throws DataBindingException
   380      *      If the operation fails, such as due to I/O error, unbindable classes.
   380      *      If the operation fails, such as due to I/O error, unbindable classes.
   381      */
   381      */
   382     public static void marshal( Object jaxbObject, URI xml ) {
   382     public static void marshal( Object jaxbObject, URI xml ) {
   395      *      the root tag name is {@link Introspector#decapitalize(String) infered} from
   395      *      the root tag name is {@link Introspector#decapitalize(String) infered} from
   396      *      {@link Class#getSimpleName() the short class name}.
   396      *      {@link Class#getSimpleName() the short class name}.
   397      *      This parameter must not be null.
   397      *      This parameter must not be null.
   398      *
   398      *
   399      * @param xml
   399      * @param xml
   400      *      The string is first interpreted as an absolute <tt>URI</tt>.
   400      *      The string is first interpreted as an absolute {@code URI}.
   401      *      If it's not {@link URI#isAbsolute() a valid absolute URI},
   401      *      If it's not {@link URI#isAbsolute() a valid absolute URI},
   402      *      then it's interpreted as a <tt>File</tt>
   402      *      then it's interpreted as a {@code File}
   403      *
   403      *
   404      * @throws DataBindingException
   404      * @throws DataBindingException
   405      *      If the operation fails, such as due to I/O error, unbindable classes.
   405      *      If the operation fails, such as due to I/O error, unbindable classes.
   406      */
   406      */
   407     public static void marshal( Object jaxbObject, String xml ) {
   407     public static void marshal( Object jaxbObject, String xml ) {
   520      *          <td>XML will be written to this file. If it already exists,
   520      *          <td>XML will be written to this file. If it already exists,
   521      *              it will be overwritten.</td>
   521      *              it will be overwritten.</td>
   522      *      </tr><tr>
   522      *      </tr><tr>
   523      *          <td>{@link URL}</td>
   523      *          <td>{@link URL}</td>
   524      *          <td>The XML will be {@link URLConnection#getOutputStream() sent} to the
   524      *          <td>The XML will be {@link URLConnection#getOutputStream() sent} to the
   525      *              resource pointed by this URL. Note that not all <tt>URL</tt>s support
   525      *              resource pointed by this URL. Note that not all {@code URL}s support
   526      *              such operation, and exact semantics depends on the <tt>URL</tt>
   526      *              such operation, and exact semantics depends on the {@code URL}
   527      *              implementations. In case of {@link HttpURLConnection HTTP URLs},
   527      *              implementations. In case of {@link HttpURLConnection HTTP URLs},
   528      *              this will perform HTTP POST.</td>
   528      *              this will perform HTTP POST.</td>
   529      *      </tr><tr>
   529      *      </tr><tr>
   530      *          <td>{@link URI}</td>
   530      *          <td>{@link URI}</td>
   531      *          <td>The URI is {@link URI#toURL() turned into URL} and then
   531      *          <td>The URI is {@link URI#toURL() turned into URL} and then
   532      *              follows the handling of <tt>URL</tt>. See above.</td>
   532      *              follows the handling of {@code URL}. See above.</td>
   533      *      </tr><tr>
   533      *      </tr><tr>
   534      *          <td>{@link String}</td>
   534      *          <td>{@link String}</td>
   535      *          <td>The string is first interpreted as an absolute <tt>URI</tt>.
   535      *          <td>The string is first interpreted as an absolute {@code URI}.
   536      *              If it's not {@link URI#isAbsolute() a valid absolute URI},
   536      *              If it's not {@link URI#isAbsolute() a valid absolute URI},
   537      *              then it's interpreted as a <tt>File</tt></td>
   537      *              then it's interpreted as a {@code File}</td>
   538      *      </tr><tr>
   538      *      </tr><tr>
   539      *          <td>{@link OutputStream}</td>
   539      *          <td>{@link OutputStream}</td>
   540      *          <td>The XML will be sent to the given {@link OutputStream}.
   540      *          <td>The XML will be sent to the given {@link OutputStream}.
   541      *              Upon a successful completion, the stream will be closed by this method.</td>
   541      *              Upon a successful completion, the stream will be closed by this method.</td>
   542      *      </tr><tr>
   542      *      </tr><tr>