Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/Development/2.1/DynamicMOXy/296967/BootstrapFromOXM/ObjectFactory"
(→Why is ObjectFactory needed?) |
|||
Line 70: | Line 70: | ||
</source> | </source> | ||
− | In standard static EclipseLink JAXB, when processing annotations we will look at the ObjectFactory, see the <tt>XmlElementDecl</tt> annotation, and set the Person Descriptor's default root element to be "individuo". | + | In standard static EclipseLink JAXB, when processing annotations we will look at the <tt>ObjectFactory</tt>, see the <tt>XmlElementDecl</tt> annotation, and set the Person Descriptor's default root element to be "individuo". |
== The Dynamic Problem == | == The Dynamic Problem == |
Revision as of 14:57, 2 September 2010
Contents
Supporting ObjectFactory in Dynamic JAXB
Background
In standard JAXB, when classes are generated from a schema, an ObjectFactory class is also created, with methods to create new instances of all types in the schema, etc. From the JAXB 2.2 spec:
The ObjectFactory is home to the XmlRegistry and XmlElementDecl annotations
Why is ObjectFactory needed?
Consider the following XSD:
<?xml version="1.0" encoding="UTF-8"?> <xs:schema ...> <xs:element name="individuo" type="myns:person"/> <xs:complexType name="person"> <xs:sequence> <xs:element name="name" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:schema>
In this case, the user has a complex type called "Person" but they would like the resulting XML to use "individuo" as its XML element name.
In standard JAXB we would get a ObjectFactory that looks like this:
@XmlRegistry public class ObjectFactory { private final static QName _Individuo_QNAME = new QName("myNamespace", "individuo"); public ObjectFactory() {} public Person createPerson() { return new Person(); } @XmlElementDecl(namespace = "myNamespace", name = "individuo") public JAXBElement<Person> createIndividuo(Person value) { return new JAXBElement<Person>(_Individuo_QNAME, Person.class, null, value); } }
In standard static EclipseLink JAXB, when processing annotations we will look at the ObjectFactory, see the XmlElementDecl annotation, and set the Person Descriptor's default root element to be "individuo".
The Dynamic Problem
Bootstrapping from XSD
Bootstrapping from OXM