1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/javax/xml/bind/annotation/XmlElement.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,210 @@ 1.4 +/* 1.5 + * Copyright (c) 2004, 2011, 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 javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 1.32 +import java.lang.annotation.Retention; 1.33 +import java.lang.annotation.Target; 1.34 + 1.35 +import static java.lang.annotation.ElementType.*; 1.36 +import static java.lang.annotation.ElementType.PARAMETER; 1.37 +import static java.lang.annotation.RetentionPolicy.*; 1.38 + 1.39 +/** 1.40 + * Maps a JavaBean property to a XML element derived from property name. 1.41 + * 1.42 + * <p> <b>Usage</b> </p> 1.43 + * <p> 1.44 + * <tt>@XmlElement</tt> annotation can be used with the following program 1.45 + * elements: 1.46 + * <ul> 1.47 + * <li> a JavaBean property </li> 1.48 + * <li> non static, non transient field </li> 1.49 + * <li> within {@link XmlElements} 1.50 + * <p> 1.51 + * 1.52 + * </ul> 1.53 + * 1.54 + * The usage is subject to the following constraints: 1.55 + * <ul> 1.56 + * <li> This annotation can be used with following annotations: 1.57 + * {@link XmlID}, 1.58 + * {@link XmlIDREF}, 1.59 + * {@link XmlList}, 1.60 + * {@link XmlSchemaType}, 1.61 + * {@link XmlValue}, 1.62 + * {@link XmlAttachmentRef}, 1.63 + * {@link XmlMimeType}, 1.64 + * {@link XmlInlineBinaryData}, 1.65 + * {@link XmlElementWrapper}, 1.66 + * {@link XmlJavaTypeAdapter}</li> 1.67 + * <li> if the type of JavaBean property is a collection type of 1.68 + * array, an indexed property, or a parameterized list, and 1.69 + * this annotation is used with {@link XmlElements} then, 1.70 + * <tt>@XmlElement.type()</tt> must be DEFAULT.class since the 1.71 + * collection item type is already known. </li> 1.72 + * </ul> 1.73 + * 1.74 + * <p> 1.75 + * A JavaBean property, when annotated with @XmlElement annotation 1.76 + * is mapped to a local element in the XML Schema complex type to 1.77 + * which the containing class is mapped. 1.78 + * 1.79 + * <p> 1.80 + * <b>Example 1: </b> Map a public non static non final field to local 1.81 + * element 1.82 + * <pre> 1.83 + * //Example: Code fragment 1.84 + * public class USPrice { 1.85 + * @XmlElement(name="itemprice") 1.86 + * public java.math.BigDecimal price; 1.87 + * } 1.88 + * 1.89 + * <!-- Example: Local XML Schema element --> 1.90 + * <xs:complexType name="USPrice"/> 1.91 + * <xs:sequence> 1.92 + * <xs:element name="itemprice" type="xs:decimal" minOccurs="0"/> 1.93 + * </sequence> 1.94 + * </xs:complexType> 1.95 + * </pre> 1.96 + * <p> 1.97 + * 1.98 + * <b> Example 2: </b> Map a field to a nillable element. 1.99 + * <pre> 1.100 + * 1.101 + * //Example: Code fragment 1.102 + * public class USPrice { 1.103 + * @XmlElement(nillable=true) 1.104 + * public java.math.BigDecimal price; 1.105 + * } 1.106 + * 1.107 + * <!-- Example: Local XML Schema element --> 1.108 + * <xs:complexType name="USPrice"> 1.109 + * <xs:sequence> 1.110 + * <xs:element name="price" type="xs:decimal" nillable="true" minOccurs="0"/> 1.111 + * </sequence> 1.112 + * </xs:complexType> 1.113 + * </pre> 1.114 + * <p> 1.115 + * <b> Example 3: </b> Map a field to a nillable, required element. 1.116 + * <pre> 1.117 + * 1.118 + * //Example: Code fragment 1.119 + * public class USPrice { 1.120 + * @XmlElement(nillable=true, required=true) 1.121 + * public java.math.BigDecimal price; 1.122 + * } 1.123 + * 1.124 + * <!-- Example: Local XML Schema element --> 1.125 + * <xs:complexType name="USPrice"> 1.126 + * <xs:sequence> 1.127 + * <xs:element name="price" type="xs:decimal" nillable="true" minOccurs="1"/> 1.128 + * </sequence> 1.129 + * </xs:complexType> 1.130 + * </pre> 1.131 + * <p> 1.132 + * 1.133 + * <p> <b>Example 4: </b>Map a JavaBean property to an XML element 1.134 + * with anonymous type.</p> 1.135 + * <p> 1.136 + * See Example 6 in @{@link XmlType}. 1.137 + * 1.138 + * <p> 1.139 + * @author Sekhar Vajjhala, Sun Microsystems, Inc. 1.140 + * @since JAXB2.0 1.141 + */ 1.142 + 1.143 +@Retention(RUNTIME) @Target({FIELD, METHOD, PARAMETER}) 1.144 +public @interface XmlElement { 1.145 + /** 1.146 + * Name of the XML Schema element. 1.147 + * <p> If the value is "##default", then element name is derived from the 1.148 + * JavaBean property name. 1.149 + */ 1.150 + String name() default "##default"; 1.151 + 1.152 + /** 1.153 + * Customize the element declaration to be nillable. 1.154 + * <p>If nillable() is true, then the JavaBean property is 1.155 + * mapped to a XML Schema nillable element declaration. 1.156 + */ 1.157 + boolean nillable() default false; 1.158 + 1.159 + /** 1.160 + * Customize the element declaration to be required. 1.161 + * <p>If required() is true, then Javabean property is mapped to 1.162 + * an XML schema element declaration with minOccurs="1". 1.163 + * maxOccurs is "1" for a single valued property and "unbounded" 1.164 + * for a multivalued property. 1.165 + * <p>If required() is false, then the Javabean property is mapped 1.166 + * to XML Schema element declaration with minOccurs="0". 1.167 + * maxOccurs is "1" for a single valued property and "unbounded" 1.168 + * for a multivalued property. 1.169 + */ 1.170 + 1.171 + boolean required() default false; 1.172 + 1.173 + /** 1.174 + * XML target namespace of the XML Schema element. 1.175 + * <p> 1.176 + * If the value is "##default", then the namespace is determined 1.177 + * as follows: 1.178 + * <ol> 1.179 + * <li> 1.180 + * If the enclosing package has {@link XmlSchema} annotation, 1.181 + * and its {@link XmlSchema#elementFormDefault() elementFormDefault} 1.182 + * is {@link XmlNsForm#QUALIFIED QUALIFIED}, then the namespace of 1.183 + * the enclosing class. 1.184 + * 1.185 + * <li> 1.186 + * Otherwise '' (which produces unqualified element in the default 1.187 + * namespace. 1.188 + * </ol> 1.189 + */ 1.190 + String namespace() default "##default"; 1.191 + 1.192 + /** 1.193 + * Default value of this element. 1.194 + * 1.195 + * <p> 1.196 + * The <pre>'\u0000'</pre> value specified as a default of this annotation element 1.197 + * is used as a poor-man's substitute for null to allow implementations 1.198 + * to recognize the 'no default value' state. 1.199 + */ 1.200 + String defaultValue() default "\u0000"; 1.201 + 1.202 + /** 1.203 + * The Java class being referenced. 1.204 + */ 1.205 + Class type() default DEFAULT.class; 1.206 + 1.207 + /** 1.208 + * Used in {@link XmlElement#type()} to 1.209 + * signal that the type be inferred from the signature 1.210 + * of the property. 1.211 + */ 1.212 + static final class DEFAULT {} 1.213 +}