@RetentionSE(valueSE=RUNTIMESE) @TargetSE(valueSE={FIELDSE,METHODSE}) public @interface XmlIDREF
JavaBean プロパティを XMLIDREF にマップします。
XML 直列化とそれに続く XML 逆直列化の間でオブジェクトグラフの参照整合性を維持するには、オブジェクト参照を参照または包含によって適切にマーシャリングする必要があります。アノテーション @XmlID と @XmlIDREF を一緒に使用すると、包含または参照によって JavaBean プロパティの型のカスタマイズされたマッピングが可能になります。
使用方法
@XmlIDREF アノテーションは、次のプログラム要素で使用できます。追加の共通情報については、jakarta.xml.bind.package javadoc の「パッケージ仕様」を参照してください。
使用箇所には、次の制約があります。
@XmlID でアノテーションが付けられたプロパティまたはフィールドが含まれている必要があります。@XmlID でアノテーションが付けられたプロパティまたはフィールドが含まれている必要があります。 メモ: コレクションアイテム型またはプロパティの型(コレクション型以外の場合)が java.lang.Object の場合、インスタンスには @XmlID 属性でアノテーションが付けられたプロパティ / フィールドが含まれている必要があります。
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>
XmlIDCopyright © 2018,2020 Eclipse Foundation.
Use is subject to license terms.