|
|
(48 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | {{EclipseLink_UserGuide
| + | See http://www.eclipse.org/eclipselink/documentation/2.4/moxy/dynamic_jaxb003.htm |
− | |info=y
| + | |
− | |eclipselink=y
| + | |
− | |eclipselinktype=MOXy
| + | |
− | |api=y
| + | |
− | |apis= * [http://www.eclipse.org/eclipselink/api/2.1/index.html?org/eclipse/persistence/jaxb/JAXBContextFactory.html *.jaxb.JAXBContextFactory]
| + | |
− | |toc=y
| + | |
− | }}
| + | |
− | | + | |
− | =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.
| + | |
− | <div style="margin-left:40px;width:65%">
| + | |
− | | + | |
− | {{tip||When bootstrapping from XSD, you will need to include <tt>jaxb-xjc.jar</tt> (from the JAXB reference implementation) on your <tt>CLASSPATH</tt>.}}
| + | |
− | | + | |
− | </div>
| + | |
− | | + | |
− | | + | |
− | You can pass the XML Schema to DynamicJAXBContextFactory by using:
| + | |
− | *'''InputStream'''
| + | |
− | *'''Node'''
| + | |
− | *'''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==
| + | |
− | *http://wiki.eclipse.org/EclipseLink/Development/2.1/DynamicMOXy/296967/Documentation#Importing_other_Schemas_.2F_EntityResolvers
| + | |
− | | + | |
− | ==Customizing Generated Mappings with EclipseLink Metadata ==
| + | |
− | *http://wiki.eclipse.org/EclipseLink/Development/2.1/DynamicMOXy/296967/Documentation#Customizing_Generated_Mappings_with_EclipseLink_Metadata
| + | |
− | | + | |
− | | + | |
− | | + | |
− | {{EclipseLink_MOXy
| + | |
− | |next= [[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping/Single Project|From a Single Project]]
| + | |
− | |previous= [[EclipseLink/UserGuide/MOXy/Runtime/Specifying_the_EclipseLink_Runtime/Using_DynamicEntities|Specying Dynamic JAXB Runtime]]
| + | |
− | |up= [[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping_Dynamic|Dynamic JAXB Bootstrapping]]
| + | |
− | |version=2.2.0 - DRAFT}}
| + | |