Search in sources :

Example 31 with XMLCompositeDirectCollectionMapping

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

the class RequiredTestProject method getRequiredTestObjectDescriptor.

private XMLDescriptor getRequiredTestObjectDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(RequiredTestObject.class);
    descriptor.setAlias("RequiredTestObject");
    descriptor.setDefaultRootElement("required-test-object");
    XMLDirectMapping directMapping = new XMLDirectMapping();
    directMapping.setAttributeName("direct");
    directMapping.setXPath("direct/text()");
    ((XMLField) directMapping.getField()).setRequired(shouldSetMappingsToRequired);
    descriptor.addMapping(directMapping);
    XMLDirectMapping directAttributeMapping = new XMLDirectMapping();
    directAttributeMapping.setAttributeName("directAttribute");
    directAttributeMapping.setXPath("@directAttribute");
    ((XMLField) directAttributeMapping.getField()).setRequired(shouldSetMappingsToRequired);
    descriptor.addMapping(directAttributeMapping);
    XMLCompositeDirectCollectionMapping directCollectionMapping = new XMLCompositeDirectCollectionMapping();
    directCollectionMapping.setAttributeName("directCollection");
    directCollectionMapping.setXPath("directCollection/text()");
    ((XMLField) directCollectionMapping.getField()).setRequired(shouldSetMappingsToRequired);
    descriptor.addMapping(directCollectionMapping);
    XMLCompositeObjectMapping compositeObjectMapping = new XMLCompositeObjectMapping();
    compositeObjectMapping.setAttributeName("compositeObject");
    compositeObjectMapping.setXPath("compositeObject/text()");
    compositeObjectMapping.setReferenceClass(RequiredTestSubObject.class);
    ((XMLField) compositeObjectMapping.getField()).setRequired(shouldSetMappingsToRequired);
    descriptor.addMapping(compositeObjectMapping);
    XMLCompositeCollectionMapping compositeCollectionMapping = new XMLCompositeCollectionMapping();
    compositeCollectionMapping.setAttributeName("compositeCollection");
    compositeCollectionMapping.setXPath("compositeCollection/text()");
    compositeCollectionMapping.setReferenceClass(RequiredTestSubObject.class);
    ((XMLField) compositeCollectionMapping.getField()).setRequired(shouldSetMappingsToRequired);
    descriptor.addMapping(compositeCollectionMapping);
    return descriptor;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) 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 32 with XMLCompositeDirectCollectionMapping

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

the class XMLRootSimpleCollectionProject method getRootDescriptor.

private XMLDescriptor getRootDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(RootObjectWithSimpleCollection.class);
    xmlDescriptor.setDefaultRootElement("ns0:myRoot");
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("ns0", "mynamespace");
    xmlDescriptor.setNamespaceResolver(nsResolver);
    XMLCompositeDirectCollectionMapping theMapping = new XMLCompositeDirectCollectionMapping();
    theMapping.setAttributeName("theList");
    theMapping.setXPath("text()");
    theMapping.setFieldElementClass(Integer.class);
    theMapping.setUsesSingleNode(true);
    xmlDescriptor.addMapping(theMapping);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)

Example 33 with XMLCompositeDirectCollectionMapping

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

the class DBWSModelProject method buildBatchQueryDescriptor.

/**
 * Build an XMLDescriptor for BatchQueryOperation.
 */
protected XMLDescriptor buildBatchQueryDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(BatchQueryOperation.class);
    descriptor.setDefaultRootElement("batch-sql-query");
    XMLDirectMapping name = new XMLDirectMapping();
    name.setAttributeName("name");
    name.setXPath("name/text()");
    descriptor.addMapping(name);
    XMLCompositeDirectCollectionMapping statementsMapping = new XMLCompositeDirectCollectionMapping();
    statementsMapping.setAttributeName("batchSql");
    XMLField f1 = new XMLField("batch-statement/text()");
    f1.setIsCDATA(true);
    statementsMapping.setField(f1);
    descriptor.addMapping(statementsMapping);
    return descriptor;
}
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)

Example 34 with XMLCompositeDirectCollectionMapping

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

