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

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 397
b99d7e355d4b
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package javax.xml.bind.annotation;
aoqi@0 27
aoqi@0 28 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
aoqi@0 29 import java.lang.annotation.Retention;
aoqi@0 30 import java.lang.annotation.Target;
aoqi@0 31
aoqi@0 32 import static java.lang.annotation.ElementType.*;
aoqi@0 33 import static java.lang.annotation.ElementType.PARAMETER;
aoqi@0 34 import static java.lang.annotation.RetentionPolicy.*;
aoqi@0 35
aoqi@0 36 /**
aoqi@0 37 * Maps a JavaBean property to a XML element derived from property name.
aoqi@0 38 *
aoqi@0 39 * <p> <b>Usage</b> </p>
aoqi@0 40 * <p>
aoqi@0 41 * <tt>@XmlElement</tt> annotation can be used with the following program
aoqi@0 42 * elements:
aoqi@0 43 * <ul>
aoqi@0 44 * <li> a JavaBean property </li>
aoqi@0 45 * <li> non static, non transient field </li>
aoqi@0 46 * <li> within {@link XmlElements}
aoqi@0 47 * <p>
aoqi@0 48 *
aoqi@0 49 * </ul>
aoqi@0 50 *
aoqi@0 51 * The usage is subject to the following constraints:
aoqi@0 52 * <ul>
aoqi@0 53 * <li> This annotation can be used with following annotations:
aoqi@0 54 * {@link XmlID},
aoqi@0 55 * {@link XmlIDREF},
aoqi@0 56 * {@link XmlList},
aoqi@0 57 * {@link XmlSchemaType},
aoqi@0 58 * {@link XmlValue},
aoqi@0 59 * {@link XmlAttachmentRef},
aoqi@0 60 * {@link XmlMimeType},
aoqi@0 61 * {@link XmlInlineBinaryData},
aoqi@0 62 * {@link XmlElementWrapper},
aoqi@0 63 * {@link XmlJavaTypeAdapter}</li>
aoqi@0 64 * <li> if the type of JavaBean property is a collection type of
aoqi@0 65 * array, an indexed property, or a parameterized list, and
aoqi@0 66 * this annotation is used with {@link XmlElements} then,
aoqi@0 67 * <tt>@XmlElement.type()</tt> must be DEFAULT.class since the
aoqi@0 68 * collection item type is already known. </li>
aoqi@0 69 * </ul>
aoqi@0 70 *
aoqi@0 71 * <p>
aoqi@0 72 * A JavaBean property, when annotated with @XmlElement annotation
aoqi@0 73 * is mapped to a local element in the XML Schema complex type to
aoqi@0 74 * which the containing class is mapped.
aoqi@0 75 *
aoqi@0 76 * <p>
aoqi@0 77 * <b>Example 1: </b> Map a public non static non final field to local
aoqi@0 78 * element
aoqi@0 79 * <pre>
aoqi@0 80 * //Example: Code fragment
aoqi@0 81 * public class USPrice {
aoqi@0 82 * &#64;XmlElement(name="itemprice")
aoqi@0 83 * public java.math.BigDecimal price;
aoqi@0 84 * }
aoqi@0 85 *
aoqi@0 86 * &lt;!-- Example: Local XML Schema element -->
aoqi@0 87 * &lt;xs:complexType name="USPrice"/>
aoqi@0 88 * &lt;xs:sequence>
aoqi@0 89 * &lt;xs:element name="itemprice" type="xs:decimal" minOccurs="0"/>
aoqi@0 90 * &lt;/sequence>
aoqi@0 91 * &lt;/xs:complexType>
aoqi@0 92 * </pre>
aoqi@0 93 * <p>
aoqi@0 94 *
aoqi@0 95 * <b> Example 2: </b> Map a field to a nillable element.
aoqi@0 96 * <pre>
aoqi@0 97 *
aoqi@0 98 * //Example: Code fragment
aoqi@0 99 * public class USPrice {
aoqi@0 100 * &#64;XmlElement(nillable=true)
aoqi@0 101 * public java.math.BigDecimal price;
aoqi@0 102 * }
aoqi@0 103 *
aoqi@0 104 * &lt;!-- Example: Local XML Schema element -->
aoqi@0 105 * &lt;xs:complexType name="USPrice">
aoqi@0 106 * &lt;xs:sequence>
aoqi@0 107 * &lt;xs:element name="price" type="xs:decimal" nillable="true" minOccurs="0"/>
aoqi@0 108 * &lt;/sequence>
aoqi@0 109 * &lt;/xs:complexType>
aoqi@0 110 * </pre>
aoqi@0 111 * <p>
aoqi@0 112 * <b> Example 3: </b> Map a field to a nillable, required element.
aoqi@0 113 * <pre>
aoqi@0 114 *
aoqi@0 115 * //Example: Code fragment
aoqi@0 116 * public class USPrice {
aoqi@0 117 * &#64;XmlElement(nillable=true, required=true)
aoqi@0 118 * public java.math.BigDecimal price;
aoqi@0 119 * }
aoqi@0 120 *
aoqi@0 121 * &lt;!-- Example: Local XML Schema element -->
aoqi@0 122 * &lt;xs:complexType name="USPrice">
aoqi@0 123 * &lt;xs:sequence>
aoqi@0 124 * &lt;xs:element name="price" type="xs:decimal" nillable="true" minOccurs="1"/>
aoqi@0 125 * &lt;/sequence>
aoqi@0 126 * &lt;/xs:complexType>
aoqi@0 127 * </pre>
aoqi@0 128 * <p>
aoqi@0 129 *
aoqi@0 130 * <p> <b>Example 4: </b>Map a JavaBean property to an XML element
aoqi@0 131 * with anonymous type.</p>
aoqi@0 132 * <p>
aoqi@0 133 * See Example 6 in @{@link XmlType}.
aoqi@0 134 *
aoqi@0 135 * <p>
aoqi@0 136 * @author Sekhar Vajjhala, Sun Microsystems, Inc.
aoqi@0 137 * @since JAXB2.0
aoqi@0 138 */
aoqi@0 139
aoqi@0 140 @Retention(RUNTIME) @Target({FIELD, METHOD, PARAMETER})
aoqi@0 141 public @interface XmlElement {
aoqi@0 142 /**
aoqi@0 143 * Name of the XML Schema element.
aoqi@0 144 * <p> If the value is "##default", then element name is derived from the
aoqi@0 145 * JavaBean property name.
aoqi@0 146 */
aoqi@0 147 String name() default "##default";
aoqi@0 148
aoqi@0 149 /**
aoqi@0 150 * Customize the element declaration to be nillable.
aoqi@0 151 * <p>If nillable() is true, then the JavaBean property is
aoqi@0 152 * mapped to a XML Schema nillable element declaration.
aoqi@0 153 */
aoqi@0 154 boolean nillable() default false;
aoqi@0 155
aoqi@0 156 /**
aoqi@0 157 * Customize the element declaration to be required.
aoqi@0 158 * <p>If required() is true, then Javabean property is mapped to
aoqi@0 159 * an XML schema element declaration with minOccurs="1".
aoqi@0 160 * maxOccurs is "1" for a single valued property and "unbounded"
aoqi@0 161 * for a multivalued property.
aoqi@0 162 * <p>If required() is false, then the Javabean property is mapped
aoqi@0 163 * to XML Schema element declaration with minOccurs="0".
aoqi@0 164 * maxOccurs is "1" for a single valued property and "unbounded"
aoqi@0 165 * for a multivalued property.
aoqi@0 166 */
aoqi@0 167
aoqi@0 168 boolean required() default false;
aoqi@0 169
aoqi@0 170 /**
aoqi@0 171 * XML target namespace of the XML Schema element.
aoqi@0 172 * <p>
aoqi@0 173 * If the value is "##default", then the namespace is determined
aoqi@0 174 * as follows:
aoqi@0 175 * <ol>
aoqi@0 176 * <li>
aoqi@0 177 * If the enclosing package has {@link XmlSchema} annotation,
aoqi@0 178 * and its {@link XmlSchema#elementFormDefault() elementFormDefault}
aoqi@0 179 * is {@link XmlNsForm#QUALIFIED QUALIFIED}, then the namespace of
aoqi@0 180 * the enclosing class.
aoqi@0 181 *
aoqi@0 182 * <li>
aoqi@0 183 * Otherwise &#39;&#39; (which produces unqualified element in the default
aoqi@0 184 * namespace.
aoqi@0 185 * </ol>
aoqi@0 186 */
aoqi@0 187 String namespace() default "##default";
aoqi@0 188
aoqi@0 189 /**
aoqi@0 190 * Default value of this element.
aoqi@0 191 *
aoqi@0 192 * <p>
aoqi@0 193 * The <pre>'\u0000'</pre> value specified as a default of this annotation element
aoqi@0 194 * is used as a poor-man's substitute for null to allow implementations
aoqi@0 195 * to recognize the 'no default value' state.
aoqi@0 196 */
aoqi@0 197 String defaultValue() default "\u0000";
aoqi@0 198
aoqi@0 199 /**
aoqi@0 200 * The Java class being referenced.
aoqi@0 201 */
aoqi@0 202 Class type() default DEFAULT.class;
aoqi@0 203
aoqi@0 204 /**
aoqi@0 205 * Used in {@link XmlElement#type()} to
aoqi@0 206 * signal that the type be inferred from the signature
aoqi@0 207 * of the property.
aoqi@0 208 */
aoqi@0 209 static final class DEFAULT {}
aoqi@0 210 }

mercurial