Search in sources :

Example 21 with XMLCompositeDirectCollectionMapping

use of org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping 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 22 with XMLCompositeDirectCollectionMapping

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

the class DirectCollectionSingleNodeXMLAttributeProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setDefaultRootElement("employee");
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    descriptor.addMapping(idMapping);
    XMLCompositeDirectCollectionMapping responsibilitiesMapping = new XMLCompositeDirectCollectionMapping();
    responsibilitiesMapping.setAttributeName("responsibilities");
    responsibilitiesMapping.useCollectionClass(ArrayList.class);
    responsibilitiesMapping.setXPath("@responsibilities");
    responsibilitiesMapping.setUsesSingleNode(true);
    descriptor.addMapping(responsibilitiesMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)

Example 23 with XMLCompositeDirectCollectionMapping

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

the class BasicBinderTestsProject method buildEmployeeDescriptor.

public void buildEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setDefaultRootElement("ns:employee");
    descriptor.setShouldPreserveDocument(true);
    descriptor.setJavaClass(Employee.class);
    descriptor.setNamespaceResolver(resolver);
    descriptor.addDirectMapping("id", "@id");
    descriptor.addDirectMapping("firstName", "getFirstName", "setFirstName", "first-name/text()");
    XMLDirectMapping lname = new XMLDirectMapping();
    lname.setAttributeName("lastName");
    lname.setGetMethodName("getLastName");
    lname.setSetMethodName("setLastName");
    lname.setXPath("last-name/text()");
    descriptor.addMapping(lname);
    XMLCompositeObjectMapping addr = new XMLCompositeObjectMapping();
    addr.setAttributeName("address");
    addr.setGetMethodName("getAddress");
    addr.setSetMethodName("setAddress");
    addr.setXPath("ns:address");
    addr.setReferenceClass(Address.class);
    descriptor.addMapping(addr);
    XMLCompositeDirectCollectionMapping resp = new XMLCompositeDirectCollectionMapping();
    resp.setAttributeName("responsibilities");
    resp.setGetMethodName("getResponsibilities");
    resp.setSetMethodName("setResponsibilities");
    resp.setXPath("responsibility");
    resp.getContainerPolicy().setContainerClass(Vector.class);
    descriptor.addMapping(resp);
    XMLCompositeCollectionMapping phone = new XMLCompositeCollectionMapping();
    phone.setAttributeName("phoneNumbers");
    phone.setGetMethodName("getPhoneNumbers");
    phone.setSetMethodName("setPhoneNumbers");
    phone.setXPath("phones/ns:phone");
    phone.setReferenceClass(PhoneNumber.class);
    phone.getContainerPolicy().setContainerClass(Vector.class);
    descriptor.addMapping(phone);
    this.addDescriptor(descriptor);
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Example 24 with XMLCompositeDirectCollectionMapping

use of org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping 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 25 with XMLCompositeDirectCollectionMapping

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

the class TypedDirectMappingTestProject method getTestObjectDescriptor.

