Search in sources :

Example 36 with NamespaceResolver

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;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)

Example 37 with NamespaceResolver

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;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) QName(javax.xml.namespace.QName) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) XMLUnionField(org.eclipse.persistence.oxm.XMLUnionField)

Example 38 with NamespaceResolver

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;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)

Example 39 with NamespaceResolver

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;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 40 with NamespaceResolver

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;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)

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