Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping/From Schema"

m (Bootstrapping from XML Schema (XSD))
m (Bootstrapping from XML Schema (XSD))
Line 29: Line 29:
  
 
You can pass the XML Schema to DynamicJAXBContextFactory by using:
 
You can pass the XML Schema to DynamicJAXBContextFactory by using:
*InputStream
+
*'''InputStream'''
*Node
+
*'''Node'''
*Source
+
*'''Source'''
 +
 
 +
The following example demonstrates these methods:
 +
<source lang="java">
 +
 
 +
/**
 +
* Create a DynamicJAXBContext, using XML Schema as the metadata source.
 +
*
 +
* @param schemaStream
 +
*      java.io.InputStream from which to read the XML Schema.
 +
* @param resolver
 +
*      An org.xml.sax.EntityResolver, used to resolve schema imports.  Can be null.
 +
* @param classLoader
 +
*      The application's current class loader, which will be used to first lookup
 +
*      classes to see if they exist before new DynamicTypes are generated.  Can be
 +
*      null, in which case Thread.currentThread().getContextClassLoader() will be used.
 +
* @param properties
 +
*      Map of properties to use when creating a new DynamicJAXBContext.  Can be null.
 +
*
 +
* @return
 +
*      A new instance of DynamicJAXBContext.
 +
*
 +
* @throws JAXBException
 +
*      if an error was encountered while creating the DynamicJAXBContext.
 +
*/
 +
public static DynamicJAXBContext createContextFromXSD(java.io.InputStream schemaStream, EntityResolver resolver,
 +
  ClassLoader classLoader, Map<String, ?> properties) throws JAXBException
 +
 
 +
public static DynamicJAXBContext createContextFromXSD(org.w3c.dom.Node schemaDOM, EntityResolver resolver,
 +
  ClassLoader classLoader, Map<String, ?> properties) throws JAXBException
 +
 
 +
public static DynamicJAXBContext createContextFromXSD(javax.xml.transform.Source schemaSource, EntityResolver resolver,
 +
  ClassLoader classLoader, Map<String, ?> properties) throws JAXBException
 +
 
 +
</source>
  
 
==Importing other Schemas / EntityResolvers==
 
==Importing other Schemas / EntityResolvers==

Revision as of 09:28, 3 January 2011

EclipseLink MOXy

Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse Source

Specifying Bootstrapping from an XML Schema

As with conventional JAXB, the first step is to create a JAXBContext. This is achieved by use of the DynamicJAXBContextFactory class. A DynamicJAXBContext cannot be instantiated directly; it must be created through the factory API.

A DynamicJAXBContext can be created from:

  • an XML Schema file (XSD)
  • the EclipseLink OXM metadata file
  • an EclipseLink Project specified in the EclipseLink sessions.xml file


Bootstrapping from XML Schema (XSD)

With EclipseLink MOXy, you can provide an existing XML schema from which to create a DynamicJAXBContext. EclipseLink will parse the schema and generate DynamicTypes for each complex type.

EclipseLink MOXy uses Sun's XJC (XML-to-Java Compiler) APIs to parse the schema into an in-memory representation and generate DynamicTypes and Mappings.

Idea.png
When bootstrapping from XSD, you will need to include jaxb-xjc.jar (from the JAXB reference implementation) on your CLASSPATH.



You can pass the XML Schema to DynamicJAXBContextFactory by using:

  • InputStream
  • Node
  • Source

The following example demonstrates these methods:

/**
 * Create a DynamicJAXBContext, using XML Schema as the metadata source.
 *
 * @param schemaStream
 *      java.io.InputStream from which to read the XML Schema.
 * @param resolver
 *      An org.xml.sax.EntityResolver, used to resolve schema imports.  Can be null.
 * @param classLoader
 *      The application's current class loader, which will be used to first lookup
 *      classes to see if they exist before new DynamicTypes are generated.  Can be
 *      null, in which case Thread.currentThread().getContextClassLoader() will be used.
 * @param properties
 *      Map of properties to use when creating a new DynamicJAXBContext.  Can be null.
 *
 * @return
 *      A new instance of DynamicJAXBContext.
 *
 * @throws JAXBException
 *      if an error was encountered while creating the DynamicJAXBContext.
 */
public static DynamicJAXBContext createContextFromXSD(java.io.InputStream schemaStream, EntityResolver resolver,
   ClassLoader classLoader, Map<String, ?> properties) throws JAXBException
 
public static DynamicJAXBContext createContextFromXSD(org.w3c.dom.Node schemaDOM, EntityResolver resolver,
   ClassLoader classLoader, Map<String, ?> properties) throws JAXBException
 
public static DynamicJAXBContext createContextFromXSD(javax.xml.transform.Source schemaSource, EntityResolver resolver,
   ClassLoader classLoader, Map<String, ?> properties) throws JAXBException

Importing other Schemas / EntityResolvers

Customizing Generated Mappings with EclipseLink Metadata


Eclipselink-logo.gif
Version: 2.2.0 - DRAFT
Other versions...

Back to the top