Search in sources :

Example 51 with NamespaceResolver

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

the class SchemaTypeQNameProject method getQNameHolderDescriptor.

private XMLDescriptor getQNameHolderDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(QNameHolder.class);
    descriptor.setDefaultRootElement("qnameholder");
    XMLDirectMapping qnameMapping = new XMLDirectMapping();
    qnameMapping.setAttributeName("theQName");
    qnameMapping.setXPath("the-qname/text()");
    ((XMLField) qnameMapping.getField()).setSchemaType(XMLConstants.QNAME_QNAME);
    descriptor.addMapping(qnameMapping);
    XMLCompositeDirectCollectionMapping qnamesMapping = new XMLCompositeDirectCollectionMapping();
    qnamesMapping.setAttributeName("theQNames");
    qnamesMapping.setXPath("the-qnames/item/text()");
    ((XMLField) qnamesMapping.getField()).setSchemaType(XMLConstants.QNAME_QNAME);
    descriptor.addMapping(qnamesMapping);
    XMLCompositeDirectCollectionMapping qnames2Mapping = new XMLCompositeDirectCollectionMapping();
    qnames2Mapping.setAttributeName("theQNames2");
    qnames2Mapping.setXPath("the-qnames/item2/text()");
    ((XMLField) qnames2Mapping.getField()).setSchemaType(XMLConstants.QNAME_QNAME);
    ((XMLField) qnames2Mapping.getField()).setUsesSingleNode(true);
    descriptor.addMapping(qnames2Mapping);
    NamespaceResolver nr = new NamespaceResolver();
    nr.put("somePrefix", "someURI");
    nr.put("xsd", "http://www.w3.org/2001/XMLSchema");
    nr.setDefaultNamespaceURI("mydefaultnamespace");
    descriptor.setNamespaceResolver(nr);
    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 52 with NamespaceResolver

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

the class TypeAttributeNonXsiPrefixProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setDefaultRootElement("employee");
    NamespaceResolver resolver = new NamespaceResolver();
    resolver.put(NON_XSI_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 identifierMapping = new XMLDirectMapping();
    identifierMapping.setAttributeName("identifier");
    XMLField field = new XMLField("identifier/text()");
    field.setIsTypedTextField(true);
    identifierMapping.setField(field);
    descriptor.addMapping(identifierMapping);
    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 : 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)

Example 53 with NamespaceResolver

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

the class TypeAttributeTimeProject 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 identifierMapping = new XMLDirectMapping();
    identifierMapping.setAttributeName("identifier");
    XMLField field = new XMLField("identifier/text()");
    field.setIsTypedTextField(true);
    field.addConversion(XMLConstants.TIME_QNAME, GregorianCalendar.class);
    identifierMapping.setField(field);
    descriptor.addMapping(identifierMapping);
    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 : 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)

Example 54 with NamespaceResolver

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

the class SelfAttributeProject method getEmployeeIDDescriptor.

private XMLDescriptor getEmployeeIDDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(EmployeeID.class);
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("ns", "urn:example");
    descriptor.setNamespaceResolver(namespaceResolver);
    XMLDirectMapping id1Mapping = new XMLDirectMapping();
    id1Mapping.setAttributeName("id1");
    id1Mapping.setXPath("@id1");
    descriptor.addMapping(id1Mapping);
    XMLDirectMapping id2Mapping = new XMLDirectMapping();
    id2Mapping.setAttributeName("id2");
    id2Mapping.setXPath("@ns:id2");
    descriptor.addMapping(id2Mapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 55 with NamespaceResolver

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

the class SelfAttributeProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.addPrimaryKeyFieldName("@id1");
    descriptor.addPrimaryKeyFieldName("@ns:id2");
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("ns", "urn:example");
    descriptor.setNamespaceResolver(namespaceResolver);
    XMLCompositeObjectMapping idMapping = new XMLCompositeObjectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath(".");
    idMapping.setReferenceClass(EmployeeID.class);
    descriptor.addMapping(idMapping);
    XMLObjectReferenceMapping managerMapping = new XMLObjectReferenceMapping();
    managerMapping.setAttributeName("manager");
    managerMapping.addSourceToTargetKeyFieldAssociation("manager/@fk1", "@id1");
    managerMapping.addSourceToTargetKeyFieldAssociation("manager/@ns:fk2", "@ns:id2");
    managerMapping.setReferenceClass(Employee.class);
    descriptor.addMapping(managerMapping);
    XMLCollectionReferenceMapping employeesMapping = new XMLCollectionReferenceMapping();
    employeesMapping.setAttributeName("teamMembers");
    employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/@fk1", "@id1");
    employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/@ns:fk2", "@ns:id2");
    employeesMapping.setReferenceClass(Employee.class);
    descriptor.addMapping(employeesMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

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