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>@XmlID</tt> and <tt>@XmlIDREF</tt> |
41 * appropriately. Annotations <tt>@XmlID</tt> and <tt>@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 * @XmlIDREF public Customer getCustomer(); |
81 * @XmlIDREF public Customer getCustomer(); |
82 * public void setCustomer(Customer customer); |
82 * public void setCustomer(Customer customer); |
83 * .... |
83 * .... |
84 * } |
84 * } |
85 * |
85 * {@code |
86 * <!-- Example: XML Schema fragment --> |
86 * |
87 * <xs:complexType name="Shipping"> |
87 * <!-- Example: XML Schema fragment --> |
88 * <xs:complexContent> |
88 * <xs:complexType name="Shipping"> |
89 * <xs:sequence> |
89 * <xs:complexContent> |
90 * <xs:element name="customer" type="xs:IDREF"/> |
90 * <xs:sequence> |
91 * .... |
91 * <xs:element name="customer" type="xs:IDREF"/> |
92 * </xs:sequence> |
92 * .... |
93 * </xs:complexContent> |
93 * </xs:sequence> |
94 * </xs:complexType> |
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 * <!-- XML Schema mapping for above code frament --> |
147 * |
147 * |
148 * <!-- XML Schema mapping for above code frament --> |
148 * <xs:complexType name="Invoice"> |
149 * |
149 * <xs:complexContent> |
150 * <xs:complexType name="Invoice"> |
150 * <xs:sequence> |
151 * <xs:complexContent> |
151 * <xs:element name="customer" type="xs:IDREF"/> |
152 * <xs:sequence> |
152 * .... |
153 * <xs:element name="customer" type="xs:IDREF"/> |
153 * </xs:sequence> |
154 * .... |
154 * </xs:complexContent> |
155 * </xs:sequence> |
155 * </xs:complexType> |
156 * </xs:complexContent> |
156 * |
157 * </xs:complexType> |
157 * <xs:complexType name="Shipping"> |
158 * |
158 * <xs:complexContent> |
159 * <xs:complexType name="Shipping"> |
159 * <xs:sequence> |
160 * <xs:complexContent> |
160 * <xs:element name="customer" type="xs:IDREF"/> |
161 * <xs:sequence> |
161 * .... |
162 * <xs:element name="customer" type="xs:IDREF"/> |
162 * </xs:sequence> |
163 * .... |
163 * </xs:complexContent> |
164 * </xs:sequence> |
164 * </xs:complexType> |
165 * </xs:complexContent> |
165 * |
166 * </xs:complexType> |
166 * <xs:complexType name="Customer"> |
167 * |
167 * <xs:complexContent> |
168 * <xs:complexType name="Customer"> |
168 * <xs:sequence> |
169 * <xs:complexContent> |
169 * .... |
170 * <xs:sequence> |
170 * </xs:sequence> |
171 * .... |
171 * <xs:attribute name="CustomerID" type="xs:ID"/> |
172 * </xs:sequence> |
172 * </xs:complexContent> |
173 * <xs:attribute name="CustomerID" type="xs:ID"/> |
173 * </xs:complexType> |
174 * </xs:complexContent> |
174 * |
175 * </xs:complexType> |
175 * <xs:complexType name="CustomerData"> |
176 * |
176 * <xs:complexContent> |
177 * <xs:complexType name="CustomerData"> |
177 * <xs:sequence> |
178 * <xs:complexContent> |
178 * <xs:element name="customer" type="xs:Customer"/> |
179 * <xs:sequence> |
179 * <xs:element name="shipping" type="xs:Shipping"/> |
180 * <xs:element name="customer" type="xs:Customer"/> |
180 * <xs:element name="invoice" type="xs:Invoice"/> |
181 * <xs:element name="shipping" type="xs:Shipping"/> |
181 * </xs:sequence> |
182 * <xs:element name="invoice" type="xs:Invoice"/> |
182 * </xs:complexContent> |
183 * </xs:sequence> |
183 * </xs:complexType> |
184 * </xs:complexContent> |
184 * |
185 * </xs:complexType> |
185 * <xs:element name"customerData" type="xs:CustomerData"/> |
186 * |
186 * |
187 * <xs:element name"customerData" type="xs:CustomerData"/> |
187 * <!-- Instance document conforming to the above XML Schema --> |
188 * |
188 * <customerData> |
189 * <!-- Instance document conforming to the above XML Schema --> |
189 * <customer customerID="Alice"> |
190 * <customerData> |
|
191 * <customer customerID="Alice"> |
190 * .... |
192 * .... |
191 * </customer> |
193 * </customer> |
192 * |
194 * |
193 * <shipping customer="Alice"> |
195 * <shipping customer="Alice"> |
194 * .... |
196 * .... |
195 * </shipping> |
197 * </shipping> |
196 * |
198 * |
197 * <invoice customer="Alice"> |
199 * <invoice customer="Alice"> |
198 * .... |
200 * .... |
199 * </invoice> |
201 * </invoice> |
200 * </customerData> |
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 * @XmlIDREF |
210 * @XmlIDREF |
209 * @XmlElement(name="Alice") |
211 * @XmlElement(name="Alice") |
210 * public List customers; |
212 * public List customers; |
211 * } |
213 * } |
212 * |
214 * {@code |
213 * <!-- XML schema fragment --> |
215 * |
214 * <xs:complexType name="Shipping"> |
216 * <!-- XML schema fragment --> |
215 * <xs:sequence> |
217 * <xs:complexType name="Shipping"> |
216 * <xs:choice minOccurs="0" maxOccurs="unbounded"> |
218 * <xs:sequence> |
217 * <xs:element name="Alice" type="xs:IDREF"/> |
219 * <xs:choice minOccurs="0" maxOccurs="unbounded"> |
218 * </xs:choice> |
220 * <xs:element name="Alice" type="xs:IDREF"/> |
219 * </xs:sequence> |
221 * </xs:choice> |
220 * </xs:complexType> |
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 * @XmlElements( |
231 * @XmlElements( |
229 * @XmlElement(name="Alice", type="Customer.class") |
232 * @XmlElement(name="Alice", type="Customer.class") |
230 * @XmlElement(name="John", type="InternationalCustomer.class") |
233 * @XmlElement(name="John", type="InternationalCustomer.class") |
231 * public List customers; |
234 * public List customers; |
232 * } |
235 * } |
233 * |
236 * {@code |
234 * <!-- XML Schema fragment --> |
237 * |
235 * <xs:complexType name="Shipping"> |
238 * <!-- XML Schema fragment --> |
236 * <xs:sequence> |
239 * <xs:complexType name="Shipping"> |
237 * <xs:choice minOccurs="0" maxOccurs="unbounded"> |
240 * <xs:sequence> |
238 * <xs:element name="Alice" type="xs:IDREF"/> |
241 * <xs:choice minOccurs="0" maxOccurs="unbounded"> |
239 * <xs:element name="John" type="xs:IDREF"/> |
242 * <xs:element name="Alice" type="xs:IDREF"/> |
240 * </xs:choice> |
243 * <xs:element name="John" type="xs:IDREF"/> |
241 * </xs:sequence> |
244 * </xs:choice> |
242 * </xs:complexType> |
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 |