-- Ordering of properties/fields
-- Synopsis
This sample demonstrates the use of annotations @XmlAccessorOrder
and @XmlType.propOrder to dictate the order in which XML content
is marshalled/unmarshaled by a Java type.
-- Details
Java to Schema maps a JavaBean's properties and fields
to an XML Schema type. The class elements are mapped
to either an XML Schema complex type or an XML Schema simple
type. The default element order for a generated schema type
is currently unspecified, because Java reflection does not
impose a return order. Lack of reliable element ordering
impacts application portability. Two annotations for defining
schema element ordering are provided for applications that
wish to remain portable across JAXB Providers, @XmlAccessorOrder
and @XmlType.propOrder.
-- @XmlAccessorOrder
@XmlAccessorOrder annotation imposes one of two element ordering
algorithms, XmlAccessOrder.UNDEFINED or XmlAccessOrder.ALPHABETICAL.
XmlAccessOrder.UNDEFINED is the default setting. The order is dependent
on the system's reflection implementation. XmlAccessOrder.ALPHABETICAL
orders the elements in lexicographic order as determined by
java.lang.String.CompareTo(String anotherString).
@XmlAccessorOrder can be defined for annotation type ElementType.PACKAGE
or on a class object. When @XmlAccessorOrder is defined on a package, the
scope of the formatting rule is active for every class in the package.
When defined on a class the rule is active on the contents of that class.
There can be multiple @XmlAccessorOrder annotations within a package.
The order of precedence is the inner most (class) annotation
takes precedence over the outter annotation. For example if
@XmlAccessorOrder(XmlAccessOrder.ALPHABETICAL) is defined on a package
and @XmlAccessorOrder(XmlAccessOrder.UNDEFINED) is defined on a class
in that package the contents of the generated schema type for the class
would be in an unspecified order and the contents of the generated schema
type for evey other class in the package would be alphabetical order.
-- @XmlType.propOrder
@XmlType can be defined for a class. The annotation element propOrder()
in @XmlType allows the specification of the content order in the generated
schema type. When @XmlType.propOrder is used on a class to specify content
order, all public properties and public fields in the class must be specified
in the parameter list. Any public property or field not desired in the parameter
list must be annotated with @XmlAttribute or @XmlTransient.
The default content order for @XmlType.propOrder is {} or {""}; not active.
In such cases the active @XmlAccessorOrder annotation takes precedence. When
class content order is specified by @XmlType.propOrder, it takes precedence
over any active @XmlAccessorOrder annotation on the class or package. If
@XmlAccessorOrder and @XmlType.propOrder(A, B, ...) annotations are specified
on a class, the propOrder always takes precedence no matter the order of
the annontation statements. For example in CODE A below the @XmlAccessorOrder
annotation preceeds @XmlType.propOrder and in CODE B @XmlType.propOrder preceeds
@XmlAccessorOrder. In both scenarios propOrder takes precedence and the identical
schema content is generated.
CODE A:
@XmlAccessorOrder(XmlAccessOrder.ALPHABETICAL)
@XmlType(propOrder={"name", "city"})
public class USAddress {
:
public String getCity() {return city;}
public void setCity(String city) {this.city = city;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
:
}
CODE B:
@XmlType(propOrder={"name", "city"})
@XmlAccessorOrder(XmlAccessOrder.ALPHABETICAL)
public class USAddress {
:
public String getCity() {return city;}
public void setCity(String city) {this.city = city;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
:
}
SCHEMA GENERATE
<xs:complexType name="usAddress">
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="city" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
-- Code example
The purchase order code example demonstrates the affects of schema content
ordering using @XmlAccessorOrder annotation at the package and class level,
and @XmlType.propOrder on a class.
Class package-info.java defines @XmlAccessorOrder to be ALPHABETICAL for
the package. The public fields shipTo and billTo in class PurchaseOrderType
will be affected in the generated schema content order by this rule. Class
USAddress defines @XmlType.propOrder on the class. This demonstates user
defined property order superseding ALPHABETICAL order in the generated schema.
The generated schema file can be found in directory schemas.
没有合适的资源?快使用搜索试试~ 我知道了~
jaxb文件包
共398个文件
html:141个
java:73个
xml:63个
4星 · 超过85%的资源 需积分: 14 31 下载量 60 浏览量
2011-08-22
09:12:04
上传
评论
收藏 8.73MB ZIP 举报
温馨提示
jaxb文件包jaxb文件包jaxb文件包jaxb文件包jaxb文件包jaxb文件包jaxb文件包jaxb文件包jaxb文件包
资源推荐
资源详情
资源评论
收起资源包目录
jaxb文件包 (398个子文件)
schemagen.bat 3KB
xjc.bat 3KB
catalog.cat 757B
catalog.cat 614B
cd 0B
default.css 5KB
stylesheet.css 1KB
XMLSchema.dtd 18KB
datatypes.dtd 8KB
nameCard.dtd 2KB
bg_titlebar.gif 4KB
d7_tab_bg.gif 1KB
sunlogo.gif 1022B
a2_corner_tr.gif 110B
corner_navblue_tr.gif 75B
inherit.gif 57B
index-all.html 186KB
Unmarshaller.html 96KB
AbstractUnmarshallerImpl.html 91KB
Marshaller.html 77KB
AbstractMarshallerImpl.html 76KB
DatatypeConverter.html 67KB
index.html 64KB
DatatypeConverterInterface.html 62KB
JAXBContext.html 52KB
catalog.html 51KB
Binder.html 45KB
JAXB.html 42KB
ValidationEventLocatorImpl.html 32KB
package-summary.html 31KB
JAXBElement.html 30KB
overview-tree.html 30KB
JAXBException.html 29KB
ValidationEventImpl.html 28KB
TypeConstraintException.html 27KB
XmlType.html 27KB
Validator.html 26KB
changelog.html 26KB
W3CDomHandler.html 25KB
AttachmentMarshaller.html 25KB
changelog2.html 24KB
PropertyException.html 22KB
XmlAnyElement.html 22KB
UnmarshalException.html 21KB
ValidationException.html 21KB
XmlElementRef.html 21KB
MarshalException.html 21KB
XmlAdapter.html 20KB
JAXBResult.html 20KB
XmlAccessType.html 20KB
XmlElementDecl.html 20KB
JAXBSource.html 20KB
NotIdentifiableEventImpl.html 20KB
ParseConversionEventImpl.html 20KB
PrintConversionEventImpl.html 20KB
package-tree.html 20KB
vendorProperties.html 20KB
XmlElement.html 19KB
xjcTask.html 19KB
AttachmentUnmarshaller.html 18KB
XmlNsForm.html 18KB
XmlSchema.html 18KB
xjc.html 18KB
XmlAccessOrder.html 18KB
ValidationEventCollector.html 17KB
NormalizedStringAdapter.html 17KB
CollapsedStringAdapter.html 17KB
vendorCustomizations.html 17KB
package-summary.html 16KB
JAXBIntrospector.html 16KB
DomHandler.html 16KB
Unmarshaller.Listener.html 16KB
XmlJavaTypeAdapter.html 16KB
ValidationEvent.html 16KB
XmlElementWrapper.html 16KB
DataBindingException.html 15KB
HexBinaryAdapter.html 15KB
DefaultValidationEventHandler.html 15KB
SchemaOutputResolver.html 15KB
XmlAttribute.html 15KB
samples.html 15KB
XmlIDREF.html 15KB
Marshaller.Listener.html 15KB
XmlElements.html 15KB
XmlRootElement.html 14KB
XmlSchemaType.html 13KB
UnmarshallerHandler.html 13KB
index.html 13KB
ValidationEventLocator.html 13KB
serialized-form.html 13KB
allclasses-frame.html 13KB
XmlAccessorType.html 13KB
ValidationEventHandler.html 12KB
XmlAccessorOrder.html 12KB
XmlEnumValue.html 12KB
XmlJavaTypeAdapter.DEFAULT.html 12KB
XmlMixed.html 12KB
constant-values.html 11KB
XmlType.DEFAULT.html 11KB
XmlSchemaType.DEFAULT.html 11KB
共 398 条
- 1
- 2
- 3
- 4
资源评论
- zhanghb_37222012-07-03可以用,不过说明也太简单啦~
小蝸牛
- 粉丝: 42
- 资源: 62
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功