1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/javax/xml/bind/annotation/XmlElements.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,177 @@ 1.4 +/* 1.5 + * Copyright (c) 2004, 2010, 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 static java.lang.annotation.RetentionPolicy.RUNTIME; 1.33 +import static java.lang.annotation.ElementType.FIELD; 1.34 +import static java.lang.annotation.ElementType.METHOD; 1.35 +import java.lang.annotation.Retention; 1.36 +import java.lang.annotation.Target; 1.37 + 1.38 +/** 1.39 + * <p> 1.40 + * A container for multiple @{@link XmlElement} annotations. 1.41 + * 1.42 + * Multiple annotations of the same type are not allowed on a program 1.43 + * element. This annotation therefore serves as a container annotation 1.44 + * for multiple @XmlElements as follows: 1.45 + * 1.46 + * <pre> 1.47 + * @XmlElements({ @XmlElement(...),@XmlElement(...) }) 1.48 + * </pre> 1.49 + * 1.50 + * <p>The <tt>@XmlElements</tt> annnotation can be used with the 1.51 + * following program elements: </p> 1.52 + * <ul> 1.53 + * <li> a JavaBean property </li> 1.54 + * <li> non static, non transient field </li> 1.55 + * </ul> 1.56 + * 1.57 + * This annotation is intended for annotation a JavaBean collection 1.58 + * property (e.g. List). 1.59 + * 1.60 + * <p><b>Usage</b></p> 1.61 + * 1.62 + * <p>The usage is subject to the following constraints: 1.63 + * <ul> 1.64 + * <li> This annotation can be used with the following 1.65 + * annotations: @{@link XmlIDREF}, @{@link XmlElementWrapper}. </li> 1.66 + * <li> If @XmlIDREF is also specified on the JavaBean property, 1.67 + * then each @XmlElement.type() must contain a JavaBean 1.68 + * property annotated with <tt>@XmlID</tt>.</li> 1.69 + * </ul> 1.70 + * 1.71 + * <p>See "Package Specification" in javax.xml.bind.package javadoc for 1.72 + * additional common information.</p> 1.73 + * 1.74 + * <hr> 1.75 + * 1.76 + * <p><b>Example 1:</b> Map to a list of elements</p> 1.77 + * <pre> 1.78 + * 1.79 + * // Mapped code fragment 1.80 + * public class Foo { 1.81 + * @XmlElements( 1.82 + * @XmlElement(name="A", type=Integer.class), 1.83 + * @XmlElement(name="B", type=Float.class) 1.84 + * } 1.85 + * public List items; 1.86 + * } 1.87 + * 1.88 + * <!-- XML Representation for a List of {1,2.5} 1.89 + * XML output is not wrapped using another element --> 1.90 + * ... 1.91 + * <A> 1 </A> 1.92 + * <B> 2.5 </B> 1.93 + * ... 1.94 + * 1.95 + * <!-- XML Schema fragment --> 1.96 + * <xs:complexType name="Foo"> 1.97 + * <xs:sequence> 1.98 + * <xs:choice minOccurs="0" maxOccurs="unbounded"> 1.99 + * <xs:element name="A" type="xs:int"/> 1.100 + * <xs:element name="B" type="xs:float"/> 1.101 + * <xs:choice> 1.102 + * </xs:sequence> 1.103 + * </xs:complexType> 1.104 + * 1.105 + * </pre> 1.106 + * 1.107 + * <p><b>Example 2:</b> Map to a list of elements wrapped with another element 1.108 + * </p> 1.109 + * <pre> 1.110 + * 1.111 + * // Mapped code fragment 1.112 + * public class Foo { 1.113 + * @XmlElementWrapper(name="bar") 1.114 + * @XmlElements( 1.115 + * @XmlElement(name="A", type=Integer.class), 1.116 + * @XmlElement(name="B", type=Float.class) 1.117 + * } 1.118 + * public List items; 1.119 + * } 1.120 + * 1.121 + * <!-- XML Schema fragment --> 1.122 + * <xs:complexType name="Foo"> 1.123 + * <xs:sequence> 1.124 + * <xs:element name="bar"> 1.125 + * <xs:complexType> 1.126 + * <xs:choice minOccurs="0" maxOccurs="unbounded"> 1.127 + * <xs:element name="A" type="xs:int"/> 1.128 + * <xs:element name="B" type="xs:float"/> 1.129 + * </xs:choice> 1.130 + * </xs:complexType> 1.131 + * </xs:element> 1.132 + * </xs:sequence> 1.133 + * </xs:complexType> 1.134 + * </pre> 1.135 + * 1.136 + * <p><b>Example 3:</b> Change element name based on type using an adapter. 1.137 + * </p> 1.138 + * <pre> 1.139 + * class Foo { 1.140 + * @XmlJavaTypeAdapter(QtoPAdapter.class) 1.141 + * @XmlElements({ 1.142 + * @XmlElement(name="A",type=PX.class), 1.143 + * @XmlElement(name="B",type=PY.class) 1.144 + * }) 1.145 + * Q bar; 1.146 + * } 1.147 + * 1.148 + * @XmlType abstract class P {...} 1.149 + * @XmlType(name="PX") class PX extends P {...} 1.150 + * @XmlType(name="PY") class PY extends P {...} 1.151 + * 1.152 + * <!-- XML Schema fragment --> 1.153 + * <xs:complexType name="Foo"> 1.154 + * <xs:sequence> 1.155 + * <xs:element name="bar"> 1.156 + * <xs:complexType> 1.157 + * <xs:choice minOccurs="0" maxOccurs="unbounded"> 1.158 + * <xs:element name="A" type="PX"/> 1.159 + * <xs:element name="B" type="PY"/> 1.160 + * </xs:choice> 1.161 + * </xs:complexType> 1.162 + * </xs:element> 1.163 + * </xs:sequence> 1.164 + * </xs:complexType> 1.165 + * </pre> 1.166 + * 1.167 + * @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul> 1.168 + * @see XmlElement 1.169 + * @see XmlElementRef 1.170 + * @see XmlElementRefs 1.171 + * @see XmlJavaTypeAdapter 1.172 + * @since JAXB2.0 1.173 + */ 1.174 +@Retention(RUNTIME) @Target({FIELD,METHOD}) 1.175 +public @interface XmlElements { 1.176 + /** 1.177 + * Collection of @{@link XmlElement} annotations 1.178 + */ 1.179 + XmlElement[] value(); 1.180 +}