The classLoader parameter is your application's current class loader, and will be used to first lookup classes to see if they exist before new DynamicTypes are generated. In most cases null can be passed for this parameter, and Thread.currentThread().getContextClassLoader() will be used instead.

+

+

==Configuration Options==

+

This is where you specify the standard EclipseLink MOXy options. One such option is the externalize metadata, see[[EclipseLink/Examples/MOXy/EclipseLink-OXM.XML | Using EclipseLink MOXy's XML Mapping (eclipselink-oxm.xml)]].

+

+

==Next Steps==

+

Next we will use this metadata to load instances of DynamicEntity from XML, see [[EclipseLink/Examples/MOXy/Dynamic/XmlToDynamicEntity|XML to DynamicEntity]].

Latest revision as of 12:23, 24 June 2010

Contents

Overview

In this example you will learn how to bootstrap a dynamic JAXBContext from an XML Schema.

Bootstrap from an XML Schema

The DynamicJAXBContextFactory is used to create a dynamic JAXBContext. The createContextFromXSD method can be used to bootstrap a DynamicJAXBContext from an XML Schema. The first parameter represents the XML schema itself and must be in one of the following forms: java.io.InputStream, org.w3c.dom.Node, or javax.xml.transform.Source.

Handling Schema Import/Includes

If the XML Schema that you wish to use to bootstrap contains imports of other schemas, then you must configure an org.xml.sax.EntityResolver that will resolve the locations of the imported schemas, and pass the EntityResolver to DynamicJAXBContextFactory.

Taking our Customer / Address example, let's say that we wish to define these two types in their own schemas:

Internal Exception: org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema
document '<imported-schema-name>', because 1) could not find the document;2) the document could
not be read;3) the root element of the document is not <xsd:schema>.

then you should try disabling XJC's "schema correctness check" by setting the following Java property:

Specifying a ClassLoader

The classLoader parameter is your application's current class loader, and will be used to first lookup classes to see if they exist before new DynamicTypes are generated. In most cases null can be passed for this parameter, and Thread.currentThread().getContextClassLoader() will be used instead.