|
EclipseLink 2.3.2, build 'v20111125-r10461' API Reference | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory
public class DynamicJAXBContextFactory
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
Field Summary | |
---|---|
static java.lang.String |
ENTITY_RESOLVER_KEY
|
static java.lang.String |
EXTERNAL_BINDINGS_KEY
|
static java.lang.String |
SCHEMAMETADATA_CLASS_NAME
|
static java.lang.String |
XML_SCHEMA_KEY
|
Constructor Summary | |
---|---|
DynamicJAXBContextFactory()
|
Method Summary | |
---|---|
static DynamicJAXBContext |
createContext(java.lang.Class<?>[] classes,
java.util.Map<java.lang.String,java.lang.Object> properties)
Unsupported Operation. |
static DynamicJAXBContext |
createContext(java.lang.String contextPath,
java.lang.ClassLoader classLoader,
java.util.Map<java.lang.String,java.lang.Object> properties)
Create a DynamicJAXBContext, using either an XML Schema, EclipseLink OXM file, or EclipseLink sessions.xml as the metadata source. |
static DynamicJAXBContext |
createContextFromOXM(java.lang.ClassLoader classLoader,
java.util.Map<java.lang.String,?> properties)
Create a DynamicJAXBContext, using an EclipseLink OXM file as the metadata source. |
static DynamicJAXBContext |
createContextFromXSD(java.io.InputStream schemaStream,
org.xml.sax.EntityResolver resolver,
java.lang.ClassLoader classLoader,
java.util.Map<java.lang.String,?> properties)
Create a DynamicJAXBContext, using XML Schema as the metadata source. |
static DynamicJAXBContext |
createContextFromXSD(org.w3c.dom.Node schemaDOM,
org.xml.sax.EntityResolver resolver,
java.lang.ClassLoader classLoader,
java.util.Map<java.lang.String,java.lang.Object> properties)
Create a DynamicJAXBContext, using XML Schema as the metadata source. |
static DynamicJAXBContext |
createContextFromXSD(javax.xml.transform.Source schemaSource,
org.xml.sax.EntityResolver resolver,
java.lang.ClassLoader classLoader,
java.util.Map<java.lang.String,java.lang.Object> properties)
Create a DynamicJAXBContext, using XML Schema as the metadata source. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String XML_SCHEMA_KEY
public static final java.lang.String ENTITY_RESOLVER_KEY
public static final java.lang.String EXTERNAL_BINDINGS_KEY
public static final java.lang.String SCHEMAMETADATA_CLASS_NAME
Constructor Detail |
---|
public DynamicJAXBContextFactory()
Method Detail |
---|
public static DynamicJAXBContext createContext(java.lang.String contextPath, java.lang.ClassLoader classLoader, java.util.Map<java.lang.String,java.lang.Object> properties) throws JAXBException
-- Context Creation From XML Schema --
The properties map must contain the following key/value pairs:
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 JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, which can have several possible values:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream iStream = classLoader.getResourceAsStream("resource/eclipselink-oxm.xml"); Map<String, Object> properties = new HashMap<String, Object>(); properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, 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.
JAXBException
- if an error was encountered while creating the DynamicJAXBContext.public static DynamicJAXBContext createContext(java.lang.Class<?>[] classes, java.util.Map<java.lang.String,java.lang.Object> properties) throws JAXBException
JAXBException
JAXBContext
public static DynamicJAXBContext createContextFromXSD(org.w3c.dom.Node schemaDOM, org.xml.sax.EntityResolver resolver, java.lang.ClassLoader classLoader, java.util.Map<java.lang.String,java.lang.Object> properties) throws JAXBException
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.
JAXBException
- if an error was encountered while creating the DynamicJAXBContext.public static DynamicJAXBContext createContextFromXSD(java.io.InputStream schemaStream, org.xml.sax.EntityResolver resolver, java.lang.ClassLoader classLoader, java.util.Map<java.lang.String,?> properties) throws JAXBException
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.
JAXBException
- if an error was encountered while creating the DynamicJAXBContext.public static DynamicJAXBContext createContextFromXSD(javax.xml.transform.Source schemaSource, org.xml.sax.EntityResolver resolver, java.lang.ClassLoader classLoader, java.util.Map<java.lang.String,java.lang.Object> properties) throws JAXBException
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.
JAXBException
- if an error was encountered while creating the DynamicJAXBContext.public static DynamicJAXBContext createContextFromOXM(java.lang.ClassLoader classLoader, java.util.Map<java.lang.String,?> properties) throws JAXBException
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 JAXBContext.ECLIPSELINK_OXM_XML_KEY, which can have several possible values:
JAXBException
- if an error was encountered while creating the DynamicJAXBContext.
|
EclipseLink 2.3.2, build 'v20111125-r10461' API Reference | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |