Search in sources :

Example 1 with XMLUnionField

use of org.eclipse.persistence.oxm.XMLUnionField 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 2 with XMLUnionField

use of org.eclipse.persistence.oxm.XMLUnionField 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)

Example 3 with XMLUnionField

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

the class XMLObjectReferenceMapping method getSchemaType.

/**
 * Return a QName representation the schema type for a given XMLField, if
 * applicable.
 *
 * Note:  This method performs the same functionality as 'getSchemaType' in
 * org.eclipse.persistence.internal.oxm.XMLSimpleMappingNodeValue.
 */
protected QName getSchemaType(XMLField xmlField, Object value, AbstractSession session) {
    QName schemaType = null;
    if (xmlField.isTypedTextField()) {
        ConversionManager conversionManager = (ConversionManager) session.getDatasourcePlatform().getConversionManager();
        schemaType = xmlField.getXMLType(value.getClass(), conversionManager);
    } else if (xmlField.isUnionField()) {
        return getSingleValueToWriteForUnion((XMLUnionField) xmlField, value, session);
    } else if (xmlField.getSchemaType() != null) {
        schemaType = xmlField.getSchemaType();
    }
    return schemaType;
}
Also used : QName(javax.xml.namespace.QName) ConversionManager(org.eclipse.persistence.internal.oxm.ConversionManager) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager) XMLUnionField(org.eclipse.persistence.oxm.XMLUnionField)

Example 4 with XMLUnionField

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

the class SimpleUnionXMLAttributeProject 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-info/@age");
    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)

Example 5 with XMLUnionField

use of org.eclipse.persistence.oxm.XMLUnionField 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);
    XMLCompositeDirectCollectionMapping itemsMapping = new XMLCompositeDirectCollectionMapping();
    itemsMapping.setAttributeName("items");
    itemsMapping.setGetMethodName("getItems");
    itemsMapping.setSetMethodName("setItems");
    itemsMapping.useCollectionClass(java.util.ArrayList.class);
    XMLUnionField field = new XMLUnionField("item/text()");
    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)

Aggregations

QName (javax.xml.namespace.QName)6 XMLUnionField (org.eclipse.persistence.oxm.XMLUnionField)6 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)5 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)5 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)5 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)3 ConversionManager (org.eclipse.persistence.internal.oxm.ConversionManager)1 XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)1