@Retention(value=RUNTIME) @Target(value=TYPE) public @interface XmlType
Map类或枚举类型的一个XML Schema类型。
使用
的@XmlType annnotation可以用下面的程序元素:
看到“包装规范”的额外的信息共享javax.xml.bind.package javadoc。
一个类映射到XML模式类型。类是由属性和字段表示的值的数据容器。模式类型是在架构类型的内容模型(例如,模型组、属性等)中的模式组件表示的值的数据容器。
要映射,一个类必须有一个公共的无参数构造函数或静态工厂方法不精。静态工厂方法可以在factoryMethod()和factoryClass()注释元素指定。静态工厂方法或无参数构造函数中使用组来创建该类的实例。如果存在,静态工厂方法重写的无参数构造函数。
一个类映射到一个XML架构复杂类型或一个XML架构简单类型。XML架构类型是基于JavaBean的属性和字段的映射包含在类派生。映射的类映射的模式类型可以是匿名的或匿名的。一个类可以被映射到一个匿名模式类型的注释的类@XmlType(name="")。
全局元素、局部元素或局部属性可以与匿名类型关联,如下所示:
XmlRootElement
的派生类。见下面的例子3。映射类到XML架构简单类型
一个类可以映射到XML Schema的简单类型使用@XmlValue注释。额外的细节和例子,看”XmlValue
注释类型。
下表显示了类到XML架构复杂类型或简单类型的映射。在表中使用的符号是:
Target propOrder ClassBody ComplexType SimpleType 类 {} [property]+ -> elements complexcontent
xs:all类 non empty [property]+ -> elements complexcontent
xs:sequence类 X no property -> element complexcontent
empty sequence类 X 1 [ @XmlValue property] &&
[property]+ ->attributessimplecontent 类 X 1 [ @XmlValue property ]&&
no properties -> attributesimpletype
这个注释可以用下面的注释:XmlRootElement
,XmlAccessorOrder
,XmlAccessorType
,XmlEnum
。然而,XmlAccessorOrder
和XmlAccessorType
时忽略该注释是一个枚举类型。
一个类映射到一个例1: XS复杂型:与定制订购的JavaBean属性序列。
@ XmlType(proporder = {“街”、“城市”、“国家”、“拉链”、“名”})公共类usAddress {字符串getname() {,};空虚setName(字符串){等};字符串getstreet() {,};无效setstreet(字符串){等};字符串getcity() {,};无效setcity(字符串){等};字符串getstate() {,};无效setstate(字符串){等};java.math.bigdecimal getzip() {等};无效setzip(java。数学。BigDecimal){等};}<!——usAddress XML Schema映射-->< xs:complexType名称=“usAddress”>< xs:序列>< xs:元名称=“街”type=“XS:字符串”/>< xs:元名称=“城市型”=“XS:字符串”/>< xs:元名称=“国家”type=“XS:字符串”/>< xs:元名称=“拉链”type=“XS:十进制”/>< xs:元名称=“名”type=“XS:字符串”/>< / xs:所有>< / xs:名称>
一个类映射到一个例2: XS复杂类型:所有
@ XmlType(proporder = { })公共类usAddress {…}<!——usAddress XML Schema映射-->< xs:complexType名称=“usAddress”>< xs:所有>< xs:元名称=“名”type=“XS:字符串”/>< xs:元名称=“街”type=“XS:字符串”/>< xs:元名称=“城市型”=“XS:字符串”/>< xs:元名称=“国家”type=“XS:字符串”/>< xs:元名称=“拉链”type=“XS:十进制”/>< / xs:序列>< / xs:名称>
例3:一个类映射到一个匿名类型的全局元素。
“xmlrootelement@ XmlType(name =“”)公共类usAddress {…}<!——usAddress XML Schema映射-->< xs:元名称=“usAddress”>< xs:名称>< xs:序列>< xs:元名称=“名”type=“XS:字符串”/>< xs:元名称=“街”type=“XS:字符串”/>< xs:元名称=“城市型”=“XS:字符串”/>< xs:元名称=“国家”type=“XS:字符串”/>< xs:元名称=“拉链”type=“XS:十进制”/>< / xs:序列>< / xs:名称>< / xs:元>
例4:属性映射到一个anonmyous型局部元素。
/ /例如:代码片段公共类发票usAddress地址;…}@ XmlType(name =“”)公共类usAddress {…}}<!——usAddress XML Schema映射-->< xs:complexType名称=“发票”>< xs:序列>< xs:元名称=“addr”>< xs:名称>< xs:元名称=“名称”,类型=“XS:字符串”/>< xs:元名称=“城市”,类型为“xs:字符串”/>< xs:元名称=“城市型”=“XS:字符串”/>< xs:元名称=“国家”type=“XS:字符串”/>< xs:元名称=“拉链”type=“XS:十进制”/>< / xs:名称>…< / xs:序列>< / xs:名称>
例5:属性映射到匿名类型的属性。
/ /例如:代码片段公共类项目{公共字符串名称;@ XmlAttribute公共usprice价格;}匿名简单类型的映射类。@ XmlType(name =“”)公共课usprice {@ XmlValue公共java.math.bigdecimal价格;}<!——例如:XML模式片段- >< xs:complexType名称=“项”>< xs:序列>< xs:元名称=“名”type=“XS:字符串”/>< xs:属性名=“价格”>< xs:简单类型>< xs:约束库=“XS:十进制”/>< / xs:简单类型>< / xs:属性>< / xs:序列>< / xs:名称>
例6:定义一个factoryclass和工厂方法模式
@ XmlType(name=“usaddresstype”,factoryclass = USAddressFactory.class,工厂方法模式=“getusaddress”)公共类usAddress {私有字符串城市;私有字符串名称;私有字符串状态;私人字符串街;私人诠释拉链;公共usAddress(String name,串街串城,字符串的状态,ZIP){ intthis.name =名称;this.street =街;this.city =城市;this.state =状态;this.zip =邮编;}}公共课usaddressfactory {公共静态usAddress getusaddress() {返回寄存器对应(“Mark Baker”、“23榆树街”,“Dayton”,“哦”,90952);}
例7:定义工厂方法模式和使用默认的factoryclass
@ XmlType(name=“usaddresstype”,工厂方法模式=“getnewinstance”)公共类usAddress {私有字符串城市;私有字符串名称;私有字符串状态;私人字符串街;私人诠释拉链;私人usaddress() { }公共静态usAddress getnewinstance() {返回新的usaddress();}}
XmlElement
,
XmlAttribute
,
XmlValue
,
XmlSchema
Modifier and Type | Optional Element and Description |
---|---|
类 |
factoryClass
包含一个无参数的工厂方法创建该类的实例的类。
|
String |
factoryMethod
一个无参数的工厂方法在
factoryClass factoryclass()指定类的名称。
|
String |
name
映射类映射的XML模式类型的名称。
|
String |
namespace
XML架构类型的目标命名空间的名称。
|
String[] |
propOrder
指定当类被映射到XML架构复杂类型时,指定XML架构元素的顺序。
|
public abstract String name
public abstract String[] propOrder
见表proporder如何影响类的映射
的proporder列表是在类JavaBean属性名称。列表中的每个名称是一个java的JavaBean属性标识符的名称。在JavaBean属性的排列顺序是以XML架构元素的JavaBean属性映射。
所有的JavaBean属性映射到XML架构元素必须上市。
一个JavaBean属性或字段列在proporder不能瞬时或注释的@XmlTransient。
默认的排序是由@ XmlAccessorOrder
JavaBean属性的确定。
public abstract String namespace
public abstract 类 factoryClass
如果factoryClass是DEFAULT.class和factoryMethod是”,那么就没有静态工厂方法。
如果factoryClass是DEFAULT.class和factoryMethod不”,然后factoryMethod是这个类的一个静态工厂方法的名称。
如果factoryClass不default.class,然后factoryMethod不得”,必须是一个静态工厂方法中指定的名称factoryClass。
public abstract String factoryMethod
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.