Search in sources :

Example 41 with NamespaceResolver

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

the class ExtraNamespacesBug6004272Project method getTeamDescriptor.

private XMLDescriptor getTeamDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Team.class);
    xmlDescriptor.setDefaultRootElement("ns4:team");
    XMLDirectMapping nameMapping = new XMLDirectMapping();
    nameMapping.setAttributeName("teamName");
    nameMapping.setXPath("ns4:teamName/text()");
    xmlDescriptor.addMapping(nameMapping);
    XMLAnyObjectMapping teamLeaderMapping = new XMLAnyObjectMapping();
    teamLeaderMapping.setAttributeName("teamLeader");
    teamLeaderMapping.setXPath("ns5:leader");
    xmlDescriptor.addMapping(teamLeaderMapping);
    XMLCompositeCollectionMapping empsMapping = new XMLCompositeCollectionMapping();
    empsMapping.setAttributeName("employees");
    empsMapping.setXPath("ns6:emp");
    // no reference class
    xmlDescriptor.addMapping(empsMapping);
    XMLSchemaClassPathReference ref = new XMLSchemaClassPathReference();
    ref.setSchemaContext("/ns4:team");
    ref.setType(XMLSchemaClassPathReference.COMPLEX_TYPE);
    xmlDescriptor.setSchemaReference(ref);
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("ns4", "http://www.example.com/ns4");
    nsResolver.put("ns5", "http://www.example.com/ns5");
    nsResolver.put("ns6", "http://www.example.com/ns6");
    // 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) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)

Example 42 with NamespaceResolver

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

the class ExtraNamespacesBug6004272Project method getCompanyDescriptor.

private XMLDescriptor getCompanyDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Company.class);
    XMLDirectMapping nameMapping = new XMLDirectMapping();
    nameMapping.setAttributeName("companyName");
    nameMapping.setXPath("ns2:companyname/text()");
    xmlDescriptor.addMapping(nameMapping);
    XMLCompositeObjectMapping managerMapping = new XMLCompositeObjectMapping();
    managerMapping.setAttributeName("manager");
    managerMapping.setXPath("ns2:manager");
    managerMapping.setReferenceClass(Manager.class);
    // XMLField xmlFld = (XMLField) managerMapping.getField();
    // xmlFld.setLeafElementType(new QName("http://www.example.com/ns2","manager-type"));
    xmlDescriptor.addMapping(managerMapping);
    XMLCompositeCollectionMapping departmentsMapping = new XMLCompositeCollectionMapping();
    departmentsMapping.setAttributeName("departments");
    departmentsMapping.setXPath("ns2:departments/ns2:dept");
    departmentsMapping.setReferenceClass(Department.class);
    xmlDescriptor.addMapping(departmentsMapping);
    NamespaceResolver nsResolver = new NamespaceResolver();
    // keep in resolver
    nsResolver.put("ns1", "http://www.example.com/rootns");
    nsResolver.put("ns2", "http://www.example.com/ns2");
    nsResolver.put("aaa", "http://www.example.com/aaa");
    xmlDescriptor.setNamespaceResolver(nsResolver);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 43 with NamespaceResolver

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

the class GloballyDefinedNodesProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Employee.class);
    xmlDescriptor.setDefaultRootElement("ns:employee");
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("ns", "http://www.example.com/EMPLOYEE");
    xmlDescriptor.setNamespaceResolver(nsResolver);
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("ns:personal-info/@ns:id");
    xmlDescriptor.addMapping(idMapping);
    XMLDirectMapping nameMapping = new XMLDirectMapping();
    nameMapping.setAttributeName("name");
    nameMapping.setXPath("ns:personal-info/ns: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 44 with NamespaceResolver

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

the class LocallyDefinedNodesProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Employee.class);
    xmlDescriptor.setDefaultRootElement("ns:employee");
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("ns", "http://www.example.com/EMPLOYEE");
    xmlDescriptor.setNamespaceResolver(nsResolver);
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("ns:personal-info/@id");
    xmlDescriptor.addMapping(idMapping);
    XMLDirectMapping nameMapping = new XMLDirectMapping();
    nameMapping.setAttributeName("name");
    nameMapping.setXPath("ns:personal-info/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 45 with NamespaceResolver

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

the class ChildAndGeneratedPrefixClashProject method getRootDescriptor.

private XMLDescriptor getRootDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Root.class);
    xmlDescriptor.setDefaultRootElement("aaa:root");
    // XMLCompositeCollectionMapping companiesMapping = new XMLCompositeCollectionMapping();
    XMLAnyCollectionMapping companiesMapping = new XMLAnyCollectionMapping();
    companiesMapping.setAttributeName("companies");
    companiesMapping.setXPath("aaa:companies");
    companiesMapping.setUseXMLRoot(true);
    // companiesMapping.setReferenceClass(Company.class);
    xmlDescriptor.addMapping(companiesMapping);
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("aaa", "http://www.example.com/aaa");
    xmlDescriptor.setNamespaceResolver(nsResolver);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) 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