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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations