|
Préférences
Moteurs de recherche
|
||||||||||||||||||||||||||||||||||||||||||
JavaTM 2 Platform Std. Ed. v1.6.0
javax.xml.bind.annotation
|
Target | propOrder | ClassBody | ComplexType | SimpleType | |
Class | {} | [property]+ -> elements | complexcontent xs:all |
||
Class | non empty | [property]+ -> elements | complexcontent xs:sequence |
||
Class | X | no property -> element | complexcontent empty sequence |
||
Class | X | 1 [ @XmlValue property] && [property]+ ->attributes |
simplecontent | ||
Class | X | 1 [ @XmlValue property ]&& no properties -> attribute |
simpletype |
This annotation can be used with the following annotations:
XmlRootElement
, XmlAccessorOrder
, XmlAccessorType
,
XmlEnum
. However, XmlAccessorOrder
and XmlAccessorType
are ignored when this
annotation is used on an enum type.
Example 1: Map a class to a complex type with xs:sequence with a customized ordering of JavaBean properties.
@XmlType(propOrder={"street", "city" , "state", "zip", "name" }) public class USAddress { String getName() {..}; void setName(String) {..}; String getStreet() {..}; void setStreet(String) {..}; String getCity() {..}; void setCity(String) {..}; String getState() {..}; void setState(String) {..}; java.math.BigDecimal getZip() {..}; void setZip(java.math.BigDecimal) {..}; } <!-- XML Schema mapping for USAddress --> <xs:complexType name="USAddress"> <xs:sequence> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="state" type="xs:string"/> <xs:element name="zip" type="xs:decimal"/> <xs:element name="name" type="xs:string"/> </xs:all> </xs:complexType>
Example 2: Map a class to a complex type with xs:all
@XmlType(propOrder={}) public class USAddress { ...} <!-- XML Schema mapping for USAddress --> <xs:complexType name="USAddress"> <xs:all> <xs:element name="name" type="xs:string"/> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="state" type="xs:string"/> <xs:element name="zip" type="xs:decimal"/> </xs:sequence> </xs:complexType>
Example 3: Map a class to a global element with an anonymous type.
@XmlRootElement @XmlType(name="") public class USAddress { ...} <!-- XML Schema mapping for USAddress --> <xs:element name="USAddress"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="state" type="xs:string"/> <xs:element name="zip" type="xs:decimal"/> </xs:sequence> </xs:complexType> </xs:element>
Example 4: Map a property to a local element with anonmyous type.
//Example: Code fragment public class Invoice { USAddress addr; ... } @XmlType(name="") public class USAddress { ... } } <!-- XML Schema mapping for USAddress --> <xs:complexType name="Invoice"> <xs:sequence> <xs:element name="addr"> <xs:complexType> <xs:element name="name", type="xs:string"/> <xs:element name="city", type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="state" type="xs:string"/> <xs:element name="zip" type="xs:decimal"/> </xs:complexType> ... </xs:sequence> </xs:complexType>
Example 5: Map a property to an attribute with anonymous type.
//Example: Code fragment public class Item { public String name; @XmlAttribute public USPrice price; } // map class to anonymous simple type. @XmlType(name="") public class USPrice { @XmlValue public java.math.BigDecimal price; } <!-- Example: XML Schema fragment --> <xs:complexType name="Item"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:attribute name="price"> <xs:simpleType> <xs:restriction base="xs:decimal"/> </xs:simpleType> </xs:attribute> </xs:sequence> </xs:complexType>
Example 6: Define a factoryClass and factoryMethod
@XmlType(name="USAddressType", factoryClass=USAddressFactory.class, factoryMethod="getUSAddress") public class USAddress { private String city; private String name; private String state; private String street; private int zip; public USAddress(String name, String street, String city, String state, int zip) { this.name = name; this.street = street; this.city = city; this.state = state; this.zip = zip; } } public class USAddressFactory { public static USAddress getUSAddress(){ return new USAddress("Mark Baker", "23 Elm St", "Dayton", "OH", 90952); }
Example 7: Define factoryMethod and use the default factoryClass
@XmlType(name="USAddressType", factoryMethod="getNewInstance") public class USAddress { private String city; private String name; private String state; private String street; private int zip; private USAddress() {} public static USAddress getNewInstance(){ return new USAddress(); } }
XmlElement
,
XmlAttribute
,
XmlValue
,
XmlSchema
Optional Element Summary | |
---|---|
Class |
factoryClass
Class containing a no-arg factory method for creating an instance of this class. |
String |
factoryMethod
Name of a no-arg factory method in the class specified in factoryClass factoryClass(). |
String |
name
Name of the XML Schema type which the class is mapped. |
String |
namespace
Name of the target namespace of the XML Schema type. |
String[] |
propOrder
Specifies the order for XML Schema elements when class is mapped to a XML Schema complex type. |
public abstract String name
public abstract String[] propOrder
Refer to the table for how the propOrder affects the mapping of class
The propOrder is a list of names of JavaBean properties in the class. Each name in the list is the name of a Java identifier of the JavaBean property. The order in which JavaBean properties are listed is the order of XML Schema elements to which the JavaBean properties are mapped.
All of the JavaBean properties being mapped to XML Schema elements must be listed.
A JavaBean property or field listed in propOrder must not be transient or annotated with @XmlTransient.
The default ordering of JavaBean properties is determined
by @XmlAccessorOrder
.
public abstract String namespace
public abstract Class factoryClass
If factoryClass is DEFAULT.class and factoryMethod is "", then there is no static factory method.
If factoryClass is DEFAULT.class and factoryMethod is not "", then factoryMethod is the name of a static factory method in this class.
If factoryClass is not DEFAULT.class, then factoryMethod must not be "" and must be the name of a static factory method specified in factoryClass.
public abstract String factoryMethod