XmlType Example

The XmlType example demonstrates the use of the @XmlType annotation.
The @XmlType annotation maps a class or an enum type
to a XML Schema type.

A class must have either a public zero-argument constructor or a static
zero-argument factory method in order to be mapped by this annotation. One
of these methods is used during unmarshalling to create an instance of the
class. The factory method may reside within in a factory class or the existing
class.

There is an order of precedence as to which method is used for unmarshalling:

If a factory class is identified in the annotation, a corresponding
factory method in that class must also be identified and that method will
be used.

If a factory method is identified in the annotation but no
factory class is identified, the factory method must reside in the current
class. The factory method is used even if there is a public zero arg constructor
method present.

If no factory method is identified in the annotation, the
class must contain a public zero arg constructor method.

In this example, a factory class provides zero arg factory methods for
several classes. The @XmlType annotation on class OrderContext references the factory class. The unmarshaller will use the identified
factory method in this class.

In this example, a factory method is defined in a class, which also
contains a standard class construct. Because the factoryMethod value
is defined and no factoryClass is defined, the factory
method newOrderInstance is used during unmarshalling.