The factoryMethod
J
2
S
-
XML
T
YPE
E
XAMPLE
75
In this example a factory class provides zero arg factory methods for several
classes. The @XmlType annotation on class
OrderContext
references the fac-
tory class. The unmarshaller will use the identified factory method in this class.
public class OrderFormsFactory {
public OrderContext newOrderInstance() {
return new OrderContext()
}
public PurchaseOrderType newPurchaseOrderType() {
return new newPurchaseOrderType();
}
}
@XmlType(name="oContext", factoryClass="OrderFormsFactory",
factoryMethod="newOrderInstance")
public class OrderContext {
public OrderContext(){ ..... }
}
In this example, a factory method is defined in a class, which also contains a
standard class constructure. Because the
factoryMethod
value is defined and no
factoryClass
is defined, the factory method
newOrderInstance
is used during
unmarshalling.
@XmlType(name="oContext", factoryMethod="newOrderInstance")
public class OrderContext {
public OrderContext(){ ..... }
public OrderContext newOrderInstance() {
return new OrderContext();
}
}