|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 必須 | オプション | 詳細: 要素 | |||||||||
@Retention(value=RUNTIME)
@Target(value={FIELD,METHOD})
public @interface XmlIDREF
JavaBean プロパティーを XML IDREF にマップします。
XML の直列化および直列化復元をまたいだオブジェクトグラフの参照整合性を維持するため、参照または包含関係に基づいて適切にオブジェクト参照を整列化する必要があります。@XmlID 注釈と @XmlIDREF 注釈を合わせて使用することにより、包含関係または参照による JavaBean プロパティーの型のマッピングをカスタマイズできるようになります。
使用方法
@XmlIDREF 注釈は、次のプログラム要素で使用できます。追加の一般的な情報については、javax.xml.bind.package javadoc の「パッケージの仕様」を参照してください。
使用には次の制約があります。
XmlElement、XmlAttribute、XmlList、XmlElements。例: JavaBean プロパティーを xs:IDREF にマップします (つまり、包含関係ではなく参照に基づく)。
//EXAMPLE: Code fragment
public class Shipping {
@XmlIDREF public Customer getCustomer();
public void setCustomer(Customer customer);
....
}
<!-- Example: XML Schema fragment -->
<xs:complexType name="Shipping">
<xs:complexContent>
<xs:sequence>
<xs:element name="customer" type="xs:IDREF"/>
....
</xs:sequence>
</xs:complexContent>
</xs:complexType>
例 2: 次に、包含関係と参照を対比した包括的な例を示します。
// By default, Customer maps to complex type xs:Customer
public class Customer {
// map JavaBean property type to xs:ID
@XmlID public String getCustomerID();
public void setCustomerID(String id);
// .... other properties not shown
}
// By default, Invoice maps to a complex type xs:Invoice
public class Invoice {
// map by reference
@XmlIDREF public Customer getCustomer();
public void setCustomer(Customer customer);
// .... other properties not shown here
}
// By default, Shipping maps to complex type xs:Shipping
public class Shipping {
// map by reference
@XmlIDREF public Customer getCustomer();
public void setCustomer(Customer customer);
}
// at least one class must reference Customer by containment;
// Customer instances won't be marshalled.
@XmlElement(name="CustomerData")
public class CustomerData {
// map reference to Customer by containment by default.
public Customer getCustomer();
// maps reference to Shipping by containment by default.
public Shipping getShipping();
// maps reference to Invoice by containment by default.
public Invoice getInvoice();
}
<!-- XML Schema mapping for above code frament -->
<xs:complexType name="Invoice">
<xs:complexContent>
<xs:sequence>
<xs:element name="customer" type="xs:IDREF"/>
....
</xs:sequence>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Shipping">
<xs:complexContent>
<xs:sequence>
<xs:element name="customer" type="xs:IDREF"/>
....
</xs:sequence>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Customer">
<xs:complexContent>
<xs:sequence>
....
</xs:sequence>
<xs:attribute name="CustomerID" type="xs:ID"/>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="CustomerData">
<xs:complexContent>
<xs:sequence>
<xs:element name="customer" type="xs:Customer"/>
<xs:element name="shipping" type="xs:Shipping"/>
<xs:element name="invoice" type="xs:Invoice"/>
</xs:sequence>
</xs:complexContent>
</xs:complexType>
<xs:element name"customerData" type="xs:CustomerData"/>
<!-- Instance document conforming to the above XML Schema -->
<customerData>
<customer customerID="Alice">
....
</customer>
<shipping customer="Alice">
....
</shipping>
<invoice customer="Alice">
....
</invoice>
</customerData>
例 3: リストを IDREF 型の繰り返し要素にマップします。
// Code fragment
public class Shipping {
@XmlIDREF
@XmlElement(name="Alice")
public List customers;
}
<!-- XML schema fragment -->
<xs:complexType name="Shipping">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Alice" type="xs:IDREF"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
例 4: リストを IDREF 型の要素リストにマップします。
//Code fragment
public class Shipping {
@XmlIDREF
@XmlElements(
@XmlElement(name="Alice", type="Customer.class")
@XmlElement(name="John", type="InternationalCustomer.class")
public List customers;
}
<!-- XML Schema fragment -->
<xs:complexType name="Shipping">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Alice" type="xs:IDREF"/>
<xs:element name="John" type="xs:IDREF"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
XmlID
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 必須 | オプション | 詳細: 要素 | |||||||||
Copyright 2009 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Documentation Redistribution Policy も参照してください。