Search in sources :

Example 96 with NamespaceResolver

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

the class CompositeElementKeyNSProject method getAddressDescriptor.

private XMLDescriptor getAddressDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Address.class);
    descriptor.addPrimaryKeyFieldName("ns:city/text()");
    descriptor.addPrimaryKeyFieldName("ns:zip/text()");
    descriptor.setDefaultRootElement("ns:address");
    // create namespace resolver
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("ns", "urn:example");
    descriptor.setNamespaceResolver(nsResolver);
    // create id mapping
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@aid");
    descriptor.addMapping(idMapping);
    // create street mapping
    XMLDirectMapping streetMapping = new XMLDirectMapping();
    streetMapping.setAttributeName("street");
    streetMapping.setXPath("ns:street/text()");
    descriptor.addMapping(streetMapping);
    // create city mapping
    XMLDirectMapping cityMapping = new XMLDirectMapping();
    cityMapping.setAttributeName("city");
    cityMapping.setXPath("ns:city/text()");
    descriptor.addMapping(cityMapping);
    // create country mapping
    XMLDirectMapping countryMapping = new XMLDirectMapping();
    countryMapping.setAttributeName("country");
    countryMapping.setXPath("ns:country/text()");
    descriptor.addMapping(countryMapping);
    // create zip mapping
    XMLDirectMapping zipMapping = new XMLDirectMapping();
    zipMapping.setAttributeName("zip");
    zipMapping.setXPath("ns:zip/text()");
    descriptor.addMapping(zipMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 97 with NamespaceResolver

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

the class CompositeElementKeyWithGroupingNSProject method getRootDescriptor.

private XMLDescriptor getRootDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Root.class);
    descriptor.setDefaultRootElement("ns:root");
    // create namespace resolver
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("ns", "urn:example");
    descriptor.setNamespaceResolver(nsResolver);
    // create employee mapping
    XMLCompositeObjectMapping empMapping = new XMLCompositeObjectMapping();
    empMapping.setAttributeName("employee");
    empMapping.setXPath("ns:employee");
    empMapping.setReferenceClass(Employee.class);
    descriptor.addMapping(empMapping);
    // create address mapping
    XMLCompositeCollectionMapping addMapping = new XMLCompositeCollectionMapping();
    addMapping.setAttributeName("addresses");
    addMapping.setXPath("ns:address");
    addMapping.setReferenceClass(Address.class);
    descriptor.addMapping(addMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Example 98 with NamespaceResolver

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

the class CompositeElementKeyWithGroupingNSProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setDefaultRootElement("employee");
    // create namespace resolver
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("ns", "urn:example");
    descriptor.setNamespaceResolver(nsResolver);
    // create id mapping
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    descriptor.addMapping(idMapping);
    // create name mapping
    XMLDirectMapping nameMapping = new XMLDirectMapping();
    nameMapping.setAttributeName("name");
    nameMapping.setXPath("ns:name/text()");
    descriptor.addMapping(nameMapping);
    // create address mapping
    XMLCollectionReferenceMapping addressMapping = new XMLCollectionReferenceMapping();
    addressMapping.useCollectionClass(ArrayList.class);
    addressMapping.setAttributeName("addresses");
    addressMapping.setXPath("ns:grouping-element");
    addressMapping.setReferenceClass(Address.class);
    addressMapping.addSourceToTargetKeyFieldAssociation("ns:address/ns:id-city/text()", "ns:city/text()");
    addressMapping.addSourceToTargetKeyFieldAssociation("ns:address/ns:id-zip/text()", "ns:zip/text()");
    descriptor.addMapping(addressMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 99 with NamespaceResolver

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

the class XMLRootComplexDifferentPrefixWithDRTestCases method getTopLinkProject.

@Override
public Project getTopLinkProject() {
    Project p = super.getTopLinkProject();
    ((XMLDescriptor) p.getDescriptor(Person.class)).setDefaultRootElement("aaa:employee");
    NamespaceResolver nr = new NamespaceResolver();
    nr.put("aaa", "test");
    nr.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    // ((XMLDescriptor)p.getDescriptor(Person.class)).getNamespaceResolver().put("myns" , "blah2");
    // ((XMLDescriptor)p.getDescriptor(Person.class)).getNamespaceResolver().put("aaa", "test");
    // ((XMLDescriptor)p.getDescriptor(Person.class)).getNamespaceResolver().put("oxm" , "blah");
    ((XMLDescriptor) p.getDescriptor(Person.class)).setNamespaceResolver(nr);
    return p;
}
Also used : Project(org.eclipse.persistence.sessions.Project) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) Person(org.eclipse.persistence.testing.oxm.xmlroot.Person)

Example 100 with NamespaceResolver

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

the class NilProject method getAddressDescriptor.

XMLDescriptor getAddressDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Address.class);
    xmlDescriptor.setDefaultRootElement("ns0:bar");
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("ns0", "urn:foo");
    xmlDescriptor.setNamespaceResolver(namespaceResolver);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Aggregations

NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)227 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)142 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)74 XMLField (org.eclipse.persistence.oxm.XMLField)36 XMLSchemaClassPathReference (org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)36 Document (org.w3c.dom.Document)35 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)23 QName (javax.xml.namespace.QName)20 InputStream (java.io.InputStream)17 StringReader (java.io.StringReader)17 StringWriter (java.io.StringWriter)17 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)16 InputSource (org.xml.sax.InputSource)14 Element (org.w3c.dom.Element)13 XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)12 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)12 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)10 HashMap (java.util.HashMap)9 Project (org.eclipse.persistence.sessions.Project)9 XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)8