the class TestProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setAlias("Employee");
    descriptor.addPrimaryKeyFieldName("name/text()");
    descriptor.setNamespaceResolver(nsr);
    if (setSchemaContext) {
        XMLSchemaReference sRef = new XMLSchemaURLReference();
        sRef.setSchemaContext("/employee-type");
        sRef.setType(XMLSchemaReference.COMPLEX_TYPE);
        descriptor.setSchemaReference(sRef);
    }
    if (setDefaultRootElement) {
        descriptor.setDefaultRootElement("employee");
    }
    // create name mapping
    XMLDirectMapping nameMapping = new XMLDirectMapping();
    nameMapping.setAttributeName("name");
    nameMapping.setXPath("name/text()");
    descriptor.addMapping(nameMapping);
    // create address mapping
    XMLCompositeObjectMapping addressMapping = new XMLCompositeObjectMapping();
    addressMapping.setAttributeName("address");
    addressMapping.setXPath("address");
    addressMapping.setReferenceClass(Address.class);
    descriptor.addMapping(addressMapping);
    // create phoneNumbers mapping
    XMLCompositeCollectionMapping phonesMapping = new XMLCompositeCollectionMapping();
    phonesMapping.setAttributeName("phoneNumbers");
    phonesMapping.useCollectionClass(ArrayList.class);
    phonesMapping.setXPath("phone-numbers");
    phonesMapping.setReferenceClass(PhoneNumber.class);
    descriptor.addMapping(phonesMapping);
    // create projectIDs mapping
    XMLCompositeDirectCollectionMapping projectIdsMapping = new XMLCompositeDirectCollectionMapping();
    projectIdsMapping.setAttributeName("projectIDs");
    projectIdsMapping.useCollectionClass(ArrayList.class);
    projectIdsMapping.setXPath("project-id");
    TypeConversionConverter tcc = new TypeConversionConverter(projectIdsMapping);
    tcc.setObjectClass(BigDecimal.class);
    projectIdsMapping.setValueConverter(tcc);
    descriptor.addMapping(projectIdsMapping);
    // create stuff mapping
    XMLAnyCollectionMapping acMapping = new XMLAnyCollectionMapping();
    acMapping.setAttributeName("stuff");
    descriptor.addMapping(acMapping);
    // Enable Choice testing when Bug 269880 has been fixed
    // create choice mapping - choice
    XMLChoiceObjectMapping choiceMapping = new XMLChoiceObjectMapping();
    choiceMapping.setAttributeName("choice");
    choiceMapping.addChoiceElement("nickname/text()", String.class);
    choiceMapping.addChoiceElement("secondAddress", Address.class);
    choiceMapping.addChoiceElement("age/text()", Integer.class);
    // descriptor.addMapping(choiceMapping);
    // Enable ChoiceCollection testing when Bug 269880 has been fixed
    // create choices mapping
    XMLChoiceCollectionMapping choiceCMapping = new XMLChoiceCollectionMapping();
    choiceCMapping.setAttributeName("choices");
    choiceCMapping.addChoiceElement("badgeId/text()", Integer.class);
    choiceCMapping.addChoiceElement("alternateAddress", Address.class);
    choiceCMapping.addChoiceElement("codename/text()", String.class);
    // descriptor.addMapping(choiceCMapping);
    // create billingAddress mapping
    XMLObjectReferenceMapping orMapping = new XMLObjectReferenceMapping();
    orMapping.setAttributeName("billingAddress");
    orMapping.setReferenceClass(Address.class);
    orMapping.addSourceToTargetKeyFieldAssociation("@bill-address-id", "@aid");
    orMapping.addSourceToTargetKeyFieldAssociation("bill-address-city/text()", "city/text()");
    descriptor.addMapping(orMapping);
    // create data mapping
    XMLBinaryDataMapping dataMapping = new XMLBinaryDataMapping();
    dataMapping.setAttributeName("data");
    XMLField field = new XMLField("data");
    field.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    dataMapping.setField(field);
    dataMapping.setShouldInlineBinaryData(false);
    dataMapping.setSwaRef(true);
    dataMapping.setMimeType("application/binary");
    descriptor.addMapping(dataMapping);
    // create bytes mapping
    XMLBinaryDataCollectionMapping bytesMapping = new XMLBinaryDataCollectionMapping();
    bytesMapping.setAttributeName("bytes");
    XMLField theField = new XMLField("bytes");
    theField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    bytesMapping.setField(theField);
    bytesMapping.setShouldInlineBinaryData(false);
    bytesMapping.setSwaRef(false);
    bytesMapping.setMimeType("text/plain");
    descriptor.addMapping(bytesMapping);
    // create URL mapping
    XMLDirectMapping urlMapping = new XMLDirectMapping();
    urlMapping.setAttributeName("aUrl");
    urlMapping.setXPath("aUrl/text()");
    descriptor.addMapping(urlMapping);
    return descriptor;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) TypeConversionConverter(org.eclipse.persistence.mappings.converters.TypeConversionConverter) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) XMLSchemaURLReference(org.eclipse.persistence.oxm.schema.XMLSchemaURLReference) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLSchemaReference(org.eclipse.persistence.oxm.schema.XMLSchemaReference) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Example 35 with XMLCompositeDirectCollectionMapping

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

the class TwoDirectCollectionMappingProject method addEmployeeDescriptor.

public void addEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setDefaultRootElement("employee");
    descriptor.setJavaClass(Employee.class);
    XMLCompositeDirectCollectionMapping responsibilities = new XMLCompositeDirectCollectionMapping();
    responsibilities.setAttributeName("primaryResponsibilities");
    responsibilities.setXPath("primary-responsibilities/responsibility/text()");
    responsibilities.getContainerPolicy().setContainerClass(Vector.class);
    responsibilities.readOnly();
    descriptor.addMapping(responsibilities);
    XMLCompositeDirectCollectionMapping responsibilities2 = new XMLCompositeDirectCollectionMapping();
    responsibilities2.setAttributeName("primaryResponsibilities2");
    responsibilities2.setXPath("primary-responsibilities/responsibility/text()");
    responsibilities2.getContainerPolicy().setContainerClass(Vector.class);
    descriptor.addMapping(responsibilities2);
    this.addDescriptor(descriptor);
}
Also used : 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