jaxws/src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlIDREF.java
changeset 29839 6d5d546e953b
parent 28887 88470f768658
child 32795 5a5710ee05a0
equal deleted inserted replaced
29838:fe5fd9871a13 29839:6d5d546e953b
    35  * Maps a JavaBean property to XML IDREF.
    35  * Maps a JavaBean property to XML IDREF.
    36  *
    36  *
    37  * <p>
    37  * <p>
    38  * To preserve referential integrity of an object graph across XML
    38  * To preserve referential integrity of an object graph across XML
    39  * serialization followed by a XML deserialization, requires an object
    39  * serialization followed by a XML deserialization, requires an object
    40  * reference to be marshalled by reference or containment
    40  * reference to be marshaled by reference or containment
    41  * appropriately. Annotations <tt>&#64;XmlID</tt> and <tt>&#64;XmlIDREF</tt>
    41  * appropriately. Annotations <tt>&#64;XmlID</tt> and <tt>&#64;XmlIDREF</tt>
    42  * together allow a customized mapping of a JavaBean property's
    42  * together allow a customized mapping of a JavaBean property's
    43  * type by containment or reference.
    43  * type by containment or reference.
    44  *
    44  *
    45  * <p><b>Usage</b> </p>
    45  * <p><b>Usage</b> </p>
    80  *   public class Shipping {
    80  *   public class Shipping {
    81  *       &#64;XmlIDREF public Customer getCustomer();
    81  *       &#64;XmlIDREF public Customer getCustomer();
    82  *       public void setCustomer(Customer customer);
    82  *       public void setCustomer(Customer customer);
    83  *       ....
    83  *       ....
    84  *    }
    84  *    }
    85  *
    85  * {@code
    86  *   &lt;!-- Example: XML Schema fragment --&gt;
    86  *
    87  *   &lt;xs:complexType name="Shipping"&gt;
    87  *   <!-- Example: XML Schema fragment -->
    88  *     &lt;xs:complexContent&gt;
    88  *   <xs:complexType name="Shipping">
    89  *       &lt;xs:sequence&gt;
    89  *     <xs:complexContent>
    90  *         &lt;xs:element name="customer" type="xs:IDREF"/&gt;
    90  *       <xs:sequence>
    91  *         ....
    91  *         <xs:element name="customer" type="xs:IDREF"/>
    92  *       &lt;/xs:sequence&gt;
    92  *         ....
    93  *     &lt;/xs:complexContent&gt;
    93  *       </xs:sequence>
    94  *   &lt;/xs:complexType&gt;
    94  *     </xs:complexContent>
    95  *
    95  *   </xs:complexType>
    96  * </pre>
    96  *
       
    97  * }</pre>
    97  *
    98  *
    98  *
    99  *
    99  * <p><b>Example 2: </b> The following is a complete example of
   100  * <p><b>Example 2: </b> The following is a complete example of
   100  * containment versus reference.
   101  * containment versus reference.
   101  *
   102  *
   140  *       public Shipping getShipping();
   141  *       public Shipping getShipping();
   141  *
   142  *
   142  *       // maps reference to Invoice by containment by default.
   143  *       // maps reference to Invoice by containment by default.
   143  *       public Invoice getInvoice();
   144  *       public Invoice getInvoice();
   144  *   }
   145  *   }
   145  *
   146  * {@code
   146  *   &lt;!-- XML Schema mapping for above code frament --&gt;
   147  *
   147  *
   148  *   <!-- XML Schema mapping for above code frament -->
   148  *   &lt;xs:complexType name="Invoice"&gt;
   149  *
   149  *     &lt;xs:complexContent&gt;
   150  *   <xs:complexType name="Invoice">
   150  *       &lt;xs:sequence&gt;
   151  *     <xs:complexContent>
   151  *         &lt;xs:element name="customer" type="xs:IDREF"/&gt;
   152  *       <xs:sequence>
   152  *         ....
   153  *         <xs:element name="customer" type="xs:IDREF"/>
   153  *       &lt;/xs:sequence&gt;
   154  *         ....
   154  *     &lt;/xs:complexContent&gt;
   155  *       </xs:sequence>
   155  *   &lt;/xs:complexType&gt;
   156  *     </xs:complexContent>
   156  *
   157  *   </xs:complexType>
   157  *   &lt;xs:complexType name="Shipping"&gt;
   158  *
   158  *     &lt;xs:complexContent&gt;
   159  *   <xs:complexType name="Shipping">
   159  *       &lt;xs:sequence&gt;
   160  *     <xs:complexContent>
   160  *         &lt;xs:element name="customer" type="xs:IDREF"/&gt;
   161  *       <xs:sequence>
   161  *         ....
   162  *         <xs:element name="customer" type="xs:IDREF"/>
   162  *       &lt;/xs:sequence&gt;
   163  *         ....
   163  *     &lt;/xs:complexContent&gt;
   164  *       </xs:sequence>
   164  *   &lt;/xs:complexType&gt;
   165  *     </xs:complexContent>
   165  *
   166  *   </xs:complexType>
   166  *   &lt;xs:complexType name="Customer"&gt;
   167  *
   167  *     &lt;xs:complexContent&gt;
   168  *   <xs:complexType name="Customer">
   168  *       &lt;xs:sequence&gt;
   169  *     <xs:complexContent>
   169  *         ....
   170  *       <xs:sequence>
   170  *       &lt;/xs:sequence&gt;
   171  *         ....
   171  *       &lt;xs:attribute name="CustomerID" type="xs:ID"/&gt;
   172  *       </xs:sequence>
   172  *     &lt;/xs:complexContent&gt;
   173  *       <xs:attribute name="CustomerID" type="xs:ID"/>
   173  *   &lt;/xs:complexType&gt;
   174  *     </xs:complexContent>
   174  *
   175  *   </xs:complexType>
   175  *   &lt;xs:complexType name="CustomerData"&gt;
   176  *
   176  *     &lt;xs:complexContent&gt;
   177  *   <xs:complexType name="CustomerData">
   177  *       &lt;xs:sequence&gt;
   178  *     <xs:complexContent>
   178  *         &lt;xs:element name="customer" type="xs:Customer"/&gt;
   179  *       <xs:sequence>
   179  *         &lt;xs:element name="shipping" type="xs:Shipping"/&gt;
   180  *         <xs:element name="customer" type="xs:Customer"/>
   180  *         &lt;xs:element name="invoice"  type="xs:Invoice"/&gt;
   181  *         <xs:element name="shipping" type="xs:Shipping"/>
   181  *       &lt;/xs:sequence&gt;
   182  *         <xs:element name="invoice"  type="xs:Invoice"/>
   182  *     &lt;/xs:complexContent&gt;
   183  *       </xs:sequence>
   183  *   &lt;/xs:complexType&gt;
   184  *     </xs:complexContent>
   184  *
   185  *   </xs:complexType>
   185  *   &lt;xs:element name"customerData" type="xs:CustomerData"/&gt;
   186  *
   186  *
   187  *   <xs:element name"customerData" type="xs:CustomerData"/>
   187  *   &lt;!-- Instance document conforming to the above XML Schema --&gt;
   188  *
   188  *    &lt;customerData&gt;
   189  *   <!-- Instance document conforming to the above XML Schema -->
   189  *       &lt;customer customerID="Alice"&gt;
   190  *    <customerData>
       
   191  *       <customer customerID="Alice">
   190  *           ....
   192  *           ....
   191  *       &lt;/customer&gt;
   193  *       </customer>
   192  *
   194  *
   193  *       &lt;shipping customer="Alice"&gt;
   195  *       <shipping customer="Alice">
   194  *           ....
   196  *           ....
   195  *       &lt;/shipping&gt;
   197  *       </shipping>
   196  *
   198  *
   197  *       &lt;invoice customer="Alice"&gt;
   199  *       <invoice customer="Alice">
   198  *           ....
   200  *           ....
   199  *       &lt;/invoice&gt;
   201  *       </invoice>
   200  *   &lt;/customerData&gt;
   202  *   </customerData>
   201  *
   203  *
   202  * </pre>
   204  * }</pre>
   203  *
   205  *
   204  * <p><b>Example 3: </b> Mapping List to repeating element of type IDREF
   206  * <p><b>Example 3: </b> Mapping List to repeating element of type IDREF
   205  * <pre>
   207  * <pre>
   206  *     // Code fragment
   208  *     // Code fragment
   207  *     public class Shipping {
   209  *     public class Shipping {
   208  *         &#64;XmlIDREF
   210  *         &#64;XmlIDREF
   209  *         &#64;XmlElement(name="Alice")
   211  *         &#64;XmlElement(name="Alice")
   210  *             public List customers;
   212  *             public List customers;
   211  *     }
   213  *     }
   212  *
   214  * {@code
   213  *     &lt;!-- XML schema fragment --&gt;
   215  *
   214  *     &lt;xs:complexType name="Shipping"&gt;
   216  *     <!-- XML schema fragment -->
   215  *       &lt;xs:sequence&gt;
   217  *     <xs:complexType name="Shipping">
   216  *         &lt;xs:choice minOccurs="0" maxOccurs="unbounded"&gt;
   218  *       <xs:sequence>
   217  *           &lt;xs:element name="Alice" type="xs:IDREF"/&gt;
   219  *         <xs:choice minOccurs="0" maxOccurs="unbounded">
   218  *         &lt;/xs:choice&gt;
   220  *           <xs:element name="Alice" type="xs:IDREF"/>
   219  *       &lt;/xs:sequence&gt;
   221  *         </xs:choice>
   220  *     &lt;/xs:complexType&gt;
   222  *       </xs:sequence>
   221  * </pre>
   223  *     </xs:complexType>
       
   224  * }</pre>
   222  *
   225  *
   223  * <p><b>Example 4: </b> Mapping a List to a list of elements of type IDREF.
   226  * <p><b>Example 4: </b> Mapping a List to a list of elements of type IDREF.
   224  * <pre>
   227  * <pre>
   225  *     //Code fragment
   228  *     //Code fragment
   226  *     public class Shipping {
   229  *     public class Shipping {
   228  *         &#64;XmlElements(
   231  *         &#64;XmlElements(
   229  *             &#64;XmlElement(name="Alice", type="Customer.class")
   232  *             &#64;XmlElement(name="Alice", type="Customer.class")
   230  *              &#64;XmlElement(name="John", type="InternationalCustomer.class")
   233  *              &#64;XmlElement(name="John", type="InternationalCustomer.class")
   231  *         public List customers;
   234  *         public List customers;
   232  *     }
   235  *     }
   233  *
   236  * {@code
   234  *     &lt;!-- XML Schema fragment --&gt;
   237  *
   235  *     &lt;xs:complexType name="Shipping"&gt;
   238  *     <!-- XML Schema fragment -->
   236  *       &lt;xs:sequence&gt;
   239  *     <xs:complexType name="Shipping">
   237  *         &lt;xs:choice minOccurs="0" maxOccurs="unbounded"&gt;
   240  *       <xs:sequence>
   238  *           &lt;xs:element name="Alice" type="xs:IDREF"/&gt;
   241  *         <xs:choice minOccurs="0" maxOccurs="unbounded">
   239  *           &lt;xs:element name="John" type="xs:IDREF"/&gt;
   242  *           <xs:element name="Alice" type="xs:IDREF"/>
   240  *         &lt;/xs:choice&gt;
   243  *           <xs:element name="John" type="xs:IDREF"/>
   241  *       &lt;/xs:sequence&gt;
   244  *         </xs:choice>
   242  *     &lt;/xs:complexType&gt;
   245  *       </xs:sequence>
   243  * </pre>
   246  *     </xs:complexType>
       
   247  * }</pre>
   244  * @author Sekhar Vajjhala, Sun Microsystems, Inc.
   248  * @author Sekhar Vajjhala, Sun Microsystems, Inc.
   245  * @see XmlID
   249  * @see XmlID
   246  * @since 1.6, JAXB 2.0
   250  * @since 1.6, JAXB 2.0
   247  */
   251  */
   248 
   252