background image

Define schema element

<< Java-toSchema Examples | Identical schema content >>
<< Java-toSchema Examples | Identical schema content >>
J
2
S
-
XML
A
CCESSOR
O
RDER
E
XAMPLE
67
pOrder, to define schema element ordering for applications that need to be
portable across JAXB Providers.
The @XmlAccessorOrder annotation imposes one of two element ordering algo-
rithms, AccessorOrder.UNDEFINED or AccessorOrder.ALPHABETICAL.
AccessorOrder.UNDEFINED is the default setting. The order is dependent on
the system's reflection implementation.
AccessorOrder.ALPHABETICAL
orders
the
elements
in
lexicographic
order
as
determined
by
java.lang.String.CompareTo(String anotherString)
.
You can define the @XmlAccessorOrder annotation for annotation type Ele-
mentType.PACKAGE on a class object. When the @XmlAccessorOrder anno-
tation 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 innermost (class) annotation takes precedence over the
outer
annotation.
For
example,
if
@XmlAccessorOrder(Accesso-
rOrder.ALPHABETICAL) is defined on a package and @XmlAccesso-
rOrder(AccessorOrder.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.
The @XmlType annotation can be defined for a class. The annotation element
propOrder() in the @XmlType annotation allows you to specify the content
order in the generated schema type. When you use the @XmlType.propOrder
annotation 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 that you want to keep out of 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 the @XmlType.propOrder annotation, it takes
precedence over any active @XmlAccessorOrder annotation on the class or
package.
If the @XmlAccessorOrder and @XmlType.propOrder(A, B, ...)
annotations are specified on a class, the propOrder always takes precedence
regardless of the order of the annontation statements. For example, in the code