use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class WithoutGroupingElementIdentifiedByNameProject method getEmployeeDescriptor.
private XMLDescriptor getEmployeeDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Employee.class);
descriptor.setDefaultRootElement("employee");
NamespaceResolver resolver = new NamespaceResolver();
resolver.put(XMLConstants.SCHEMA_INSTANCE_PREFIX, javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
resolver.put(XMLConstants.SCHEMA_PREFIX, javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
descriptor.setNamespaceResolver(resolver);
XMLDirectMapping idMapping = new XMLDirectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath("@id");
descriptor.addMapping(idMapping);
XMLCompositeDirectCollectionMapping responsibilitiesMapping = new XMLCompositeDirectCollectionMapping();
responsibilitiesMapping.setAttributeName("responsibilities");
XMLField field = new XMLField("responsibility/text()");
field.setIsTypedTextField(true);
responsibilitiesMapping.setField(field);
descriptor.addMapping(responsibilitiesMapping);
return descriptor;
}
use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class SimpleUnionPositionalXMLAttributeProject method getPersonDescriptor.
private XMLDescriptor getPersonDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Person.class);
descriptor.setDefaultRootElement("person");
NamespaceResolver resolver = new NamespaceResolver();
resolver.put(XMLConstants.SCHEMA_INSTANCE_PREFIX, javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
resolver.put(XMLConstants.SCHEMA_PREFIX, javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
descriptor.setNamespaceResolver(resolver);
XMLCompositeDirectCollectionMapping itemsMapping = new XMLCompositeDirectCollectionMapping();
itemsMapping.setAttributeName("items");
itemsMapping.setGetMethodName("getItems");
itemsMapping.setSetMethodName("setItems");
itemsMapping.useCollectionClass(java.util.ArrayList.class);
XMLUnionField field = new XMLUnionField("items[1]/@item");
QName dateQname = new QName(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI, "date");
QName integerQName = new QName(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI, "integer");
field.addSchemaType(dateQname);
field.addSchemaType(integerQName);
itemsMapping.setField(field);
descriptor.addMapping(itemsMapping);
XMLDirectMapping firstNameMapping = new XMLDirectMapping();
firstNameMapping.setAttributeName("firstName");
firstNameMapping.setXPath("first-name/text()");
descriptor.addMapping(firstNameMapping);
XMLDirectMapping lastNameMapping = new XMLDirectMapping();
lastNameMapping.setAttributeName("lastName");
lastNameMapping.setXPath("last-name/text()");
descriptor.addMapping(lastNameMapping);
return descriptor;
}
use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class DirectCollectionNodeNullPolicyProject method getEmployeeDescriptor.
/**
* Set only the mappings that do not have a default NodeNullPolicy
*/
private XMLDescriptor getEmployeeDescriptor(boolean fieldsAsElements) {
// if all fields are attributes the use XPath format @id otherwise use id/text()
String xPathPrepend;
// if all fields are attributes the use XPath format @id otherwise use id/text()
String xPathAppend;
if (fieldsAsElements) {
xPathPrepend = "";
xPathAppend = "/text()";
} else {
xPathPrepend = "@";
xPathAppend = "";
}
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Employee.class);
descriptor.setDefaultRootElement("employee");
XMLDirectMapping idMapping = new XMLDirectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath(xPathPrepend + "id" + xPathAppend);
descriptor.addMapping(idMapping);
XMLDirectMapping firstNameMapping = new XMLDirectMapping();
firstNameMapping.setAttributeName("firstName");
firstNameMapping.setXPath(xPathPrepend + "first-name" + xPathAppend);
descriptor.addMapping(firstNameMapping);
XMLCompositeDirectCollectionMapping taskMapping = new XMLCompositeDirectCollectionMapping();
taskMapping.setAttributeName("tasks");
if (fieldsAsElements) {
taskMapping.setXPath(xPathPrepend + "task" + xPathAppend);
} else {
taskMapping.setXPath("tasks/" + xPathPrepend + "task" + xPathAppend);
}
descriptor.addMapping(taskMapping);
XMLDirectMapping lastNameMapping = new XMLDirectMapping();
lastNameMapping.setAttributeName("lastName");
lastNameMapping.setXPath(xPathPrepend + "last-name" + xPathAppend);
descriptor.addMapping(lastNameMapping);
NamespaceResolver nsr = new NamespaceResolver();
nsr.put(XMLConstants.SCHEMA_INSTANCE_PREFIX, javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
descriptor.setNamespaceResolver(nsr);
return descriptor;
}
use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class ExtraNamespacesBug6004272Project method getRootDescriptor.
private XMLDescriptor getRootDescriptor() {
XMLDescriptor xmlDescriptor = new XMLDescriptor();
xmlDescriptor.setJavaClass(Root.class);
xmlDescriptor.setDefaultRootElement("ns1:root");
XMLCompositeCollectionMapping companiesMapping = new XMLCompositeCollectionMapping();
companiesMapping.setAttributeName("companies");
companiesMapping.setXPath("ns2:companies/ns2:company");
companiesMapping.setReferenceClass(Company.class);
xmlDescriptor.addMapping(companiesMapping);
NamespaceResolver nsResolver = new NamespaceResolver();
nsResolver.put("ns1", "http://www.example.com/rootns");
nsResolver.put("ns2", "http://www.example.com/ns2");
xmlDescriptor.setNamespaceResolver(nsResolver);
return xmlDescriptor;
}
use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class ExtraNamespacesBug6004272Project method getManagerDescriptor.
private XMLDescriptor getManagerDescriptor() {
XMLDescriptor xmlDescriptor = new XMLDescriptor();
xmlDescriptor.setJavaClass(Manager.class);
xmlDescriptor.setDefaultRootElement("ns3:manager");
xmlDescriptor.getInheritancePolicy().setParentClass(Employee.class);
XMLDirectMapping titleMapping = new XMLDirectMapping();
titleMapping.setAttributeName("title");
titleMapping.setXPath("ns3:title/text()");
xmlDescriptor.addMapping(titleMapping);
XMLSchemaClassPathReference ref = new XMLSchemaClassPathReference();
ref.setSchemaContext("/ns2:manager-type");
ref.setType(XMLSchemaClassPathReference.COMPLEX_TYPE);
xmlDescriptor.setSchemaReference(ref);
NamespaceResolver nsResolver = new NamespaceResolver();
nsResolver.put("ns3", "http://www.example.com/ns3");
nsResolver.put("ns2", "http://www.example.com/ns2");
nsResolver.put("ns4", "http://www.example.com/ns4");
nsResolver.put("ns7", "http://www.example.com/ns7");
nsResolver.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
xmlDescriptor.setNamespaceResolver(nsResolver);
return xmlDescriptor;
}
Aggregations