Search in sources :

Example 1 with XMLFragmentMapping

use of org.eclipse.persistence.oxm.mappings.XMLFragmentMapping in project eclipselink by eclipse-ee4j.

the class SDOProperty method buildXMLFragmentMapping.

public XMLFragmentMapping buildXMLFragmentMapping(String uri) {
    XMLFragmentMapping mapping = new XMLFragmentMapping();
    mapping.setAttributeName(getName());
    mapping.setXPath(getQualifiedXPath(uri, false));
    mapping.setAttributeAccessor(new SDOFragmentMappingAttributeAccessor(this, aHelperContext));
    return mapping;
}
Also used : XMLFragmentMapping(org.eclipse.persistence.oxm.mappings.XMLFragmentMapping) SDOFragmentMappingAttributeAccessor(org.eclipse.persistence.sdo.helper.SDOFragmentMappingAttributeAccessor)

Example 2 with XMLFragmentMapping

use of org.eclipse.persistence.oxm.mappings.XMLFragmentMapping in project eclipselink by eclipse-ee4j.

the class SelfProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setDefaultRootElement("bar:employee");
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("bar", "urn:example");
    descriptor.setNamespaceResolver(namespaceResolver);
    XMLDirectMapping firstNameMapping = new XMLDirectMapping();
    firstNameMapping.setAttributeName("firstName");
    firstNameMapping.setXPath("bar:first-name/text()");
    firstNameMapping.setIsReadOnly(true);
    descriptor.addMapping(firstNameMapping);
    XMLDirectMapping lastNameMapping = new XMLDirectMapping();
    lastNameMapping.setAttributeName("lastName");
    lastNameMapping.setXPath("bar:last-name/text()");
    lastNameMapping.setIsReadOnly(true);
    descriptor.addMapping(lastNameMapping);
    XMLFragmentMapping nodeMapping = new XMLFragmentMapping();
    nodeMapping.setAttributeName("xmlNode");
    nodeMapping.setXPath(".");
    descriptor.addMapping(nodeMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLFragmentMapping(org.eclipse.persistence.oxm.mappings.XMLFragmentMapping)

Example 3 with XMLFragmentMapping

use of org.eclipse.persistence.oxm.mappings.XMLFragmentMapping in project eclipselink by eclipse-ee4j.

the class XMLFragmentElementProject method addEmployeeDescriptor.

public void addEmployeeDescriptor() {
    XMLDescriptor desc = new XMLDescriptor();
    desc.setJavaClass(Employee.class);
    desc.setDefaultRootElement("employee");
    XMLDirectMapping mapping = new XMLDirectMapping();
    mapping.setAttributeName("firstName");
    mapping.setXPath("first-name/text()");
    desc.addMapping(mapping);
    mapping = new XMLDirectMapping();
    mapping.setAttributeName("lastName");
    mapping.setXPath("last-name/text()");
    desc.addMapping(mapping);
    XMLFragmentMapping mapping2 = new XMLFragmentMapping();
    mapping2.setAttributeName("xmlNode");
    mapping2.setXPath("xml-node");
    desc.addMapping(mapping2);
    // desc.setShouldPreserveDocument(true);
    this.addDescriptor(desc);
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLFragmentMapping(org.eclipse.persistence.oxm.mappings.XMLFragmentMapping)

Example 4 with XMLFragmentMapping

use of org.eclipse.persistence.oxm.mappings.XMLFragmentMapping in project eclipselink by eclipse-ee4j.

the class XMLFragmentTextNodeProject method addEmployeeDescriptor.

public void addEmployeeDescriptor() {
    XMLDescriptor desc = new XMLDescriptor();
    desc.setJavaClass(Employee.class);
    desc.setDefaultRootElement("employee");
    XMLDirectMapping mapping = new XMLDirectMapping();
    mapping.setAttributeName("firstName");
    mapping.setXPath("first-name/text()");
    desc.addMapping(mapping);
    mapping = new XMLDirectMapping();
    mapping.setAttributeName("lastName");
    mapping.setXPath("last-name/text()");
    desc.addMapping(mapping);
    XMLFragmentMapping mapping2 = new XMLFragmentMapping();
    mapping2.setAttributeName("xmlNode");
    mapping2.setXPath("xml-node/text()");
    desc.addMapping(mapping2);
    // desc.setShouldPreserveDocument(true);
    this.addDescriptor(desc);
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLFragmentMapping(org.eclipse.persistence.oxm.mappings.XMLFragmentMapping)

Example 5 with XMLFragmentMapping

use of org.eclipse.persistence.oxm.mappings.XMLFragmentMapping in project eclipselink by eclipse-ee4j.

the class XMLFragmentNSTestCases method testObjectToXMLStringWriterPrefixedChild.

/**
 * Test WriterRecord - prefixed child nodes
 */
public void testObjectToXMLStringWriterPrefixedChild() throws Exception {
    NamespaceResolver nsresolver = new NamespaceResolver();
    nsresolver.put("ns1", "http://www.example.com/test-uri");
    XMLFragmentMapping mapping = new XMLFragmentMapping();
    mapping.setAttributeName("xmlNode");
    mapping.setXPath("ns1:xml-node");
    setProject(new XMLFragmentNSProject(nsresolver, mapping));
    StringWriter writer = new StringWriter();
    xmlMarshaller.marshal(getWriteControlObjectNS(XML_SUB_ELEMENT_PFX_CHILD, "http://www.example.com/test-uri"), writer);
    StringReader reader = new StringReader(writer.toString());
    InputSource inputSource = new InputSource(reader);
    Document testDocument = parser.parse(inputSource);
    writer.close();
    reader.close();
    objectToXMLDocumentTest(testDocument, XML_RESOURCE_PFX_CHILD, "testObjectToXMLStringWriterPrefixedChild");
}
Also used : InputSource(org.xml.sax.InputSource) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLFragmentMapping(org.eclipse.persistence.oxm.mappings.XMLFragmentMapping) Document(org.w3c.dom.Document)

Aggregations

XMLFragmentMapping (org.eclipse.persistence.oxm.mappings.XMLFragmentMapping)14 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)8 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)7 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)6 Document (org.w3c.dom.Document)6 StringReader (java.io.StringReader)3 StringWriter (java.io.StringWriter)3 InputSource (org.xml.sax.InputSource)3 XMLAnyObjectMapping (org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)2 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 XMLField (org.eclipse.persistence.oxm.XMLField)1 XMLBinaryDataCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping)1 XMLBinaryDataMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping)1 XMLChoiceCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping)1 XMLChoiceObjectMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping)1 XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)1 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)1 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)1