JAXB uses an object factory to provide a mechanism for instantiating instances of JAXB generated constructs. The object factory contains methods for instantiating all of the XML schema defined constructs in the package's scope. The only exception is that enumerations do not get a creation method in the object factory.
For each Java class generated to implement an XML schema complex type, the object factory contains a method for creating an instance of the class. This method takes the form:
typeName
createtypeName
();
For example, if your schema contained a complex type named widgetType
, FUSE Services Framework generates a
class called WidgetType
to implement it. Example 10.5 shows
the generated creation method in the object factory.
Example 10.5. Complex Type Object Factory Entry
public class ObjectFactory { ... WidgetType createWidgetType() { return new WidgetType(); } ... }
For elements that are declared in the schema's global scope, FUSE Services Framework inserts a factory method into the object factory.
As discussed in Using XML Elements, XML Schema elements are mapped to
JAXBElement<T>
objects. The creation method takes the form:
public JAXBElement<elementType
> createelementName
(elementType
value);
For example if you have an element named comment
of type xsd:string,
FUSE Services Framework generates the object factory method shown in Example 10.6
Example 10.6. Element Object Factory Entry
public class ObjectFactory { ... @XmlElementDecl(namespace = "...", name = "comment") public JAXBElement<String> createComment(String value) { return new JAXBElement<String>(_Comment_QNAME, String.class, null, value); } ... }