1 /*2 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.3 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.4 */5 6 package javax.xml.bind.annotation;7 8 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;9 import static java.lang.annotation.RetentionPolicy.RUNTIME ;10 import static java.lang.annotation.ElementType.FIELD ;11 import static java.lang.annotation.ElementType.METHOD ;12 import java.lang.annotation.Retention ;13 import java.lang.annotation.Target ;14 15 /**16 * <p>17 * A container for multiple @{@link XmlElement} annotations.18 *19 * Multiple annotations of the same type are not allowed on a program20 * element. This annotation therefore serves as a container annotation21 * for multiple @XmlElements as follows:22 *23 * <pre>24 * @XmlElements({ @XmlElement(...),@XmlElement(...) })25 * </pre>26 *27 * <p>The <tt>@XmlElements</tt> annnotation can be used with the28 * following program elements: </p>29 * <ul>30 * <li> a JavaBean property </li>31 * <li> non static, non transient field </li>32 * </ul>33 *34 * This annotation is intended for annotation a JavaBean collection35 * property (e.g. List). 36 *37 * <p><b>Usage</b></p>38 *39 * <p>The usage is subject to the following constraints:40 * <ul>41 * <li> This annotation can be used with the following42 * annotations: @{@link XmlIDREF}, @{@link XmlElementWrapper}. </li>43 * <li> If @XmlIDREF is also specified on the JavaBean property,44 * then each @XmlElement.type() must contain a JavaBean45 * property annotated with <tt>@XmlID</tt>.</li>46 * </ul>47 *48 * <p>See "Package Specification" in javax.xml.bind.package javadoc for49 * additional common information.</p>50 *51 * <hr>52 * 53 * <p><b>Example 1:</b> Map to a list of elements</p>54 * <pre>55 * 56 * // Mapped code fragment57 * public class Foo {58 * @XmlElements(59 * @XmlElement(name="A", type=Integer.class),60 * @XmlElement(name="B", type=Float.class)61 * }62 * public List items;63 * }64 *65 * <!-- XML Representation for a List of {1,2.5} 66 * XML output is not wrapped using another element -->67 * ...68 * <A> 1 </A>69 * <B> 2.5 </B>70 * ...71 *72 * <!-- XML Schema fragment -->73 * <xs:complexType name="Foo">74 * <xs:sequence>75 * <xs:choice minOccurs="0" maxOccurs="unbounded">76 * <xs:element name="A" type="xs:int"/>77 * <xs:element name="B" type="xs:float"/>78 * <xs:choice>79 * </xs:sequence>80 * </xs:complexType>81 *82 * </pre>83 *84 * <p><b>Example 2:</b> Map to a list of elements wrapped with another element85 * </p>86 * <pre>87 * 88 * // Mapped code fragment89 * public class Foo {90 * @XmlElementWrapper(name="bar")91 * @XmlElements(92 * @XmlElement(name="A", type=Integer.class),93 * @XmlElement(name="B", type=Float.class)94 * }95 * public List items;96 * }97 *98 * <!-- XML Schema fragment -->99 * <xs:complexType name="Foo">100 * <xs:sequence>101 * <xs:element name="bar">102 * <xs:complexType>103 * <xs:choice minOccurs="0" maxOccurs="unbounded">104 * <xs:element name="A" type="xs:int"/>105 * <xs:element name="B" type="xs:float"/>106 * </xs:choice>107 * </xs:complexType>108 * </xs:element>109 * </xs:sequence>110 * </xs:complexType>111 * </pre>112 *113 * <p><b>Example 3:</b> Change element name based on type using an adapter. 114 * </p>115 * <pre>116 * class Foo {117 * @XmlJavaTypeAdapter(QtoPAdapter.class)118 * @XmlElements({119 * @XmlElement(name="A",type=PX.class),120 * @XmlElement(name="B",type=PY.class)121 * })122 * Q bar;123 * }124 * 125 * @XmlType abstract class P {...}126 * @XmlType(name="PX") class PX extends P {...}127 * @XmlType(name="PY") class PY extends P {...}128 *129 * <!-- XML Schema fragment -->130 * <xs:complexType name="Foo">131 * <xs:sequence>132 * <xs:element name="bar">133 * <xs:complexType>134 * <xs:choice minOccurs="0" maxOccurs="unbounded">135 * <xs:element name="A" type="PX"/>136 * <xs:element name="B" type="PY"/>137 * </xs:choice>138 * </xs:complexType>139 * </xs:element>140 * </xs:sequence>141 * </xs:complexType>142 * </pre>143 * 144 * @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul>145 * @see XmlElement 146 * @see XmlElementRef147 * @see XmlElementRefs148 * @see XmlJavaTypeAdapter149 * @since JAXB2.0150 */151 @Retention (RUNTIME) @Target ({FIELD,METHOD})152 public @interface XmlElements {153 /**154 * Collection of @{@link XmlElement} annotations155 */156 XmlElement[] value();157 }158