src/share/jaxws_classes/javax/xml/bind/annotation/XmlRootElement.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/javax/xml/bind/annotation/XmlRootElement.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,182 @@
     1.4 +/*
     1.5 + * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package javax.xml.bind.annotation;
    1.30 +
    1.31 +import java.lang.annotation.Retention;
    1.32 +import java.lang.annotation.Target;
    1.33 +
    1.34 +import static java.lang.annotation.RetentionPolicy.RUNTIME;
    1.35 +import static java.lang.annotation.ElementType.TYPE;
    1.36 +
    1.37 +/**
    1.38 + * Maps a class or an enum type to an XML element.
    1.39 + *
    1.40 + * <p> <b>Usage</b> </p>
    1.41 + * <p>
    1.42 + * The &#64;XmlRootElement annotation can be used with the following program
    1.43 + * elements:
    1.44 + * <ul>
    1.45 + *   <li> a top level class </li>
    1.46 + *   <li> an enum type </li>
    1.47 + * </ul>
    1.48 + *
    1.49 + * <p>See "Package Specification" in javax.xml.bind.package javadoc for
    1.50 + * additional common information.</p>
    1.51 + *
    1.52 + * <p>
    1.53 + * When a top level class or an enum type is annotated with the
    1.54 + * &#64;XmlRootElement annotation, then its value is represented
    1.55 + * as XML element in an XML document.
    1.56 + *
    1.57 + * <p> This annotation can be used with the following annotations:
    1.58 + * {@link XmlType}, {@link XmlEnum}, {@link XmlAccessorType},
    1.59 + * {@link XmlAccessorOrder}.
    1.60 + * <p>
    1.61 +
    1.62 + * <p>
    1.63 + * <b>Example 1: </b> Associate an element with XML Schema type
    1.64 + * <pre>
    1.65 + *     // Example: Code fragment
    1.66 + *     &#64;XmlRootElement
    1.67 + *     class Point {
    1.68 + *        int x;
    1.69 + *        int y;
    1.70 + *        Point(int _x,int _y) {x=_x;y=_y;}
    1.71 + *     }
    1.72 + * </pre>
    1.73 + *
    1.74 + * <pre>
    1.75 + *     //Example: Code fragment corresponding to XML output
    1.76 + *     marshal( new Point(3,5), System.out);
    1.77 + * </pre>
    1.78 + *
    1.79 + * <pre>
    1.80 + *     &lt;!-- Example: XML output -->
    1.81 + *     &lt;point>
    1.82 + *       &lt;x> 3 </x>
    1.83 + *       &lt;y> 5 </y>
    1.84 + *     &lt;/point>
    1.85 + * </pre>
    1.86 + *
    1.87 + * The annotation causes an global element declaration to be produced
    1.88 + * in the schema. The global element declaration is associated with
    1.89 + * the XML schema type to which the class is mapped.
    1.90 + *
    1.91 + * <pre>
    1.92 + *     &lt;!-- Example: XML schema definition -->
    1.93 + *     &lt;xs:element name="point" type="point"/>
    1.94 + *     &lt;xs:complexType name="point">
    1.95 + *       &lt;xs:sequence>
    1.96 + *         &lt;xs:element name="x" type="xs:int"/>
    1.97 + *         &lt;xs:element name="y" type="xs:int"/>
    1.98 + *       &lt;/xs:sequence>
    1.99 + *     &lt;/xs:complexType>
   1.100 + * </pre>
   1.101 + *
   1.102 + * <p>
   1.103 + *
   1.104 + * <b>Example 2: Orthogonality to type inheritance </b>
   1.105 + *
   1.106 + * <p>
   1.107 + * An element declaration annotated on a type is not inherited by its
   1.108 + * derived types. The following example shows this.
   1.109 + * <pre>
   1.110 + *     // Example: Code fragment
   1.111 + *     &#64;XmlRootElement
   1.112 + *     class Point3D extends Point {
   1.113 + *         int z;
   1.114 + *         Point3D(int _x,int _y,int _z) {super(_x,_y);z=_z;}
   1.115 + *     }
   1.116 + *
   1.117 + *     //Example: Code fragment corresponding to XML output *
   1.118 + *     marshal( new Point3D(3,5,0), System.out );
   1.119 + *
   1.120 + *     &lt;!-- Example: XML output -->
   1.121 + *     &lt;!-- The element name is point3D not point -->
   1.122 + *     &lt;point3D>
   1.123 + *       &lt;x>3&lt;/x>
   1.124 + *       &lt;y>5&lt;/y>
   1.125 + *       &lt;z>0&lt;/z>
   1.126 + *     &lt;/point3D>
   1.127 + *
   1.128 + *     &lt;!-- Example: XML schema definition -->
   1.129 + *     &lt;xs:element name="point3D" type="point3D"/>
   1.130 + *     &lt;xs:complexType name="point3D">
   1.131 + *       &lt;xs:complexContent>
   1.132 + *         &lt;xs:extension base="point">
   1.133 + *           &lt;xs:sequence>
   1.134 + *             &lt;xs:element name="z" type="xs:int"/>
   1.135 + *           &lt;/xs:sequence>
   1.136 + *         &lt;/xs:extension>
   1.137 + *       &lt;/xs:complexContent>
   1.138 + *     &lt;/xs:complexType>
   1.139 + * </pre>
   1.140 + *
   1.141 + * <b>Example 3: </b> Associate a global element with XML Schema type
   1.142 + * to which the class is mapped.
   1.143 + * <pre>
   1.144 + *     //Example: Code fragment
   1.145 + *     &#64;XmlRootElement(name="PriceElement")
   1.146 + *     public class USPrice {
   1.147 + *         &#64;XmlElement
   1.148 + *         public java.math.BigDecimal price;
   1.149 + *     }
   1.150 + *
   1.151 + *     &lt;!-- Example: XML schema definition -->
   1.152 + *     &lt;xs:element name="PriceElement" type="USPrice"/>
   1.153 + *     &lt;xs:complexType name="USPrice">
   1.154 + *       &lt;xs:sequence>
   1.155 + *         &lt;xs:element name="price" type="xs:decimal"/>
   1.156 + *       &lt;/sequence>
   1.157 + *     &lt;/xs:complexType>
   1.158 + * </pre>
   1.159 + *
   1.160 + * @author Sekhar Vajjhala, Sun Microsystems, Inc.
   1.161 + * @since JAXB2.0
   1.162 + */
   1.163 +@Retention(RUNTIME)
   1.164 +@Target({TYPE})
   1.165 +public @interface XmlRootElement {
   1.166 +    /**
   1.167 +     * namespace name of the XML element.
   1.168 +     * <p>
   1.169 +     * If the value is "##default", then the XML namespace name is derived
   1.170 +     * from the package of the class ( {@link XmlSchema} ). If the
   1.171 +     * package is unnamed, then the XML namespace is the default empty
   1.172 +     * namespace.
   1.173 +     */
   1.174 +    String namespace() default "##default";
   1.175 +
   1.176 +    /**
   1.177 +     * local name of the XML element.
   1.178 +     * <p>
   1.179 +     * If the value is "##default", then the name is derived from the
   1.180 +     * class name.
   1.181 +     *
   1.182 +     */
   1.183 +    String name() default "##default";
   1.184 +
   1.185 +}

mercurial