|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
javax.xml.bind.annotation Annotation Type XmlID
@Target(value={FIELD, METHOD})
将 JavaBean 属性映射到 XML ID。
要在 XML 序列化然后反序列化这一过程中保持对象图形的引用完整性,需要通过使用引用或容器适当地对对象引用进行编组。注释 @XmlID 和 @XmlIDREF 一起使用时允许通过容器或引用来实现 JavaBean 属性类型的自定义映射。
用法
@XmlID 注释能够与以下程序元素一起使用:- JavaBean 属性
- 非 static、非 transient 字段
有关公共信息,请参阅 javax.xml.bind.package javadoc 中的“包规范”。
用法受到以下约束的限制:- 只能使用 @XmlID 注释一个类中最多一个字段或属性。
- JavaBean 属性的类型必须是 java.lang.String。
- 能够与 @XmlID 一起使用的其他映射注释只有 @XmlElement 和 @XmlAttribute。
示例:将 JavaBean 属性的类型映射到 xs:ID
// Example: code fragment public class Customer { @XmlAttribute @XmlID public String getCustomerID(); public void setCustomerID(String id); .... other properties not shown } <!-- Example: XML Schema fragment --> <xs:complexType name="Customer"> <xs:complexContent> <xs:sequence> .... </xs:sequence> <xs:attribute name="customerID" type="xs:ID"/> </xs:complexContent> </xs:complexType>
since | JAXB2.0 | |
version |
| |
See also | javax.xml.bind.annotation.XmlIDREF |
Maps a JavaBean property to XML ID.
To preserve referential integrity of an object graph across XML serialization followed by a XML deserialization, requires an object reference to be marshalled by reference or containment appropriately. Annotations @XmlID and @XmlIDREF together allow a customized mapping of a JavaBean property's type by containment or reference.
Usage
The @XmlID annotation can be used with the following program elements:- a JavaBean property
- non static, non transient field
See "Package Specification" in javax.xml.bind.package javadoc for additional common information.
The usage is subject to the following constraints:- At most one field or property in a class can be annotated with @XmlID.
- The JavaBean property's type must be java.lang.String.
- The only other mapping annotations that can be used with @XmlID are:@XmlElement and @XmlAttribute.
Example: Map a JavaBean property's type to xs:ID
// Example: code fragment public class Customer { @XmlAttribute @XmlID public String getCustomerID(); public void setCustomerID(String id); .... other properties not shown } <!-- Example: XML Schema fragment --> <xs:complexType name="Customer"> <xs:complexContent> <xs:sequence> .... </xs:sequence> <xs:attribute name="customerID" type="xs:ID"/> </xs:complexContent> </xs:complexType>
- Since:
- JAXB2.0
- Version:
- $Revision: 1.5 $
- Author:
- Sekhar Vajjhala, Sun Microsystems, Inc.
- See Also:
XmlIDREF
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
Submit a bug or feature
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!