Module org.eclipse.persistence.core
Class Context<ABSTRACT_SESSION extends CoreAbstractSession,DESCRIPTOR extends Descriptor<?,?,?,?,?,NAMESPACE_RESOLVER,?,?,?,?>,FIELD extends Field,NAMESPACE_RESOLVER extends NamespaceResolver,PROJECT extends CoreProject,SESSION extends CoreSession,SESSION_EVENT_LISTENER extends CoreSessionEventListener>
java.lang.Object
org.eclipse.persistence.internal.oxm.Context<ABSTRACT_SESSION,DESCRIPTOR,FIELD,NAMESPACE_RESOLVER,PROJECT,SESSION,SESSION_EVENT_LISTENER>
- Direct Known Subclasses:
XMLContext
public abstract class Context<ABSTRACT_SESSION extends CoreAbstractSession,DESCRIPTOR extends Descriptor<?,?,?,?,?,NAMESPACE_RESOLVER,?,?,?,?>,FIELD extends Field,NAMESPACE_RESOLVER extends NamespaceResolver,PROJECT extends CoreProject,SESSION extends CoreSession,SESSION_EVENT_LISTENER extends CoreSessionEventListener>
extends Object
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Context.ContextState<ABSTRACT_SESSION extends CoreAbstractSession,
DESCRIPTOR extends Descriptor, PROJECT extends CoreProject, SESSION extends CoreSession, SESSION_EVENT_LISTENER extends CoreSessionEventListener> -
Field Summary
Modifier and TypeFieldDescription -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T> T
createByXPath
(Object parentObject, String xPath, NAMESPACE_RESOLVER namespaceResolver, Class<T> returnType) Create a new object instance for a given XPath, relative to the parentObject.protected abstract FIELD
createField
(String path) abstract Marshaller
abstract Unmarshaller
getDescriptor
(QName qName) INTERNAL: Return the Descriptor with the default root mapping matching the QName parameter.getDescriptor
(XPathQName xpathQName) INTERNAL: Return the Descriptor with the default root mapping matching the XPathQName parameter.getDescriptorByGlobalType
(XPathFragment xPathFragment) INTERNAL: Return the Descriptor mapped to the global type matching the XPathFragment parameter.INTERNAL:getSession
(DESCRIPTOR descriptor) getSession
(Class<?> clazz) INTERNAL: Return the session corresponding to this class.getSession
(Object object) INTERNAL: Return the session corresponding to this object.<T> T
getValueByXPath
(Object object, String xPath, NAMESPACE_RESOLVER namespaceResolver, Class<T> returnType) Query the object model based on the corresponding document.abstract boolean
INTERNAL: Return true if any session held onto by this context has a document preservation policy that requires unmarshalling from a Node.void
setValueByXPath
(Object object, String xPath, NAMESPACE_RESOLVER namespaceResolver, Object value) Set values in the object model based on the corresponding document.
-
Field Details
-
contextState
protected volatile Context.ContextState<ABSTRACT_SESSION extends CoreAbstractSession,DESCRIPTOR extends Descriptor<?, contextState?, ?, ?, ?, NAMESPACE_RESOLVER, ?, ?, ?, ?>, PROJECT extends CoreProject, SESSION extends CoreSession, SESSION_EVENT_LISTENER extends CoreSessionEventListener>
-
-
Constructor Details
-
Context
public Context()
-
-
Method Details
-
createByXPath
public <T> T createByXPath(Object parentObject, String xPath, NAMESPACE_RESOLVER namespaceResolver, Class<T> returnType) Create a new object instance for a given XPath, relative to the parentObject.- Type Parameters:
T
- The return type of this method corresponds to the returnType parameter.- Parameters:
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.- Returns:
- An instance of the Java class mapped to the supplied return type, or null if no result was found.
-
createField
-
createMarshaller
-
createUnmarshaller
-
getDescriptor
INTERNAL: Return the Descriptor with the default root mapping matching the QName parameter. -
getDescriptor
INTERNAL: Return the Descriptor with the default root mapping matching the XPathQName parameter. -
getDescriptorByGlobalType
INTERNAL: Return the Descriptor mapped to the global type matching the XPathFragment parameter. -
getSession
INTERNAL: Return the session corresponding to this class. Since the class may be mapped by more that one of the projects used to create the Context, this method will return the first match. -
getSession
INTERNAL: -
getSession
-
getSession
INTERNAL: Return the session corresponding to this object. Since the object may be mapped by more that one of the projects used to create the Context, this method will return the first match. -
getValueByXPath
public <T> T getValueByXPath(Object object, String xPath, NAMESPACE_RESOLVER namespaceResolver, Class<T> returnType) Query the object model based on the corresponding document. The following pairings are equivalent:
Return the Customer's IDInteger id = context.getValueByXPath(customer, "@id", null, Integer.class); Integer id = customer.getId();
Return the Customer's NameString name = context.getValueByXPath(customer, "ns:personal-info/ns:name/text()", null, String.class); String name = customer.getName();
Return the Customer's AddressAddress address = context.getValueByXPath(customer, "ns:contact-info/ns:address", aNamespaceResolver, Address.class); Address address = customer.getAddress();
Return all the Customer's PhoneNumbersList phoneNumbers = context.getValueByXPath(customer, "ns:contact-info/ns:phone-number", aNamespaceResolver, List.class); List phoneNumbers = customer.getPhoneNumbers();
Return the Customer's second PhoneNumberPhoneNumber phoneNumber = context.getValueByXPath(customer, "ns:contact-info/ns:phone-number[2]", aNamespaceResolver, PhoneNumber.class); PhoneNumber phoneNumber = customer.getPhoneNumbers().get(1);
Return the base objectCustomer customer = context.getValueByXPath(customer, ".", aNamespaceResolver, Customer.class); Customer customer = customer;
- Type Parameters:
T
- The return type of this method corresponds to the returnType parameter.- Parameters:
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.- Returns:
- The object corresponding to the XPath or null if no result was found.
-
hasDocumentPreservation
public abstract boolean hasDocumentPreservation()INTERNAL: Return true if any session held onto by this context has a document preservation policy that requires unmarshalling from a Node. -
setValueByXPath
public void setValueByXPath(Object object, String xPath, NAMESPACE_RESOLVER namespaceResolver, Object value) Set values in the object model based on the corresponding document. The following pairings are equivalent:
Set the Customer's IDcontext.setValueByXPath(customer, "@id", null, Integer.valueOf(123)); customer.setId(Integer.valueOf(123));
Set the Customer's Namecontext.setValueByXPath(customer, "ns:personal-info/ns:name/text()", aNamespaceResolver, "Jane Doe"); customer.setName("Jane Doe");
Set the Customer's Addresscontext.setValueByXPath(customer, "ns:contact-info/ns:address", aNamespaceResolver, anAddress); customer.setAddress(anAddress);
Set the Customer's PhoneNumberscontext.setValueByXPath(customer, "ns:contact-info/ns:phone-number", aNamespaceResolver, phoneNumbers); customer.setPhoneNumbers(phoneNumbers);
Set the Customer's second PhoneNumbercontext.setValueByXPath(customer, "ns:contact-info/ns:phone-number[2]", aNamespaceResolver, aPhoneNumber); customer.getPhoneNumbers().get(1);
- Parameters:
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.
-