Search in sources :

Example 16 with XMLChoiceCollectionMapping

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

the class DBWSBuilderModelProject method buildTableOperationModelDescriptor.

protected ClassDescriptor buildTableOperationModelDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(TableOperationModel.class);
    XMLDirectMapping nameMapping = new XMLDirectMapping();
    nameMapping.setAttributeName("name");
    nameMapping.setXPath("@name");
    descriptor.addMapping(nameMapping);
    ObjectTypeConverter converter = new ObjectTypeConverter();
    converter.addConversionValue("true", Boolean.TRUE);
    converter.addConversionValue("false", Boolean.FALSE);
    converter.setFieldClassification(String.class);
    XMLDirectMapping simpleXMLFormatTagMapping = new XMLDirectMapping();
    simpleXMLFormatTagMapping.setAttributeName("simpleXMLFormatTag");
    simpleXMLFormatTagMapping.setGetMethodName("getSimpleXMLFormatTag");
    simpleXMLFormatTagMapping.setSetMethodName("setSimpleXMLFormatTag");
    simpleXMLFormatTagMapping.setXPath("@simpleXMLFormatTag");
    descriptor.addMapping(simpleXMLFormatTagMapping);
    XMLDirectMapping xmlTagMapping = new XMLDirectMapping();
    xmlTagMapping.setAttributeName("xmlTag");
    xmlTagMapping.setGetMethodName("getXmlTag");
    xmlTagMapping.setSetMethodName("setXmlTag");
    xmlTagMapping.setXPath("@xmlTag");
    descriptor.addMapping(xmlTagMapping);
    XMLDirectMapping isCollectionMapping = new XMLDirectMapping();
    isCollectionMapping.setAttributeName("isCollection");
    isCollectionMapping.setConverter(converter);
    isCollectionMapping.setNullValue(Boolean.FALSE);
    isCollectionMapping.setXPath("@isCollection");
    descriptor.addMapping(isCollectionMapping);
    XMLDirectMapping binaryAttachment = new XMLDirectMapping();
    binaryAttachment.setAttributeName("binaryAttachment");
    binaryAttachment.setConverter(converter);
    binaryAttachment.setNullValue(Boolean.FALSE);
    binaryAttachment.setXPath("@binaryAttachment");
    descriptor.addMapping(binaryAttachment);
    XMLDirectMapping attachmentType = new XMLDirectMapping();
    attachmentType.setAttributeName("attachmentType");
    attachmentType.setXPath("@attachmentType");
    descriptor.addMapping(attachmentType);
    XMLDirectMapping returnTypeMapping = new XMLDirectMapping();
    returnTypeMapping.setAttributeName("returnType");
    returnTypeMapping.setXPath("@returnType");
    descriptor.addMapping(returnTypeMapping);
    XMLDirectMapping catalogPatternMapping = new XMLDirectMapping();
    catalogPatternMapping.setAttributeName("catalogPattern");
    catalogPatternMapping.setXPath("@catalogPattern");
    descriptor.addMapping(catalogPatternMapping);
    XMLDirectMapping schemaPatternMapping = new XMLDirectMapping();
    schemaPatternMapping.setAttributeName("schemaPattern");
    schemaPatternMapping.setXPath("@schemaPattern");
    descriptor.addMapping(schemaPatternMapping);
    XMLDirectMapping tableNamePatternMapping = new XMLDirectMapping();
    tableNamePatternMapping.setAttributeName("tablePattern");
    tableNamePatternMapping.setXPath("@tableNamePattern");
    descriptor.addMapping(tableNamePatternMapping);
    XMLChoiceCollectionMapping additionalOperationsMapping = new XMLChoiceCollectionMapping();
    additionalOperationsMapping.setAttributeName("additionalOperations");
    additionalOperationsMapping.setContainerPolicy(new ListContainerPolicy(ArrayList.class));
    additionalOperationsMapping.addChoiceElement("procedure", ProcedureOperationModel.class);
    additionalOperationsMapping.addChoiceElement("plsql-procedure", PLSQLProcedureOperationModel.class);
    additionalOperationsMapping.addChoiceElement("sql", SQLOperationModel.class);
    additionalOperationsMapping.addChoiceElement("batch-sql", BatchSQLOperationModel.class);
    descriptor.addMapping(additionalOperationsMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ListContainerPolicy(org.eclipse.persistence.internal.queries.ListContainerPolicy) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter) ArrayList(java.util.ArrayList) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping)

Example 17 with XMLChoiceCollectionMapping

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

the class PreLoginMappingAdapter method convertMappingToXMLChoiceMapping.

/**
 * Build an XMLChoiceObjectMapping based on a particular mapping and replace that mapping with
 * the newly created XMLChoiceObjectMapping in jaxbDescriptor.
 * @param jaxbDescriptor the jaxb descriptor
 * @param jpaMapping the jpa mapping
 * @param cl the classloader
 */
