< prev index next >

src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlIDREF.java

Print this page




  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 IDREF.
  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 marshaled 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>@XmlIDREF</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  * <p> The usage is subject to the following constraints:
  57  * <ul>
  58  *
  59  *   <li> If the type of the field or property is a collection type,
  60  *        then the collection item type must contain a property or
  61  *        field annotated with <tt>@XmlID</tt>.  </li>
  62  *   <li> If the field or property is single valued, then the type of
  63  *        the property or field must contain a property or field
  64  *        annotated with <tt>@XmlID</tt>.
  65  *        <p>Note: If the collection item type or the type of the
  66  *        property (for non collection type) is java.lang.Object, then
  67  *        the instance must contain a property/field annotated with
  68  *        <tt>@XmlID</tt> attribute.
  69  *        </li>
  70  *   <li> This annotation can be used with the following annotations:
  71  *        {@link XmlElement}, {@link XmlAttribute}, {@link XmlList},
  72  *        and {@link XmlElements}.</li>
  73  *
  74  * </ul>
  75  * <p><b>Example:</b> Map a JavaBean property to <tt>xs:IDREF</tt>
  76  *   (i.e. by reference rather than by containment)</p>
  77  * <pre>
  78  *
  79  *   //EXAMPLE: Code fragment
  80  *   public class Shipping {
  81  *       @XmlIDREF public Customer getCustomer();
  82  *       public void setCustomer(Customer customer);
  83  *       ....
  84  *    }
  85  * {@code
  86  *
  87  *   <!-- Example: XML Schema fragment -->
  88  *   <xs:complexType name="Shipping">
  89  *     <xs:complexContent>
  90  *       <xs:sequence>
  91  *         <xs:element name="customer" type="xs:IDREF"/>
  92  *         ....
  93  *       </xs:sequence>
  94  *     </xs:complexContent>
  95  *   </xs:complexType>
  96  *
  97  * }</pre>
  98  *
  99  *
 100  * <p><b>Example 2: </b> The following is a complete example of
 101  * containment versus reference.
 102  *
 103  * <pre>
 104  *    // By default, Customer maps to complex type <tt>xs:Customer</tt>
 105  *    public class Customer {
 106  *
 107  *        // map JavaBean property type to <tt>xs:ID</tt>
 108  *        @XmlID public String getCustomerID();
 109  *        public void setCustomerID(String id);
 110  *
 111  *        // .... other properties not shown
 112  *    }
 113  *
 114  *
 115  *   // By default, Invoice maps to a complex type <tt>xs:Invoice</tt>
 116  *   public class Invoice {
 117  *
 118  *       // map by reference
 119  *       @XmlIDREF public Customer getCustomer();
 120  *       public void setCustomer(Customer customer);
 121  *
 122  *      // .... other properties not shown here
 123  *   }
 124  *
 125  *   // By default, Shipping maps to complex type <tt>xs:Shipping</tt>
 126  *   public class Shipping {
 127  *
 128  *       // map by reference
 129  *       @XmlIDREF public Customer getCustomer();
 130  *       public void setCustomer(Customer customer);
 131  *   }
 132  *
 133  *   // at least one class must reference Customer by containment;
 134  *   // Customer instances won't be marshalled.
 135  *   @XmlElement(name="CustomerData")
 136  *   public class CustomerData {
 137  *       // map reference to Customer by containment by default.
 138  *       public Customer getCustomer();
 139  *
 140  *       // maps reference to Shipping by containment by default.
 141  *       public Shipping getShipping();
 142  *
 143  *       // maps reference to Invoice by containment by default.
 144  *       public Invoice getInvoice();
 145  *   }




  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 IDREF.
  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 marshaled by reference or containment
  41  * appropriately. Annotations {@code @XmlID} and {@code @XmlIDREF}
  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 {@code @XmlIDREF} 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  * <p> The usage is subject to the following constraints:
  57  * <ul>
  58  *
  59  *   <li> If the type of the field or property is a collection type,
  60  *        then the collection item type must contain a property or
  61  *        field annotated with {@code @XmlID}.  </li>
  62  *   <li> If the field or property is single valued, then the type of
  63  *        the property or field must contain a property or field
  64  *        annotated with {@code @XmlID}.
  65  *        <p>Note: If the collection item type or the type of the
  66  *        property (for non collection type) is java.lang.Object, then
  67  *        the instance must contain a property/field annotated with
  68  *        {@code @XmlID} attribute.
  69  *        </li>
  70  *   <li> This annotation can be used with the following annotations:
  71  *        {@link XmlElement}, {@link XmlAttribute}, {@link XmlList},
  72  *        and {@link XmlElements}.</li>
  73  *
  74  * </ul>
  75  * <p><b>Example:</b> Map a JavaBean property to {@code xs:IDREF}
  76  *   (i.e. by reference rather than by containment)</p>
  77  * <pre>
  78  *
  79  *   //EXAMPLE: Code fragment
  80  *   public class Shipping {
  81  *       @XmlIDREF public Customer getCustomer();
  82  *       public void setCustomer(Customer customer);
  83  *       ....
  84  *    }
  85  * {@code
  86  *
  87  *   <!-- Example: XML Schema fragment -->
  88  *   <xs:complexType name="Shipping">
  89  *     <xs:complexContent>
  90  *       <xs:sequence>
  91  *         <xs:element name="customer" type="xs:IDREF"/>
  92  *         ....
  93  *       </xs:sequence>
  94  *     </xs:complexContent>
  95  *   </xs:complexType>
  96  *
  97  * }</pre>
  98  *
  99  *
 100  * <p><b>Example 2: </b> The following is a complete example of
 101  * containment versus reference.
 102  *
 103  * <pre>
 104  *    // By default, Customer maps to complex type {@code xs:Customer}
 105  *    public class Customer {
 106  *
 107  *        // map JavaBean property type to {@code xs:ID}
 108  *        @XmlID public String getCustomerID();
 109  *        public void setCustomerID(String id);
 110  *
 111  *        // .... other properties not shown
 112  *    }
 113  *
 114  *
 115  *   // By default, Invoice maps to a complex type {@code xs:Invoice}
 116  *   public class Invoice {
 117  *
 118  *       // map by reference
 119  *       @XmlIDREF public Customer getCustomer();
 120  *       public void setCustomer(Customer customer);
 121  *
 122  *      // .... other properties not shown here
 123  *   }
 124  *
 125  *   // By default, Shipping maps to complex type {@code xs:Shipping}
 126  *   public class Shipping {
 127  *
 128  *       // map by reference
 129  *       @XmlIDREF public Customer getCustomer();
 130  *       public void setCustomer(Customer customer);
 131  *   }
 132  *
 133  *   // at least one class must reference Customer by containment;
 134  *   // Customer instances won't be marshalled.
 135  *   @XmlElement(name="CustomerData")
 136  *   public class CustomerData {
 137  *       // map reference to Customer by containment by default.
 138  *       public Customer getCustomer();
 139  *
 140  *       // maps reference to Shipping by containment by default.
 141  *       public Shipping getShipping();
 142  *
 143  *       // maps reference to Invoice by containment by default.
 144  *       public Invoice getInvoice();
 145  *   }


< prev index next >