public class XMLContext extends org.eclipse.persistence.internal.oxm.Context<org.eclipse.persistence.internal.sessions.AbstractSession,XMLDescriptor,XMLField,NamespaceResolver,Project,DatabaseSession,SessionEventListener>
An XMLContext is created based on EclipseLink sessions or projects and can then used to create instances of XMLMarshaller, XMLUnmarshaller and XMLValidator.
There are constructors to create an XMLContext with a single EclipseLink project or with a String which is a single EclipseLink session name or a ':' separated list of EclipseLink session names.
Code Sample The XMLContext is thread-safe. If multiple threads accessing the same XMLContext object
request an XMLMarshaller, each will receive their own instance of XMLMarshaller, so any
state that the XMLMarshaller maintains will be unique to that process. The same is true
of instances of XMLUnmarshaller and XMLValidator.
XMLContext context = new XMLContext("mySessionName");
XMLMarshaller marshaller = context.createMarshaller();
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
XMLValidator validator = context.createValidator();
XMLMarshaller
,
XMLUnmarshaller
,
XMLValidator
org.eclipse.persistence.internal.oxm.Context.ContextState<ABSTRACT_SESSION extends org.eclipse.persistence.internal.core.sessions.CoreAbstractSession,DESCRIPTOR extends org.eclipse.persistence.internal.oxm.mappings.Descriptor,PROJECT extends CoreProject,SESSION extends CoreSession,SESSION_EVENT_LISTENER extends CoreSessionEventListener>
Constructor and Description |
---|
XMLContext(java.util.Collection projects) |
XMLContext(java.util.Collection projects,
java.lang.ClassLoader classLoader) |
XMLContext(Project project)
Create a new XMLContext based on the specified project
|
XMLContext(Project project,
java.lang.ClassLoader classLoader)
Create a new XMLContext based on the specified Project and ClassLoader.
|
XMLContext(Project project,
java.lang.ClassLoader classLoader,
java.util.Collection<SessionEventListener> sessionEventListeners)
Create a new XMLContext based on the specified Project and ClassLoader.
|
XMLContext(Project project,
java.lang.ClassLoader classLoader,
SessionEventListener sessionEventListener)
Create a new XMLContext based on the specified Project and ClassLoader.
|
XMLContext(java.lang.String sessionNames)
Create a new XMLContext based on the specified session name or list of
session names
|
XMLContext(java.lang.String sessionNames,
java.lang.ClassLoader classLoader)
Create a new XMLContext based on the specified session name or list of
session names
|
XMLContext(java.lang.String sessionNames,
java.lang.ClassLoader classLoader,
java.lang.String xmlResource)
Create a new XMLContext based on passed in session names, classloader and
session meta XML.
|
XMLContext(java.lang.String sessionNames,
java.lang.String xmlResource)
Create a new XMLContext based on passed in session names and session meta
XML.
|
Modifier and Type | Method and Description |
---|---|
void |
addDescriptorByQName(javax.xml.namespace.QName qName,
XMLDescriptor descriptor) |
void |
addSession(DatabaseSession sessionToAdd)
INTERNAL: Add and initialize a new session to the list of sessions
associated with this XMLContext.
|
void |
applyORMMetadata(org.eclipse.persistence.internal.sessions.AbstractSession ormSession)
ADVANCED:
Adjust the OXM metadata to take into account ORM mapping metadata,
|
XMLBinder |
createBinder()
Create a new XMLBinder
|
java.lang.Object |
createByQualifiedName(java.lang.String namespace,
java.lang.String typeName,
boolean isGlobalType)
Create a new object instance for a given XML namespace and name.
|
<T> T |
createByXPath(java.lang.Object parentObject,
java.lang.String xPath,
NamespaceResolver namespaceResolver,
java.lang.Class<T> returnType)
Create a new object instance for a given XPath, relative to the parentObject.
|
protected XMLField |
createField(java.lang.String path) |
XMLMarshaller |
createMarshaller()
Create a new XMLMarshaller
|
XMLUnmarshaller |
createUnmarshaller()
Create a new XMLUnmarshaller
|
XMLUnmarshaller |
createUnmarshaller(java.util.Map<java.lang.String,java.lang.Boolean> parserFeatures)
Create a new XMLUnmarshaller
Map
|
XMLValidator |
createValidator()
Create a new XMLValidator
|
XMLDescriptor |
getDescriptor(javax.xml.namespace.QName qName)
INTERNAL: Return the XMLDescriptor with the default root mapping matching
the QName parameter.
|
XMLDescriptor |
getDescriptor(org.eclipse.persistence.internal.oxm.XPathQName xpathQName)
INTERNAL: Return the XMLDescriptor with the default root mapping matching
the QName parameter.
|
XMLDescriptor |
getDescriptorByGlobalType(org.eclipse.persistence.internal.oxm.XPathFragment xPathFragment)
INTERNAL: Return the XMLDescriptor mapped to the global type matching the
XPathFragment parameter.
|
DocumentPreservationPolicy |
getDocumentPreservationPolicy(org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL:
Return the DocumentPreservationPolicy associated with this session
|
org.eclipse.persistence.internal.sessions.AbstractSession |
getReadSession(java.lang.Class clazz)
INTERNAL:
Return the session corresponding to this class.
|
org.eclipse.persistence.internal.sessions.AbstractSession |
getReadSession(java.lang.Object object)
INTERNAL: Return the session corresponding to this object.
|
org.eclipse.persistence.internal.sessions.AbstractSession |
getReadSession(XMLDescriptor xmlDescriptor)
INTERNAL:
Return the session corresponding to this XMLDescriptor.
|
org.eclipse.persistence.internal.sessions.AbstractSession |
getSession(java.lang.Class clazz)
INTERNAL: Return the session corresponding to this class.
|
DatabaseSession |
getSession(int index)
INTERNAL:
XMLContext xmlContext = new XMLContext("path0:path1"); |
org.eclipse.persistence.internal.sessions.AbstractSession |
getSession(java.lang.Object object)
INTERNAL: Return the session corresponding to this object.
|
org.eclipse.persistence.internal.sessions.AbstractSession |
getSession(XMLDescriptor xmlDescriptor)
INTERNAL: Return the session corresponding to this XMLDescriptor.
|
java.util.List |
getSessions()
INTERNAL: Return the EclipseLink session used to marshal.
|
<T> T |
getValueByXPath(java.lang.Object object,
java.lang.String xPath,
NamespaceResolver namespaceResolver,
java.lang.Class<T> returnType)
Query the object model based on the corresponding XML document.
|
org.eclipse.persistence.oxm.XMLContext.XMLContextState |
getXMLContextState()
INTERNAL: Return the XMLContextState that represents the XMLContexts
stateful information.
|
boolean |
hasDocumentPreservation()
INTERNAL:
Return true if any session held onto by this context has a document preservation
policy that requires unmarshalling from a Node.
|
void |
setupDocumentPreservationPolicy(DatabaseSession session) |
void |
setValueByXPath(java.lang.Object object,
java.lang.String xPath,
NamespaceResolver namespaceResolver,
java.lang.Object value)
Set values in the object model based on the corresponding XML document.
|
void |
setXMLContextState(org.eclipse.persistence.oxm.XMLContext.XMLContextState xcs)
INTERNAL: Set the stateful information for this XMLContext.
|
void |
storeXMLDescriptorByQName(XMLDescriptor xmlDescriptor)
INTERNAL:
|
public XMLContext(java.lang.String sessionNames)
sessionNames
- A single session name or multiple session names separated by a :public XMLContext(java.lang.String sessionNames, java.lang.ClassLoader classLoader)
sessionNames
- A single session name or multiple session names separated by a :classLoader
- classloader for loading sessions.xmlpublic XMLContext(java.lang.String sessionNames, java.lang.String xmlResource)
sessionNames
- A single session name or multiple session names separated by
a:xmlResource
- path to XML file containing session meta data to initialize
and load sessions.public XMLContext(java.lang.String sessionNames, java.lang.ClassLoader classLoader, java.lang.String xmlResource)
sessionNames
- A single session name or multiple session names separated by a :classLoader
- classloader for loading sessions.xmlxmlResource
- path to XML file containing session meta data to initialize
and load sessions.public XMLContext(Project project)
project
- An EclipseLink projectpublic XMLContext(Project project, java.lang.ClassLoader classLoader)
project
- An EclipseLink projectclassLoader
- The ClassLoader to be usedpublic XMLContext(Project project, java.lang.ClassLoader classLoader, SessionEventListener sessionEventListener)
project
- An EclipseLink projectclassLoader
- The ClassLoader to be usedsessionEventListener
- If non-null, this listener will be registered with the SessionEventManagerSessionEventListener
,
SessionEventManager
public XMLContext(Project project, java.lang.ClassLoader classLoader, java.util.Collection<SessionEventListener> sessionEventListeners)
project
- An EclipseLink projectclassLoader
- The ClassLoader to be usedsessionEventListeners
- If non-null, these listeners will be registered with the SessionEventManagerSessionEventListener
,
SessionEventManager
public XMLContext(java.util.Collection projects)
public XMLContext(java.util.Collection projects, java.lang.ClassLoader classLoader)
public org.eclipse.persistence.oxm.XMLContext.XMLContextState getXMLContextState()
public void setXMLContextState(org.eclipse.persistence.oxm.XMLContext.XMLContextState xcs)
public void addSession(DatabaseSession sessionToAdd)
public XMLUnmarshaller createUnmarshaller()
createUnmarshaller
in class org.eclipse.persistence.internal.oxm.Context<org.eclipse.persistence.internal.sessions.AbstractSession,XMLDescriptor,XMLField,NamespaceResolver,Project,DatabaseSession,SessionEventListener>
public XMLUnmarshaller createUnmarshaller(java.util.Map<java.lang.String,java.lang.Boolean> parserFeatures)
MapparserFeatures = new HashMap (1); parserFeatures.put("http://apache.org/xml/features/validation/schema/normalized-value", false); XMLUnmarshaller unmarshaller = xmlContext.createUnmarshaller(parserFeatures);
public XMLBinder createBinder()
public XMLMarshaller createMarshaller()
createMarshaller
in class org.eclipse.persistence.internal.oxm.Context<org.eclipse.persistence.internal.sessions.AbstractSession,XMLDescriptor,XMLField,NamespaceResolver,Project,DatabaseSession,SessionEventListener>
public XMLValidator createValidator()
public org.eclipse.persistence.internal.sessions.AbstractSession getReadSession(java.lang.Object object)
public org.eclipse.persistence.internal.sessions.AbstractSession getReadSession(java.lang.Class clazz)
public org.eclipse.persistence.internal.sessions.AbstractSession getReadSession(XMLDescriptor xmlDescriptor)
public java.util.List getSessions()
public DatabaseSession getSession(int index)
XMLContext xmlContext = new XMLContext("path0:path1");
DatabaseSession session = xmlContext.getSession(0); // returns session for path0
public org.eclipse.persistence.internal.sessions.AbstractSession getSession(java.lang.Object object)
getSession
in class org.eclipse.persistence.internal.oxm.Context<org.eclipse.persistence.internal.sessions.AbstractSession,XMLDescriptor,XMLField,NamespaceResolver,Project,DatabaseSession,SessionEventListener>
public org.eclipse.persistence.internal.sessions.AbstractSession getSession(java.lang.Class clazz)
getSession
in class org.eclipse.persistence.internal.oxm.Context<org.eclipse.persistence.internal.sessions.AbstractSession,XMLDescriptor,XMLField,NamespaceResolver,Project,DatabaseSession,SessionEventListener>
public org.eclipse.persistence.internal.sessions.AbstractSession getSession(XMLDescriptor xmlDescriptor)
getSession
in class org.eclipse.persistence.internal.oxm.Context<org.eclipse.persistence.internal.sessions.AbstractSession,XMLDescriptor,XMLField,NamespaceResolver,Project,DatabaseSession,SessionEventListener>
public void storeXMLDescriptorByQName(XMLDescriptor xmlDescriptor)
public XMLDescriptor getDescriptor(javax.xml.namespace.QName qName)
getDescriptor
in class org.eclipse.persistence.internal.oxm.Context<org.eclipse.persistence.internal.sessions.AbstractSession,XMLDescriptor,XMLField,NamespaceResolver,Project,DatabaseSession,SessionEventListener>
public XMLDescriptor getDescriptor(org.eclipse.persistence.internal.oxm.XPathQName xpathQName)
getDescriptor
in class org.eclipse.persistence.internal.oxm.Context<org.eclipse.persistence.internal.sessions.AbstractSession,XMLDescriptor,XMLField,NamespaceResolver,Project,DatabaseSession,SessionEventListener>
public void addDescriptorByQName(javax.xml.namespace.QName qName, XMLDescriptor descriptor)
public XMLDescriptor getDescriptorByGlobalType(org.eclipse.persistence.internal.oxm.XPathFragment xPathFragment)
getDescriptorByGlobalType
in class org.eclipse.persistence.internal.oxm.Context<org.eclipse.persistence.internal.sessions.AbstractSession,XMLDescriptor,XMLField,NamespaceResolver,Project,DatabaseSession,SessionEventListener>
public DocumentPreservationPolicy getDocumentPreservationPolicy(org.eclipse.persistence.internal.sessions.AbstractSession session)
session
- public void setupDocumentPreservationPolicy(DatabaseSession session)
public boolean hasDocumentPreservation()
hasDocumentPreservation
in class org.eclipse.persistence.internal.oxm.Context<org.eclipse.persistence.internal.sessions.AbstractSession,XMLDescriptor,XMLField,NamespaceResolver,Project,DatabaseSession,SessionEventListener>
public void applyORMMetadata(org.eclipse.persistence.internal.sessions.AbstractSession ormSession)
public <T> T getValueByXPath(java.lang.Object object, java.lang.String xPath, NamespaceResolver namespaceResolver, java.lang.Class<T> returnType)
Query the object model based on the corresponding XML document. The following pairings are equivalent:
Return the Customer's IDInteger id = xmlContext.getValueByXPath(customer, "@id", null, Integer.class); Integer id = customer.getId();Return the Customer's Name
String name = xmlContext.getValueByXPath(customer, "ns:personal-info/ns:name/text()", null, String.class); String name = customer.getName();Return the Customer's Address
Address address = xmlContext.getValueByXPath(customer, "ns:contact-info/ns:address", aNamespaceResolver, Address.class); Address address = customer.getAddress();Return all the Customer's PhoneNumbers
List phoneNumbers = xmlContext.getValueByXPath(customer, "ns:contact-info/ns:phone-number", aNamespaceResolver, List.class); List phoneNumbers = customer.getPhoneNumbers();Return the Customer's second PhoneNumber
PhoneNumber phoneNumber = xmlContext.getValueByXPath(customer, "ns:contact-info/ns:phone-number[2]", aNamespaceResolver, PhoneNumber.class); PhoneNumber phoneNumber = customer.getPhoneNumbers().get(1);Return the base object
Customer customer = xmlContext.getValueByXPath(customer, ".", aNamespaceResolver, Customer.class); Customer customer = customer;
getValueByXPath
in class org.eclipse.persistence.internal.oxm.Context<org.eclipse.persistence.internal.sessions.AbstractSession,XMLDescriptor,XMLField,NamespaceResolver,Project,DatabaseSession,SessionEventListener>
T
- The return type of this method corresponds to the returnType parameter.object
- The XPath will be executed relative to this object.xPath
- The XPath statementnamespaceResolver
- A NamespaceResolver containing the prefix/URI pairings from the XPath statement.returnType
- The return type.public void setValueByXPath(java.lang.Object object, java.lang.String xPath, NamespaceResolver namespaceResolver, java.lang.Object value)
Set values in the object model based on the corresponding XML document. The following pairings are equivalent:
Set the Customer's IDxmlContext.setValueByXPath(customer, "@id", null, new Integer(123)); customer.setId(new Integer(123));Set the Customer's Name
xmlContext.setValueByXPath(customer, "ns:personal-info/ns:name/text()", aNamespaceResolver, "Jane Doe"); customer.setName("Jane Doe");Set the Customer's Address
xmlContext.setValueByXPath(customer, "ns:contact-info/ns:address", aNamespaceResolver, anAddress); customer.setAddress(anAddress);Set the Customer's PhoneNumbers
xmlContext.setValueByXPath(customer, "ns:contact-info/ns:phone-number", aNamespaceResolver, phoneNumbers); customer.setPhoneNumbers(phoneNumbers);Set the Customer's second PhoneNumber
xmlContext.setValueByXPath(customer, "ns:contact-info/ns:phone-number[2]", aNamespaceResolver, aPhoneNumber); customer.getPhoneNumbers().get(1);
setValueByXPath
in class org.eclipse.persistence.internal.oxm.Context<org.eclipse.persistence.internal.sessions.AbstractSession,XMLDescriptor,XMLField,NamespaceResolver,Project,DatabaseSession,SessionEventListener>
object
- The XPath will be executed relative to this object.xPath
- The XPath statementnamespaceResolver
- A NamespaceResolver containing the prefix/URI pairings from the XPath statement.value
- The value to be set.public java.lang.Object createByQualifiedName(java.lang.String namespace, java.lang.String typeName, boolean isGlobalType) throws java.lang.IllegalArgumentException
namespace
- The namespace of the complex type to create a new Java instance of.typeName
- The XML type name to create a new Java instance of.isGlobalType
- True if the object to be created represents a global type, false if it
represents a global element.java.lang.IllegalArgumentException
public <T> T createByXPath(java.lang.Object parentObject, java.lang.String xPath, NamespaceResolver namespaceResolver, java.lang.Class<T> returnType)
createByXPath
in class org.eclipse.persistence.internal.oxm.Context<org.eclipse.persistence.internal.sessions.AbstractSession,XMLDescriptor,XMLField,NamespaceResolver,Project,DatabaseSession,SessionEventListener>
T
- The return type of this method corresponds to the returnType parameter.parentObject
- The XPath will be executed relative to this object.xPath
- The XPath statement.namespaceResolver
- A NamespaceResolver containing the prefix/URI pairings from the XPath statement.returnType
- The return type.protected XMLField createField(java.lang.String path)
createField
in class org.eclipse.persistence.internal.oxm.Context<org.eclipse.persistence.internal.sessions.AbstractSession,XMLDescriptor,XMLField,NamespaceResolver,Project,DatabaseSession,SessionEventListener>