Search in sources :

Example 46 with NamespaceResolver

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

the class ChildAndGeneratedPrefixClashProject method getTeamDescriptor.

private XMLDescriptor getTeamDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Team.class);
    xmlDescriptor.setDefaultRootElement("aaa:team");
    XMLDirectMapping nameMapping = new XMLDirectMapping();
    nameMapping.setAttributeName("teamName");
    nameMapping.setXPath("ns0:teamName/text()");
    xmlDescriptor.addMapping(nameMapping);
    XMLSchemaClassPathReference ref = new XMLSchemaClassPathReference();
    ref.setSchemaContext("/aaa:team");
    ref.setType(XMLSchemaClassPathReference.COMPLEX_TYPE);
    xmlDescriptor.setSchemaReference(ref);
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("aaa", "http://www.example.com/aaa");
    nsResolver.put("ns0", "http://www.example.com/teamNS0");
    nsResolver.put("ns1", "http://www.example.com/teamNS1");
    xmlDescriptor.setNamespaceResolver(nsResolver);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)

Example 47 with NamespaceResolver

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

the class DefaultNamespaceProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Employee.class);
    xmlDescriptor.setDefaultRootElement("DEFAULT:employee");
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("DEFAULT", "http://www.example.com/EMPLOYEE");
    xmlDescriptor.setNamespaceResolver(nsResolver);
    // Unqualified attributes are in the null namespace
    // rather than the default namespace
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("DEFAULT:personal-info/@id");
    xmlDescriptor.addMapping(idMapping);
    XMLDirectMapping nameMapping = new XMLDirectMapping();
    nameMapping.setAttributeName("name");
    nameMapping.setXPath("DEFAULT:personal-info/DEFAULT:name/text()");
    xmlDescriptor.addMapping(nameMapping);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 48 with NamespaceResolver

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

the class CustomerNSProject method getPhoneNumberDescriptor.

private XMLDescriptor getPhoneNumberDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(PhoneNumber.class);
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("ns", "urn:customer");
    xmlDescriptor.setNamespaceResolver(namespaceResolver);
    XMLDirectMapping valueMapping = new XMLDirectMapping();
    valueMapping.setAttributeName("value");
    valueMapping.setXPath("text()");
    xmlDescriptor.addMapping(valueMapping);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 49 with NamespaceResolver

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

the class CustomerProject method getAddressDescriptor.

private XMLDescriptor getAddressDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Address.class);
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.setDefaultNamespaceURI("urn:customer");
    descriptor.setNamespaceResolver(nsResolver);
    XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
    schemaReference.setSchemaContext("/address-type");
    schemaReference.setType(XMLSchemaClassPathReference.COMPLEX_TYPE);
    descriptor.setSchemaReference(schemaReference);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)

Example 50 with NamespaceResolver

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

the class SimpleUnionProject 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);
    XMLDirectMapping ageMapping = new XMLDirectMapping();
    ageMapping.setAttributeName("age");
    XMLUnionField field = new XMLUnionField("age/text()");
    QName qname = 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.setSchemaType(qname);
    field.addSchemaType(integerQName);
    field.addSchemaType(integerQName);
    ageMapping.setField(field);
    descriptor.addMapping(ageMapping);
    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) XMLUnionField(org.eclipse.persistence.oxm.XMLUnionField)

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