@SuppressWarnings("rawtypes")
private static void convertMappingToXMLChoiceMapping(ClassDescriptor jaxbDescriptor, DatabaseMapping jpaMapping, ClassLoader cl, Session jpaSession) {
    if ((jpaMapping != null) && (jaxbDescriptor != null)) {
        if ((jpaMapping instanceof ForeignReferenceMapping) && ((jpaMapping.isAggregateCollectionMapping()) || (jpaMapping.isAggregateMapping()))) {
            // Aggregates don't have identity to create links, thus no weaved REST adapters to insert choice mappings
            return;
        }
        String attributeName = jpaMapping.getAttributeName();
        DatabaseMapping jaxbMapping = jaxbDescriptor.getMappingForAttributeName(jpaMapping.getAttributeName());
        if (!(jaxbMapping.isXMLMapping() && (jaxbMapping.isAbstractCompositeCollectionMapping() || jaxbMapping.isAbstractCompositeObjectMapping()))) {
            return;
        }
        ClassDescriptor refDesc = null;
        if (jpaMapping instanceof ForeignReferenceMapping) {
            Class clazz = ((ForeignReferenceMapping) jpaMapping).getReferenceClass();
            refDesc = jpaSession.getDescriptor(clazz);
        } else if (jpaMapping instanceof XMLCompositeObjectMapping) {
            Class clazz = ((XMLCompositeObjectMapping) jpaMapping).getReferenceClass();
            refDesc = jpaSession.getDescriptor(clazz);
        }
        if (refDesc == null) {
            return;
        }
        String adapterClassName = RestAdapterClassWriter.constructClassNameForReferenceAdapter(refDesc.getJavaClassName());
        if (adapterClassName != null) {
            try {
                if (jaxbMapping.isAbstractCompositeObjectMapping()) {
                    XMLChoiceObjectMapping xmlChoiceMapping = new XMLChoiceObjectMapping();
                    xmlChoiceMapping.setAttributeName(attributeName);
                    copyAccessorToMapping(jaxbMapping, xmlChoiceMapping);
                    xmlChoiceMapping.setProperties(jaxbMapping.getProperties());
                    XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) jaxbMapping;
                    xmlChoiceMapping.addChoiceElement(compositeMapping.getXPath(), Link.class);
                    xmlChoiceMapping.addChoiceElement(compositeMapping.getXPath(), refDesc.getJavaClass());
                    xmlChoiceMapping.setConverter(new XMLJavaTypeConverter((Class<? extends XmlAdapter<?, ?>>) Class.forName(adapterClassName, true, cl)));
                    jaxbDescriptor.removeMappingForAttributeName(jaxbMapping.getAttributeName());
                    jaxbDescriptor.addMapping(xmlChoiceMapping);
                } else if (jaxbMapping.isAbstractCompositeCollectionMapping()) {
                    XMLChoiceCollectionMapping xmlChoiceMapping = new XMLChoiceCollectionMapping();
                    xmlChoiceMapping.setAttributeName(attributeName);
                    copyAccessorToMapping(jaxbMapping, xmlChoiceMapping);
                    xmlChoiceMapping.setProperties(jaxbMapping.getProperties());
                    XMLCompositeCollectionMapping compositeMapping = (XMLCompositeCollectionMapping) jaxbMapping;
                    xmlChoiceMapping.addChoiceElement(compositeMapping.getXPath(), Link.class);
                    xmlChoiceMapping.addChoiceElement(compositeMapping.getXPath(), refDesc.getJavaClass());
                    xmlChoiceMapping.setContainerPolicy(jaxbMapping.getContainerPolicy());
                    xmlChoiceMapping.setConverter(new XMLJavaTypeConverter((Class<? extends XmlAdapter<?, ?>>) Class.forName(adapterClassName, true, cl)));
                    jaxbDescriptor.removeMappingForAttributeName(jaxbMapping.getAttributeName());
                    jaxbDescriptor.addMapping(xmlChoiceMapping);
                }
            } catch (Exception ex) {
                throw JPARSException.exceptionOccurred(ex);
            }
        }
    }
}
Also used : XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) JPARSException(org.eclipse.persistence.jpa.rs.exceptions.JPARSException) ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) XmlAdapter(jakarta.xml.bind.annotation.adapters.XmlAdapter) Link(org.eclipse.persistence.internal.jpa.rs.metadata.model.Link) XMLJavaTypeConverter(org.eclipse.persistence.internal.jaxb.XMLJavaTypeConverter)

Example 18 with XMLChoiceCollectionMapping

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

the class TestModelProject method addRootDescriptor.

