1 /* 2 * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.xml.bind.annotation; 27 28 import java.lang.annotation.Target; 29 import java.lang.annotation.Retention; 30 import static java.lang.annotation.ElementType.*; 31 import static java.lang.annotation.RetentionPolicy.*; 32 33 /** 34 * <p> 35 * Maps a JavaBean property to XML ID. 36 * 37 * <p> 38 * To preserve referential integrity of an object graph across XML 39 * serialization followed by a XML deserialization, requires an object 40 * reference to be marshalled by reference or containment 41 * appropriately. Annotations <tt>@XmlID</tt> and <tt>@XmlIDREF</tt> 42 * together allow a customized mapping of a JavaBean property's 43 * type by containment or reference. 44 * 45 * <p><b>Usage</b> </p> 46 * The <tt>@XmlID</tt> annotation can be used with the following 47 * program elements: 48 * <ul> 49 * <li> a JavaBean property </li> 50 * <li> non static, non transient field </li> 51 * </ul> 52 * 53 * <p>See "Package Specification" in javax.xml.bind.package javadoc for 54 * additional common information.</p> 55 * 56 * The usage is subject to the following constraints: 57 * <ul> 58 * <li> At most one field or property in a class can be annotated 59 * with <tt>@XmlID</tt>. </li> 60 * <li> The JavaBean property's type must be <tt>java.lang.String</tt>.</li> 61 * <li> The only other mapping annotations that can be used 62 * with <tt>@XmlID</tt> 63 * are:<tt>@XmlElement</tt> and <tt>@XmlAttribute</tt>.</li> 64 * </ul> 65 * 66 * <p><b>Example</b>: Map a JavaBean property's type to <tt>xs:ID</tt></p> 67 * <pre> 68 * // Example: code fragment 69 * public class Customer { 70 * @XmlAttribute 71 * @XmlID 72 * public String getCustomerID(); 73 * public void setCustomerID(String id); 74 * .... other properties not shown 75 * } 76 * 77 * <!-- Example: XML Schema fragment --> 78 * <xs:complexType name="Customer"> 79 * <xs:complexContent> 80 * <xs:sequence> 81 * .... 82 * </xs:sequence> 83 * <xs:attribute name="customerID" type="xs:ID"/> 84 * </xs:complexContent> 85 * </xs:complexType> 86 * </pre> 87 * 88 * @author Sekhar Vajjhala, Sun Microsystems, Inc. 89 * @see XmlIDREF 90 * @since JAXB2.0 91 */ 92 93 @Retention(RUNTIME) @Target({FIELD, METHOD}) 94 public @interface XmlID { }