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>

    • Constructor Detail

      • Context

        public Context()
    • Method Detail

      • 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

        protected abstract FIELD createField​(String path)
      • createMarshaller

        public abstract Marshaller createMarshaller()
      • createUnmarshaller

        public abstract Unmarshaller createUnmarshaller()
      • getDescriptor

        public DESCRIPTOR getDescriptor​(QName qName)
        INTERNAL: Return the Descriptor with the default root mapping matching the QName parameter.
      • getDescriptor

        public DESCRIPTOR getDescriptor​(XPathQName xpathQName)
        INTERNAL: Return the Descriptor with the default root mapping matching the XPathQName parameter.
      • getDescriptorByGlobalType

        public DESCRIPTOR getDescriptorByGlobalType​(XPathFragment xPathFragment)
        INTERNAL: Return the Descriptor mapped to the global type matching the XPathFragment parameter.
      • getSession

        public ABSTRACT_SESSION getSession​(Class<?> clazz)
        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

        public SESSION getSession()
        INTERNAL:
      • getSession

        public ABSTRACT_SESSION getSession​(Object object)
        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 ID
         Integer id = context.getValueByXPath(customer, "@id", null, Integer.class);
         Integer id = customer.getId();
        Return the Customer's Name
         String name = context.getValueByXPath(customer, "ns:personal-info/ns:name/text()", null, String.class);
         String name = customer.getName();
        Return the Customer's Address
         Address address = context.getValueByXPath(customer, "ns:contact-info/ns:address", aNamespaceResolver, Address.class);
         Address address = customer.getAddress();
        Return all the Customer's PhoneNumbers
         List phoneNumbers = context.getValueByXPath(customer, "ns:contact-info/ns:phone-number", aNamespaceResolver, List.class);
         List phoneNumbers = customer.getPhoneNumbers();
        Return the Customer's second PhoneNumber
         PhoneNumber phoneNumber = context.getValueByXPath(customer, "ns:contact-info/ns:phone-number[2]", aNamespaceResolver, PhoneNumber.class);
         PhoneNumber phoneNumber = customer.getPhoneNumbers().get(1);
        Return the base object
         Customer 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 statement
        namespaceResolver - 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 ID
         context.setValueByXPath(customer, "@id", null, Integer.valueOf(123));
         customer.setId(Integer.valueOf(123));
        Set the Customer's Name
         context.setValueByXPath(customer, "ns:personal-info/ns:name/text()", aNamespaceResolver, "Jane Doe");
         customer.setName("Jane Doe");
        Set the Customer's Address
         context.setValueByXPath(customer, "ns:contact-info/ns:address", aNamespaceResolver, anAddress);
         customer.setAddress(anAddress);
        Set the Customer's PhoneNumbers
         context.setValueByXPath(customer, "ns:contact-info/ns:phone-number", aNamespaceResolver, phoneNumbers);
         customer.setPhoneNumbers(phoneNumbers);
        Set the Customer's second PhoneNumber
         context.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 statement
        namespaceResolver - A NamespaceResolver containing the prefix/URI pairings from the XPath statement.
        value - The value to be set.