public class DynamicJAXBContextFactory extends Object
DynamicJAXBContextFactory allows the user to create a DynamicJAXBContext without having realized Java classes available on the classpath. During context creation, the user's metadata will be analyzed, and in-memory classes will be generated.
Objects that are returned by EclipseLink unmarshal methods will be subclasses of DynamicEntity. DynamicEntities offer a simple get(propertyName) / set(propertyName, propertyValue) API to manipulate their data.
Example:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream iStream = classLoader.getResourceAsStream("resource/MySchema.xsd");
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(DynamicJAXBContextFactory.XML_SCHEMA_KEY, iStream);
DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("org.example", classLoader, properties);
DynamicEntity employee = jaxbContext.newDynamicEntity("org.example.Employee");
employee.set("firstName", "Bob");
employee.set("lastName", "Barker");
jaxbContext.createMarshaller().(employee, System.out);
JAXBContext
,
DynamicJAXBContext
,
DynamicEntity
,
DynamicType
Modifier and Type | Field and Description |
---|---|
static String |
ENTITY_RESOLVER_KEY |
static String |
EXTERNAL_BINDINGS_KEY |
static String |
SCHEMAMETADATA_CLASS_NAME |
static String |
XML_SCHEMA_KEY |
Constructor and Description |
---|
DynamicJAXBContextFactory() |
Modifier and Type | Method and Description |
---|---|
static DynamicJAXBContext |
createContext(Class<?>[] classes,
Map<String,Object> properties)
Unsupported Operation.
|
static DynamicJAXBContext |
createContext(String contextPath,
ClassLoader classLoader,
Map<String,Object> properties)
Create a
DynamicJAXBContext , using either an XML Schema, EclipseLink OXM file,
or EclipseLink sessions.xml as the metadata source. |
static DynamicJAXBContext |
createContextFromOXM(ClassLoader classLoader,
Map<String,?> properties)
Create a
DynamicJAXBContext , using an EclipseLink OXM file as the metadata source. |
static DynamicJAXBContext |
createContextFromXSD(InputStream schemaStream,
EntityResolver resolver,
ClassLoader classLoader,
Map<String,?> properties)
Create a
DynamicJAXBContext , using XML Schema as the metadata source. |
static DynamicJAXBContext |
createContextFromXSD(Node schemaDOM,
EntityResolver resolver,
ClassLoader classLoader,
Map<String,Object> properties)
Create a
DynamicJAXBContext , using XML Schema as the metadata source. |
static DynamicJAXBContext |
createContextFromXSD(Source schemaSource,
EntityResolver resolver,
ClassLoader classLoader,
Map<String,Object> properties)
Create a
DynamicJAXBContext , using XML Schema as the metadata source. |
public static final String XML_SCHEMA_KEY
public static final String ENTITY_RESOLVER_KEY
public static final String EXTERNAL_BINDINGS_KEY
public static final String SCHEMAMETADATA_CLASS_NAME
public static DynamicJAXBContext createContext(String contextPath, ClassLoader classLoader, Map<String,Object> properties) throws jakarta.xml.bind.JAXBException
DynamicJAXBContext
, using either an XML Schema, EclipseLink OXM file,
or EclipseLink sessions.xml
as the metadata source. This creation method will be
called if the user calls the newInstance()
method on jakarta.xml.bind.JAXBContext
,
and has specified jakarta.xml.bind.JAXBContextFactory=org.eclipse.persistence.jaxb.DynamicJAXBContextFactory
in their
jaxb.properties
file.-- Context Creation From XML Schema --
The properties
map must contain the following key/value pairs:
org.w3c.dom.Node
, javax.xml.transform.Source
, or java.io.InputStream
pointing to the XML Schema
org.xml.sax.EntityResolver
, used to resolve schema imports. Can be null.
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream iStream = classLoader.getResourceAsStream("resource/MySchema.xsd"); Map<String, Object> properties = new HashMap<String, Object>(); properties.put(DynamicJAXBContextFactory.XML_SCHEMA_KEY, iStream); DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("org.example", classLoader, properties); DynamicEntity emp = jaxbContext.newDynamicEntity("org.example.Employee"); ...Context Creation From EclipseLink OXM:
The properties
map must contain the key JAXBContextProperties.OXM_METADATA_SOURCE, which can have
several possible values:
java.io.File
, java.io.InputStream
, java.io.Reader
, java.net.URL
,javax.xml.stream.XMLEventReader
, javax.xml.stream.XMLStreamReader
, javax.xml.transform.Source
,org.w3c.dom.Node
, or org.xml.sax.InputSource
.
List
of objects from the set above.
Map<String, Object>
, where String
is a package name, and Object
is the pointer to the OXM file, from the setpackage-name
element is not required in the xml-bindings
element of your OXM file.
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream iStream = classLoader.getResourceAsStream("resource/eclipselink-oxm.xml"); Map<String, Object> properties = new HashMap<String, Object>(); properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, iStream); DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("org.example", classLoader, properties); DynamicEntity emp = jaxbContext.newDynamicEntity("org.example.Employee"); ...Context Creation From EclipseLink sessions.xml:
The sessionNames
parameter is a colon-delimited list of session names within the
sessions.xml
file. Descriptors
in this session's Project
must not
have javaClass
set, but must have javaClassName
set.
Example:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("org.example", classLoader, null); DynamicEntity emp = jaxbContext.newDynamicEntity("org.example.Employee"); ...
contextPath
- A colon-delimited String
specifying the packages containing jaxb.properties
. If bootstrapping
from EclipseLink sessions.xml
, this will also be the name(s) of your sessions.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.properties
- Map of properties to use when creating a new DynamicJAXBContext
. Can be null if bootstrapping from sessions.xml.DynamicJAXBContext
.jakarta.xml.bind.JAXBException
- if an error was encountered while creating the DynamicJAXBContext
.public static DynamicJAXBContext createContext(Class<?>[] classes, Map<String,Object> properties) throws jakarta.xml.bind.JAXBException
jakarta.xml.bind.JAXBException
JAXBContext
public static DynamicJAXBContext createContextFromXSD(Node schemaDOM, EntityResolver resolver, ClassLoader classLoader, Map<String,Object> properties) throws jakarta.xml.bind.JAXBException
DynamicJAXBContext
, using XML Schema as the metadata source.schemaDOM
- org.w3c.dom.Node
representing the XML Schema.resolver
- An org.xml.sax.EntityResolver
, used to resolve schema imports. Can be null.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.properties
- Map of properties to use when creating a new DynamicJAXBContext
. Can be null.DynamicJAXBContext
.jakarta.xml.bind.JAXBException
- if an error was encountered while creating the DynamicJAXBContext
.public static DynamicJAXBContext createContextFromXSD(InputStream schemaStream, EntityResolver resolver, ClassLoader classLoader, Map<String,?> properties) throws jakarta.xml.bind.JAXBException
DynamicJAXBContext
, using XML Schema as the metadata source.schemaStream
- java.io.InputStream
from which to read the XML Schema.resolver
- An org.xml.sax.EntityResolver
, used to resolve schema imports. Can be null.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.properties
- Map of properties to use when creating a new DynamicJAXBContext
. Can be null.DynamicJAXBContext
.jakarta.xml.bind.JAXBException
- if an error was encountered while creating the DynamicJAXBContext
.public static DynamicJAXBContext createContextFromXSD(Source schemaSource, EntityResolver resolver, ClassLoader classLoader, Map<String,Object> properties) throws jakarta.xml.bind.JAXBException
DynamicJAXBContext
, using XML Schema as the metadata source.schemaSource
- javax.xml.transform.Source
from which to read the XML Schema.resolver
- An org.xml.sax.EntityResolver
, used to resolve schema imports. Can be null.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.properties
- Map of properties to use when creating a new DynamicJAXBContext
. Can be null.DynamicJAXBContext
.jakarta.xml.bind.JAXBException
- if an error was encountered while creating the DynamicJAXBContext
.public static DynamicJAXBContext createContextFromOXM(ClassLoader classLoader, Map<String,?> properties) throws jakarta.xml.bind.JAXBException
DynamicJAXBContext
, using an EclipseLink OXM file as the metadata source.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.properties
- Map of properties to use when creating a new DynamicJAXBContext
. This map must
contain a key of JAXBContextProperties.OXM_METADATA_SOURCE, which can have several possible values:
java.io.File
, java.io.InputStream
, java.io.Reader
, java.net.URL
,javax.xml.stream.XMLEventReader
, javax.xml.stream.XMLStreamReader
, javax.xml.transform.Source
,org.w3c.dom.Node
, or org.xml.sax.InputSource
.
List
of objects from the set above.
Map<String, Object>
, where String
is a package name, and Object
is the pointer to the OXM file, from the setpackage-name
element is not required in the xml-bindings
element of your OXM file.
DynamicJAXBContext
.jakarta.xml.bind.JAXBException
- if an error was encountered while creating the DynamicJAXBContext
.Copyright © 2007–2021 Eclipse.org - EclipseLink Project. All rights reserved.