Tue, 06 Mar 2012 16:09:35 -0800
7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom
ohair@286 | 1 | /* |
ohair@286 | 2 | * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package javax.xml.bind.annotation; |
ohair@286 | 27 | |
ohair@286 | 28 | import java.lang.annotation.Target; |
ohair@286 | 29 | import java.lang.annotation.Retention; |
ohair@286 | 30 | import static java.lang.annotation.ElementType.*; |
ohair@286 | 31 | import static java.lang.annotation.RetentionPolicy.*; |
ohair@286 | 32 | |
ohair@286 | 33 | /** |
ohair@286 | 34 | * <p> |
ohair@286 | 35 | * Maps a JavaBean property to XML IDREF. |
ohair@286 | 36 | * |
ohair@286 | 37 | * <p> |
ohair@286 | 38 | * To preserve referential integrity of an object graph across XML |
ohair@286 | 39 | * serialization followed by a XML deserialization, requires an object |
ohair@286 | 40 | * reference to be marshalled by reference or containment |
ohair@286 | 41 | * appropriately. Annotations <tt>@XmlID</tt> and <tt>@XmlIDREF</tt> |
ohair@286 | 42 | * together allow a customized mapping of a JavaBean property's |
ohair@286 | 43 | * type by containment or reference. |
ohair@286 | 44 | * |
ohair@286 | 45 | * <p><b>Usage</b> </p> |
ohair@286 | 46 | * The <tt>@XmlIDREF</tt> annotation can be used with the following |
ohair@286 | 47 | * program elements: |
ohair@286 | 48 | * <ul> |
ohair@286 | 49 | * <li> a JavaBean property </li> |
ohair@286 | 50 | * <li> non static, non transient field </li> |
ohair@286 | 51 | * </ul> |
ohair@286 | 52 | * |
ohair@286 | 53 | * <p>See "Package Specification" in javax.xml.bind.package javadoc for |
ohair@286 | 54 | * additional common information.</p> |
ohair@286 | 55 | * |
ohair@286 | 56 | * <p> The usage is subject to the following constraints: |
ohair@286 | 57 | * <ul> |
ohair@286 | 58 | * |
ohair@286 | 59 | * <li> If the type of the field or property is a collection type, |
ohair@286 | 60 | * then the collection item type must contain a property or |
ohair@286 | 61 | * field annotated with <tt>@XmlID</tt>. </li> |
ohair@286 | 62 | * <li> If the field or property is single valued, then the type of |
ohair@286 | 63 | * the property or field must contain a property or field |
ohair@286 | 64 | * annotated with <tt>@XmlID</tt>. |
ohair@286 | 65 | * <p>Note: If the collection item type or the type of the |
ohair@286 | 66 | * property (for non collection type) is java.lang.Object, then |
ohair@286 | 67 | * the instance must contain a property/field annotated with |
ohair@286 | 68 | * <tt>@XmlID</tt> attribute. |
ohair@286 | 69 | * </li> |
ohair@286 | 70 | * <li> This annotation can be used with the following annotations: |
ohair@286 | 71 | * {@link XmlElement}, {@link XmlAttribute}, {@link XmlList}, |
ohair@286 | 72 | * and {@link XmlElements}.</li> |
ohair@286 | 73 | * |
ohair@286 | 74 | * </ul> |
ohair@286 | 75 | * <p><b>Example:</b> Map a JavaBean property to <tt>xs:IDREF</tt> |
ohair@286 | 76 | * (i.e. by reference rather than by containment)</p> |
ohair@286 | 77 | * <pre> |
ohair@286 | 78 | * |
ohair@286 | 79 | * //EXAMPLE: Code fragment |
ohair@286 | 80 | * public class Shipping { |
ohair@286 | 81 | * @XmlIDREF public Customer getCustomer(); |
ohair@286 | 82 | * public void setCustomer(Customer customer); |
ohair@286 | 83 | * .... |
ohair@286 | 84 | * } |
ohair@286 | 85 | * |
ohair@286 | 86 | * <!-- Example: XML Schema fragment --> |
ohair@286 | 87 | * <xs:complexType name="Shipping"> |
ohair@286 | 88 | * <xs:complexContent> |
ohair@286 | 89 | * <xs:sequence> |
ohair@286 | 90 | * <xs:element name="customer" type="xs:IDREF"/> |
ohair@286 | 91 | * .... |
ohair@286 | 92 | * </xs:sequence> |
ohair@286 | 93 | * </xs:complexContent> |
ohair@286 | 94 | * </xs:complexType> |
ohair@286 | 95 | * |
ohair@286 | 96 | * </pre> |
ohair@286 | 97 | * |
ohair@286 | 98 | * |
ohair@286 | 99 | * <p><b>Example 2: </b> The following is a complete example of |
ohair@286 | 100 | * containment versus reference. |
ohair@286 | 101 | * |
ohair@286 | 102 | * <pre> |
ohair@286 | 103 | * // By default, Customer maps to complex type <tt>xs:Customer</tt> |
ohair@286 | 104 | * public class Customer { |
ohair@286 | 105 | * |
ohair@286 | 106 | * // map JavaBean property type to <tt>xs:ID</tt> |
ohair@286 | 107 | * @XmlID public String getCustomerID(); |
ohair@286 | 108 | * public void setCustomerID(String id); |
ohair@286 | 109 | * |
ohair@286 | 110 | * // .... other properties not shown |
ohair@286 | 111 | * } |
ohair@286 | 112 | * |
ohair@286 | 113 | * |
ohair@286 | 114 | * // By default, Invoice maps to a complex type <tt>xs:Invoice</tt> |
ohair@286 | 115 | * public class Invoice { |
ohair@286 | 116 | * |
ohair@286 | 117 | * // map by reference |
ohair@286 | 118 | * @XmlIDREF public Customer getCustomer(); |
ohair@286 | 119 | * public void setCustomer(Customer customer); |
ohair@286 | 120 | * |
ohair@286 | 121 | * // .... other properties not shown here |
ohair@286 | 122 | * } |
ohair@286 | 123 | * |
ohair@286 | 124 | * // By default, Shipping maps to complex type <tt>xs:Shipping</tt> |
ohair@286 | 125 | * public class Shipping { |
ohair@286 | 126 | * |
ohair@286 | 127 | * // map by reference |
ohair@286 | 128 | * @XmlIDREF public Customer getCustomer(); |
ohair@286 | 129 | * public void setCustomer(Customer customer); |
ohair@286 | 130 | * } |
ohair@286 | 131 | * |
ohair@286 | 132 | * // at least one class must reference Customer by containment; |
ohair@286 | 133 | * // Customer instances won't be marshalled. |
ohair@286 | 134 | * @XmlElement(name="CustomerData") |
ohair@286 | 135 | * public class CustomerData { |
ohair@286 | 136 | * // map reference to Customer by containment by default. |
ohair@286 | 137 | * public Customer getCustomer(); |
ohair@286 | 138 | * |
ohair@286 | 139 | * // maps reference to Shipping by containment by default. |
ohair@286 | 140 | * public Shipping getShipping(); |
ohair@286 | 141 | * |
ohair@286 | 142 | * // maps reference to Invoice by containment by default. |
ohair@286 | 143 | * public Invoice getInvoice(); |
ohair@286 | 144 | * } |
ohair@286 | 145 | * |
ohair@286 | 146 | * <!-- XML Schema mapping for above code frament --> |
ohair@286 | 147 | * |
ohair@286 | 148 | * <xs:complexType name="Invoice"> |
ohair@286 | 149 | * <xs:complexContent> |
ohair@286 | 150 | * <xs:sequence> |
ohair@286 | 151 | * <xs:element name="customer" type="xs:IDREF"/> |
ohair@286 | 152 | * .... |
ohair@286 | 153 | * </xs:sequence> |
ohair@286 | 154 | * </xs:complexContent> |
ohair@286 | 155 | * </xs:complexType> |
ohair@286 | 156 | * |
ohair@286 | 157 | * <xs:complexType name="Shipping"> |
ohair@286 | 158 | * <xs:complexContent> |
ohair@286 | 159 | * <xs:sequence> |
ohair@286 | 160 | * <xs:element name="customer" type="xs:IDREF"/> |
ohair@286 | 161 | * .... |
ohair@286 | 162 | * </xs:sequence> |
ohair@286 | 163 | * </xs:complexContent> |
ohair@286 | 164 | * </xs:complexType> |
ohair@286 | 165 | * |
ohair@286 | 166 | * <xs:complexType name="Customer"> |
ohair@286 | 167 | * <xs:complexContent> |
ohair@286 | 168 | * <xs:sequence> |
ohair@286 | 169 | * .... |
ohair@286 | 170 | * </xs:sequence> |
ohair@286 | 171 | * <xs:attribute name="CustomerID" type="xs:ID"/> |
ohair@286 | 172 | * </xs:complexContent> |
ohair@286 | 173 | * </xs:complexType> |
ohair@286 | 174 | * |
ohair@286 | 175 | * <xs:complexType name="CustomerData"> |
ohair@286 | 176 | * <xs:complexContent> |
ohair@286 | 177 | * <xs:sequence> |
ohair@286 | 178 | * <xs:element name="customer" type="xs:Customer"/> |
ohair@286 | 179 | * <xs:element name="shipping" type="xs:Shipping"/> |
ohair@286 | 180 | * <xs:element name="invoice" type="xs:Invoice"/> |
ohair@286 | 181 | * </xs:sequence> |
ohair@286 | 182 | * </xs:complexContent> |
ohair@286 | 183 | * </xs:complexType> |
ohair@286 | 184 | * |
ohair@286 | 185 | * <xs:element name"customerData" type="xs:CustomerData"/> |
ohair@286 | 186 | * |
ohair@286 | 187 | * <!-- Instance document conforming to the above XML Schema --> |
ohair@286 | 188 | * <customerData> |
ohair@286 | 189 | * <customer customerID="Alice"> |
ohair@286 | 190 | * .... |
ohair@286 | 191 | * </customer> |
ohair@286 | 192 | * |
ohair@286 | 193 | * <shipping customer="Alice"> |
ohair@286 | 194 | * .... |
ohair@286 | 195 | * </shipping> |
ohair@286 | 196 | * |
ohair@286 | 197 | * <invoice customer="Alice"> |
ohair@286 | 198 | * .... |
ohair@286 | 199 | * </invoice> |
ohair@286 | 200 | * </customerData> |
ohair@286 | 201 | * |
ohair@286 | 202 | * </pre> |
ohair@286 | 203 | * |
ohair@286 | 204 | * <p><b>Example 3: </b> Mapping List to repeating element of type IDREF |
ohair@286 | 205 | * <pre> |
ohair@286 | 206 | * // Code fragment |
ohair@286 | 207 | * public class Shipping { |
ohair@286 | 208 | * @XmlIDREF |
ohair@286 | 209 | * @XmlElement(name="Alice") |
ohair@286 | 210 | * public List customers; |
ohair@286 | 211 | * } |
ohair@286 | 212 | * |
ohair@286 | 213 | * <!-- XML schema fragment --> |
ohair@286 | 214 | * <xs:complexType name="Shipping"> |
ohair@286 | 215 | * <xs:sequence> |
ohair@286 | 216 | * <xs:choice minOccurs="0" maxOccurs="unbounded"> |
ohair@286 | 217 | * <xs:element name="Alice" type="xs:IDREF"/> |
ohair@286 | 218 | * </xs:choice> |
ohair@286 | 219 | * </xs:sequence> |
ohair@286 | 220 | * </xs:complexType> |
ohair@286 | 221 | * </pre> |
ohair@286 | 222 | * |
ohair@286 | 223 | * <p><b>Example 4: </b> Mapping a List to a list of elements of type IDREF. |
ohair@286 | 224 | * <pre> |
ohair@286 | 225 | * //Code fragment |
ohair@286 | 226 | * public class Shipping { |
ohair@286 | 227 | * @XmlIDREF |
ohair@286 | 228 | * @XmlElements( |
ohair@286 | 229 | * @XmlElement(name="Alice", type="Customer.class") |
ohair@286 | 230 | * @XmlElement(name="John", type="InternationalCustomer.class") |
ohair@286 | 231 | * public List customers; |
ohair@286 | 232 | * } |
ohair@286 | 233 | * |
ohair@286 | 234 | * <!-- XML Schema fragment --> |
ohair@286 | 235 | * <xs:complexType name="Shipping"> |
ohair@286 | 236 | * <xs:sequence> |
ohair@286 | 237 | * <xs:choice minOccurs="0" maxOccurs="unbounded"> |
ohair@286 | 238 | * <xs:element name="Alice" type="xs:IDREF"/> |
ohair@286 | 239 | * <xs:element name="John" type="xs:IDREF"/> |
ohair@286 | 240 | * </xs:choice> |
ohair@286 | 241 | * </xs:sequence> |
ohair@286 | 242 | * </xs:complexType> |
ohair@286 | 243 | * </pre> |
ohair@286 | 244 | * @author Sekhar Vajjhala, Sun Microsystems, Inc. |
ohair@286 | 245 | * @see XmlID |
ohair@286 | 246 | * @since JAXB2.0 |
ohair@286 | 247 | */ |
ohair@286 | 248 | |
ohair@286 | 249 | @Retention(RUNTIME) @Target({FIELD, METHOD}) |
ohair@286 | 250 | public @interface XmlIDREF {} |