public XMLDescriptor getTestObjectDescriptor() {
    XMLDescriptor testObjectDescriptor = new XMLDescriptor();
    testObjectDescriptor.setJavaClass(org.eclipse.persistence.testing.oxm.mappings.typeddirect.TestObject.class);
    testObjectDescriptor.setDefaultRootElement("test-object");
    XMLDirectMapping base64Mapping = new XMLDirectMapping();
    base64Mapping.setAttributeName("base64");
    base64Mapping.setGetMethodName("getBase64");
    base64Mapping.setSetMethodName("setBase64");
    XMLField field = new XMLField("binary[1]/text()");
    field.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    base64Mapping.setField(field);
    testObjectDescriptor.addMapping(base64Mapping);
    XMLDirectMapping hexMapping = new XMLDirectMapping();
    hexMapping.setAttributeName("hex");
    hexMapping.setGetMethodName("getHex");
    hexMapping.setSetMethodName("setHex");
    XMLField hexfield = new XMLField("binary[2]/text()");
    hexfield.setSchemaType(XMLConstants.HEX_BINARY_QNAME);
    hexMapping.setField(hexfield);
    testObjectDescriptor.addMapping(hexMapping);
    XMLDirectMapping dateMapping = new XMLDirectMapping();
    dateMapping.setAttributeName("date");
    dateMapping.setGetMethodName("getDate");
    dateMapping.setSetMethodName("setDate");
    XMLField datefield = new XMLField("date/text()");
    datefield.setSchemaType(XMLConstants.DATE_QNAME);
    dateMapping.setField(datefield);
    testObjectDescriptor.addMapping(dateMapping);
    XMLDirectMapping timeMapping = new XMLDirectMapping();
    timeMapping.setAttributeName("time");
    timeMapping.setGetMethodName("getTime");
    timeMapping.setSetMethodName("setTime");
    XMLField timefield = new XMLField("time/text()");
    timefield.setSchemaType(XMLConstants.TIME_QNAME);
    timeMapping.setField(timefield);
    testObjectDescriptor.addMapping(timeMapping);
    XMLDirectMapping dateTimeMapping = new XMLDirectMapping();
    dateTimeMapping.setAttributeName("dateTime");
    dateTimeMapping.setGetMethodName("getDateTime");
    dateTimeMapping.setSetMethodName("setDateTime");
    XMLField dateTimefield = new XMLField("date-time/text()");
    dateTimefield.setSchemaType(XMLConstants.DATE_TIME_QNAME);
    dateTimeMapping.setField(dateTimefield);
    testObjectDescriptor.addMapping(dateTimeMapping);
    XMLCompositeDirectCollectionMapping dateVectorMapping = new XMLCompositeDirectCollectionMapping();
    dateVectorMapping.setAttributeName("dateVector");
    dateVectorMapping.setGetMethodName("getDateVector");
    dateVectorMapping.setSetMethodName("setDateVector");
    XMLField dateVectorfield = new XMLField("date-vector/date-element/text()");
    dateVectorfield.setSchemaType(XMLConstants.DATE_QNAME);
    dateVectorMapping.setField(dateVectorfield);
    dateVectorMapping.setAttributeElementClass(java.util.Calendar.class);
    testObjectDescriptor.addMapping(dateVectorMapping);
    XMLCompositeDirectCollectionMapping timeVectorMapping = new XMLCompositeDirectCollectionMapping();
    timeVectorMapping.setAttributeName("timeVector");
    timeVectorMapping.setGetMethodName("getTimeVector");
    timeVectorMapping.setSetMethodName("setTimeVector");
    XMLField timeVectorfield = new XMLField("time-vector/time-element/text()");
    timeVectorfield.setSchemaType(XMLConstants.TIME_QNAME);
    timeVectorMapping.setField(timeVectorfield);
    timeVectorMapping.setAttributeElementClass(java.util.Calendar.class);
    testObjectDescriptor.addMapping(timeVectorMapping);
    XMLCompositeDirectCollectionMapping dateTimeVectorMapping = new XMLCompositeDirectCollectionMapping();
    dateTimeVectorMapping.setAttributeName("dateTimeVector");
    dateTimeVectorMapping.setGetMethodName("getDateTimeVector");
    dateTimeVectorMapping.setSetMethodName("setDateTimeVector");
    XMLField dateTimeVectorfield = new XMLField("date-time-vector/date-time-element/text()");
    dateTimeVectorfield.setSchemaType(XMLConstants.DATE_TIME_QNAME);
    dateTimeVectorMapping.setField(dateTimeVectorfield);
    dateTimeVectorMapping.setAttributeElementClass(java.util.Calendar.class);
    testObjectDescriptor.addMapping(dateTimeVectorMapping);
    XMLCompositeDirectCollectionMapping base64VectorMapping = new XMLCompositeDirectCollectionMapping();
    base64VectorMapping.setAttributeName("base64Vector");
    base64VectorMapping.setGetMethodName("getBase64Vector");
    base64VectorMapping.setSetMethodName("setBase64Vector");
    XMLField base64Vectorfield = new XMLField("base-64-vector/base-64-element/text()");
    base64Vectorfield.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    base64VectorMapping.setField(base64Vectorfield);
    base64VectorMapping.setAttributeElementClass(byte[].class);
    testObjectDescriptor.addMapping(base64VectorMapping);
    XMLCompositeDirectCollectionMapping hexVectorMapping = new XMLCompositeDirectCollectionMapping();
    hexVectorMapping.setAttributeName("hexVector");
    hexVectorMapping.setGetMethodName("getHexVector");
    hexVectorMapping.setSetMethodName("setHexVector");
    XMLField hexVectorfield = new XMLField("hex-vector/hex-element/text()");
    hexVectorfield.setSchemaType(XMLConstants.HEX_BINARY_QNAME);
    hexVectorMapping.setField(hexVectorfield);
    hexVectorMapping.setAttributeElementClass(byte[].class);
    testObjectDescriptor.addMapping(hexVectorMapping);
    XMLDirectMapping unTypedDateMapping = new XMLDirectMapping();
    unTypedDateMapping.setAttributeName("untypedDate");
    unTypedDateMapping.setGetMethodName("getUntypedDate");
    unTypedDateMapping.setSetMethodName("setUntypedDate");
    unTypedDateMapping.setXPath("untyped-date/text()");
    testObjectDescriptor.addMapping(unTypedDateMapping);
    XMLDirectMapping typedDateMapping = new XMLDirectMapping();
    typedDateMapping.setAttributeName("typedDate");
    typedDateMapping.setGetMethodName("getTypedDate");
    typedDateMapping.setSetMethodName("setTypedDate");
    XMLField typedDatefield = new XMLField("typed-date/text()");
    typedDatefield.setSchemaType(XMLConstants.DATE_QNAME);
    typedDateMapping.setField(typedDatefield);
    testObjectDescriptor.addMapping(typedDateMapping);
    XMLDirectMapping nextMapping;
    XMLField typedField;
    nextMapping = new XMLDirectMapping();
    nextMapping.setAttributeName("untypedSqlDate");
    nextMapping.setGetMethodName("getUntypedSqlDate");
    nextMapping.setSetMethodName("setUntypedSqlDate");
    nextMapping.setXPath("untyped-sql-date/text()");
    testObjectDescriptor.addMapping(nextMapping);
    nextMapping = new XMLDirectMapping();
    nextMapping.setAttributeName("typedSqlDate");
    nextMapping.setGetMethodName("getTypedSqlDate");
    nextMapping.setSetMethodName("setTypedSqlDate");
    typedField = new XMLField("typed-sql-date/text()");
    typedField.setSchemaType(XMLConstants.DATE_QNAME);
    nextMapping.setField(typedField);
    testObjectDescriptor.addMapping(nextMapping);
    nextMapping = new XMLDirectMapping();
    nextMapping.setAttributeName("untypedTimestamp");
    nextMapping.setGetMethodName("getUntypedTimestamp");
    nextMapping.setSetMethodName("setUntypedTimestamp");
    nextMapping.setXPath("untyped-timestamp/text()");
    testObjectDescriptor.addMapping(nextMapping);
    nextMapping = new XMLDirectMapping();
    nextMapping.setAttributeName("typedTimestamp");
    nextMapping.setGetMethodName("getTypedTimestamp");
    nextMapping.setSetMethodName("setTypedTimestamp");
    typedField = new XMLField("typed-timestamp/text()");
    typedField.setSchemaType(XMLConstants.TIME_QNAME);
    nextMapping.setField(typedField);
    testObjectDescriptor.addMapping(nextMapping);
    return testObjectDescriptor;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)

Aggregations

XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)63 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)49 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)40 XMLField (org.eclipse.persistence.oxm.XMLField)14 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)11 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)11 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)10 QName (javax.xml.namespace.QName)6 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)6 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)3 DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)3 JAXBException (org.eclipse.persistence.exceptions.JAXBException)3 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)3 JAXBArrayAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor)3 Field (org.eclipse.persistence.internal.oxm.mappings.Field)3 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)3 BigDecimal (java.math.BigDecimal)2 CoreDescriptor (org.eclipse.persistence.core.descriptors.CoreDescriptor)2 CoreMapping (org.eclipse.persistence.core.mappings.CoreMapping)2 CoreConverter (org.eclipse.persistence.core.mappings.converters.CoreConverter)2