|
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 의 「패키지의 스펙」을 참조해 주세요.
사용에는 다음의 제약이 있습니다.
주:컬렉션 항목의 형태, 또는 프로퍼티의 형태 (컬렉션형 이외의 경우)가 java.lang.Object 의 경우, 인스턴스에,@XmlID 속성으로 주석 된 프로퍼티이나 필드가 포함될 필요가 있습니다.
XmlElement ,XmlAttribute ,XmlList ,XmlElements . 예 1: 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 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy 도 참조해 주세요.