public void addRootDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClassName("org.persistence.testing.jaxb.dynamic.xxx.Root");
    descriptor.setNamespaceResolver(nsResolver);
    XMLCompositeObjectMapping compObj = new XMLCompositeObjectMapping();
    compObj.setAttributeName("compObj");
    compObj.setXPath("comp-obj");
    compObj.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.CompositeObjectTarget");
    descriptor.addMapping(compObj);
    XMLCompositeCollectionMapping compColl = new XMLCompositeCollectionMapping();
    compColl.setAttributeName("compColl");
    compColl.setXPath("comp-coll/item");
    compColl.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.CompositeCollectionTarget");
    compColl.useCollectionClass(ArrayList.class);
    compColl.setContainerPolicy(ContainerPolicy.buildPolicyFor(ArrayList.class));
    descriptor.addMapping(compColl);
    XMLCompositeDirectCollectionMapping compDirColl = new XMLCompositeDirectCollectionMapping();
    compDirColl.setAttributeName("compDirColl");
    compDirColl.setXPath("comp-dir-coll");
    descriptor.addMapping(compDirColl);
    XMLBinaryDataMapping binData = new XMLBinaryDataMapping();
    binData.setAttributeName("binData");
    XMLField binDataField = new XMLField("bin-data");
    binDataField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    binData.setField(binDataField);
    binData.setShouldInlineBinaryData(true);
    descriptor.addMapping(binData);
    XMLBinaryDataCollectionMapping binDataColl = new XMLBinaryDataCollectionMapping();
    binDataColl.setAttributeName("binDataColl");
    XMLField binDataCollField = new XMLField("bin-data-coll");
    binDataCollField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    binDataColl.setField(binDataCollField);
    binDataColl.setShouldInlineBinaryData(true);
    descriptor.addMapping(binDataColl);
    XMLAnyObjectMapping anyObj = new XMLAnyObjectMapping();
    anyObj.setAttributeName("anyObj");
    anyObj.setField(new XMLField("any-obj"));
    descriptor.addMapping(anyObj);
    XMLCompositeObjectMapping anyAtt = new XMLCompositeObjectMapping();
    anyAtt.setAttributeName("anyAtt");
    anyAtt.setXPath("any-att");
    anyAtt.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.AnyAttributeTarget");
    descriptor.addMapping(anyAtt);
    XMLTransformationMapping transform = new XMLTransformationMapping();
    transform.setAttributeName("transform");
    transform.setAttributeTransformer(new AttributeTransformer());
    transform.addFieldTransformer("transform/first-val/text()", new FirstFieldTransformer());
    transform.addFieldTransformer("transform/second-val/text()", new SecondFieldTransformer());
    descriptor.addMapping(transform);
    XMLFragmentMapping frag = new XMLFragmentMapping();
    frag.setAttributeName("frag");
    frag.setXPath("frag");
    descriptor.addMapping(frag);
    XMLFragmentCollectionMapping fragColl = new XMLFragmentCollectionMapping();
    fragColl.setAttributeName("fragColl");
    fragColl.setXPath("frag-coll");
    fragColl.useCollectionClass(ArrayList.class);
    descriptor.addMapping(fragColl);
    XMLObjectReferenceMapping objRef = new XMLObjectReferenceMapping();
    objRef.setAttributeName("objRef");
    objRef.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.ObjectReferenceTarget");
    objRef.addSourceToTargetKeyFieldAssociation("obj-ref-id/text()", "@id");
    descriptor.addMapping(objRef);
    XMLCollectionReferenceMapping collRef = new XMLCollectionReferenceMapping();
    collRef.setAttributeName("collRef");
    collRef.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.CollectionReferenceTarget");
    collRef.addSourceToTargetKeyFieldAssociation("coll-ref-id/text()", "@id");
    descriptor.addMapping(collRef);
    XMLChoiceObjectMapping choice = new XMLChoiceObjectMapping();
    choice.setAttributeName("choice");
    choice.addChoiceElement("choice-int/text()", Integer.class);
    choice.addChoiceElement("choice-float/text()", Float.class);
    descriptor.addMapping(choice);
    XMLChoiceCollectionMapping choiceColl = new XMLChoiceCollectionMapping();
    choiceColl.setAttributeName("choiceColl");
    choiceColl.addChoiceElement("choice-coll-double/text()", Double.class);
    choiceColl.addChoiceElement("choice-coll-string/text()", String.class);
    choiceColl.addChoiceElement("choice-coll-boolean/text()", Boolean.class);
    descriptor.addMapping(choiceColl);
    this.addDescriptor(descriptor);
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) ArrayList(java.util.ArrayList) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) SecondFieldTransformer(org.eclipse.persistence.testing.jaxb.dynamic.util.SecondFieldTransformer) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) XMLFragmentCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLFragmentCollectionMapping) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) FirstFieldTransformer(org.eclipse.persistence.testing.jaxb.dynamic.util.FirstFieldTransformer) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) AttributeTransformer(org.eclipse.persistence.testing.jaxb.dynamic.util.AttributeTransformer) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLFragmentMapping(org.eclipse.persistence.oxm.mappings.XMLFragmentMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)

Aggregations

XMLChoiceCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping)18 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)13 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)11 ArrayList (java.util.ArrayList)6 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)6 XMLField (org.eclipse.persistence.oxm.XMLField)6 XMLChoiceObjectMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping)6 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)6 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)5 XMLBinaryDataCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping)4 XMLBinaryDataMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping)4 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)4 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)4 QName (javax.xml.namespace.QName)3 XMLJavaTypeConverter (org.eclipse.persistence.internal.jaxb.XMLJavaTypeConverter)3 XMLAnyCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping)3 XMLAnyObjectMapping (org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)3 XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)3 XMLMapping (org.eclipse.persistence.oxm.mappings.XMLMapping)3 XMLTransformationMapping (org.eclipse.persistence.oxm.mappings.XMLTransformationMapping)3