Search in sources :

Example 1 with ChoiceObjectMapping

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

the class MappingsGenerator method generateMapping.

/**
 * Generate a mapping for a given Property.
 *
 * @return newly created mapping
 */
public Mapping generateMapping(Property property, Descriptor descriptor, JavaClass descriptorJavaClass, NamespaceInfo namespaceInfo) {
    if (property.isSetXmlJavaTypeAdapter()) {
        // if we are dealing with a reference, generate mapping and return
        if (property.isReference()) {
            return generateMappingForReferenceProperty(property, descriptor, namespaceInfo);
        }
        XmlJavaTypeAdapter xja = property.getXmlJavaTypeAdapter();
        JavaClass adapterClass = helper.getJavaClass(xja.getValue());
        JavaClass valueType = null;
        String sValType = xja.getValueType();
        if (sValType.equals("jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter.DEFAULT")) {
            valueType = property.getActualType();
        } else {
            valueType = helper.getJavaClass(xja.getValueType());
        }
        Mapping mapping;
        boolean isArray = property.getType().isArray() && !property.getType().getRawName().equals("byte[]");
        // a composite mapping
        if (property.isChoice()) {
            if (helper.isCollectionType(property.getType()) || property.getType().isArray()) {
                mapping = generateChoiceCollectionMapping(property, descriptor, namespaceInfo);
                ((ChoiceCollectionMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
            } else {
                mapping = generateChoiceMapping(property, descriptor, namespaceInfo);
                ((ChoiceObjectMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
            }
        } else if (typeInfo.containsKey(valueType.getQualifiedName())) {
            TypeInfo reference = typeInfo.get(valueType.getQualifiedName());
            if (helper.isCollectionType(property.getType())) {
                if (reference.isEnumerationType()) {
                    mapping = generateEnumCollectionMapping(property, descriptor, namespaceInfo, (EnumTypeInfo) reference);
                    XMLJavaTypeConverter converter = new XMLJavaTypeConverter(adapterClass.getQualifiedName());
                    converter.setNestedConverter(((DirectCollectionMapping) mapping).getValueConverter());
                    ((DirectCollectionMapping) mapping).setValueConverter(converter);
                } else {
                    if (property.getVariableAttributeName() != null) {
                        mapping = generateVariableXPathCollectionMapping(property, descriptor, namespaceInfo, valueType);
                        ((VariableXPathCollectionMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
                    } else {
                        mapping = generateCompositeCollectionMapping(property, descriptor, descriptorJavaClass, namespaceInfo, valueType.getQualifiedName());
                        ((CompositeCollectionMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
                    }
                }
            } else {
                if (reference.isEnumerationType()) {
                    mapping = generateDirectEnumerationMapping(property, descriptor, namespaceInfo, (EnumTypeInfo) reference);
                    XMLJavaTypeConverter converter = new XMLJavaTypeConverter(adapterClass.getQualifiedName());
                    converter.setNestedConverter(((DirectMapping) mapping).getConverter());
                    ((DirectMapping) mapping).setConverter(converter);
                } else if (property.isInverseReference()) {
                    mapping = generateInverseReferenceMapping(property, descriptor, namespaceInfo);
                } else {
                    if (property.getVariableAttributeName() != null) {
                        mapping = generateVariableXPathObjectMapping(property, descriptor, namespaceInfo, valueType);
                        ((VariableXPathObjectMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
                    } else {
                        mapping = generateCompositeObjectMapping(property, descriptor, namespaceInfo, valueType.getQualifiedName());
                        ((CompositeObjectMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
                    }
                }
            }
        } else {
            // no descriptor for value type
            if (property.isAny()) {
                if (helper.isCollectionType(property.getType())) {
                    mapping = generateAnyCollectionMapping(property, descriptor, namespaceInfo, property.isMixedContent());
                    ((AnyCollectionMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
                } else {
                    mapping = generateAnyObjectMapping(property, descriptor, namespaceInfo);
                    ((AnyObjectMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
                }
            } else if (helper.isCollectionType(property.getType()) || isArray) {
                if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
                    mapping = generateBinaryDataCollectionMapping(property, descriptor, namespaceInfo);
                    ((BinaryDataCollectionMapping) mapping).setValueConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
                } else {
                    mapping = generateDirectCollectionMapping(property, descriptor, namespaceInfo);
                    if (adapterClass.getQualifiedName().equals(CollapsedStringAdapter.class.getName())) {
                        ((DirectCollectionMapping) mapping).setCollapsingStringValues(true);
                    } else if (adapterClass.getQualifiedName().equals(NormalizedStringAdapter.class.getName())) {
                        ((DirectCollectionMapping) mapping).setNormalizingStringValues(true);
                    } else {
                        ((DirectCollectionMapping) mapping).setValueConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
                    }
                }
            } else if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
                mapping = generateBinaryMapping(property, descriptor, namespaceInfo);
                ((BinaryDataMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
            } else {
                if (!property.isAttribute() && areEquals(valueType, Object.class) || property.isTyped()) {
                    mapping = generateCompositeObjectMapping(property, descriptor, namespaceInfo, null);
                    ((CompositeObjectMapping) mapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
                    ((CompositeObjectMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
                    return mapping;
                }
                mapping = generateDirectMapping(property, descriptor, namespaceInfo);
                if (adapterClass.getQualifiedName().equals(CollapsedStringAdapter.class.getName())) {
                    ((DirectMapping) mapping).setCollapsingStringValues(true);
                } else if (adapterClass.getQualifiedName().equals(NormalizedStringAdapter.class.getName())) {
                    ((DirectMapping) mapping).setNormalizingStringValues(true);
                } else {
                    ((DirectMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
                }
            }
        }
        return mapping;
    }
    if (property.getVariableAttributeName() != null) {
        if (helper.isCollectionType(property.getType()) || property.getType().isArray() || property.isMap()) {
            return generateVariableXPathCollectionMapping(property, descriptor, namespaceInfo, property.getActualType());
        } else {
            return generateVariableXPathObjectMapping(property, descriptor, namespaceInfo, property.getActualType());
        }
    }
    if (property.isSetXmlJoinNodes()) {
        if (helper.isCollectionType(property.getType())) {
            return generateXMLCollectionReferenceMapping(property, descriptor, namespaceInfo, property.getActualType());
        }
        return generateXMLObjectReferenceMapping(property, descriptor, namespaceInfo, property.getType());
    }
    if (property.isXmlTransformation()) {
        return generateTransformationMapping(property, descriptor, namespaceInfo);
    }
    if (property.isChoice()) {
        if (helper.isCollectionType(property.getType()) || property.getType().isArray()) {
            return generateChoiceCollectionMapping(property, descriptor, namespaceInfo);
        }
        return generateChoiceMapping(property, descriptor, namespaceInfo);
    }
    if (property.isInverseReference()) {
        return generateInverseReferenceMapping(property, descriptor, namespaceInfo);
    }
    if (property.isReference()) {
        return generateMappingForReferenceProperty(property, descriptor, namespaceInfo);
    }
    if (property.isAny()) {
        if (helper.isCollectionType(property.getType()) || property.getType().isArray()) {
            return generateAnyCollectionMapping(property, descriptor, namespaceInfo, property.isMixedContent());
        }
        return generateAnyObjectMapping(property, descriptor, namespaceInfo);
    }
    if (property.isMap()) {
        if (property.isAnyAttribute()) {
            return generateAnyAttributeMapping(property, descriptor, namespaceInfo);
        }
        return generateCompositeCollectionMapping(property, descriptor, descriptorJavaClass, namespaceInfo, null);
    }
    if (helper.isCollectionType(property.getType())) {
        return generateCollectionMapping(property, descriptor, descriptorJavaClass, namespaceInfo);
    }
    JavaClass referenceClass = property.getType();
    String referenceClassName = referenceClass.getRawName();
    if (referenceClass.isArray() && !referenceClassName.equals("byte[]")) {
        JavaClass componentType = referenceClass.getComponentType();
        TypeInfo reference = typeInfo.get(componentType.getName());
        if (reference != null && reference.isEnumerationType()) {
            return generateEnumCollectionMapping(property, descriptor, namespaceInfo, (EnumTypeInfo) reference);
        }
        if (areEquals(componentType, Object.class)) {
            CompositeCollectionMapping mapping = generateCompositeCollectionMapping(property, descriptor, descriptorJavaClass, namespaceInfo, null);
            mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
            return mapping;
        }
        if (reference != null || componentType.isArray()) {
            if (property.isXmlIdRef() || property.isSetXmlJoinNodes()) {
                return generateXMLCollectionReferenceMapping(property, descriptor, namespaceInfo, componentType);
            }
            return generateCompositeCollectionMapping(property, descriptor, descriptorJavaClass, namespaceInfo, componentType.getQualifiedName());
        }
        return generateDirectCollectionMapping(property, descriptor, namespaceInfo);
    }
    if (property.isXmlIdRef()) {
        return generateXMLObjectReferenceMapping(property, descriptor, namespaceInfo, referenceClass);
    }
    TypeInfo reference = typeInfo.get(referenceClass.getQualifiedName());
    if (reference != null) {
        if (reference.isEnumerationType()) {
            return generateDirectEnumerationMapping(property, descriptor, namespaceInfo, (EnumTypeInfo) reference);
        }
        if (property.isXmlLocation()) {
            CompositeObjectMapping locationMapping = generateCompositeObjectMapping(property, descriptor, namespaceInfo, referenceClass.getQualifiedName());
            reference.getDescriptor().setInstantiationPolicy(new NullInstantiationPolicy());
            descriptor.setLocationAccessor(locationMapping.getAttributeAccessor());
            return locationMapping;
        } else {
            return generateCompositeObjectMapping(property, descriptor, namespaceInfo, referenceClass.getQualifiedName());
        }
    }
    if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
        return generateBinaryMapping(property, descriptor, namespaceInfo);
    }
    if (referenceClass.getQualifiedName().equals(OBJECT_CLASS_NAME) && !property.isAttribute() || property.isTyped()) {
        CompositeObjectMapping coMapping = generateCompositeObjectMapping(property, descriptor, namespaceInfo, null);
        coMapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
        return coMapping;
    }
    if (property.isXmlLocation()) {
        return null;
    }
    return generateDirectMapping(property, descriptor, namespaceInfo);
}
Also used : CollapsedStringAdapter(jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter) XmlJavaTypeAdapter(org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter) XMLVariableXPathObjectMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathObjectMapping) AnyObjectMapping(org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) VariableXPathCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathCollectionMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping) XMLVariableXPathCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathCollectionMapping) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) XMLMapping(org.eclipse.persistence.oxm.mappings.XMLMapping) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) VariableXPathObjectMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathObjectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) CollectionReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) TransformationMapping(org.eclipse.persistence.internal.oxm.mappings.TransformationMapping) ObjectReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping) XMLAnyAttributeMapping(org.eclipse.persistence.oxm.mappings.XMLAnyAttributeMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) InverseReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) AnyCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) AnyAttributeMapping(org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) XMLContainerMapping(org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) NormalizedStringAdapter(jakarta.xml.bind.annotation.adapters.NormalizedStringAdapter) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLVariableXPathObjectMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathObjectMapping) VariableXPathObjectMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathObjectMapping) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) XMLJavaTypeConverter(org.eclipse.persistence.internal.jaxb.XMLJavaTypeConverter) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping)

Example 2 with ChoiceObjectMapping

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

the class SchemaModelGenerator method processMapping.

/**
 * Process a given mapping.
 */
protected void processMapping(CoreMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) {
    if (mapping instanceof BinaryDataMapping) {
        processXMLBinaryDataMapping((BinaryDataMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties);
    } else if (mapping instanceof BinaryDataCollectionMapping) {
        processXMLBinaryDataCollectionMapping((BinaryDataCollectionMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties);
    } else if (mapping instanceof DirectMapping) {
        processXMLDirectMapping((DirectMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties);
    } else if (mapping instanceof DirectCollectionMapping) {
        processXMLCompositeDirectCollectionMapping((DirectCollectionMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties);
    } else if (mapping instanceof CompositeCollectionMapping) {
        processXMLCompositeMapping((CompositeCollectionMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors, true);
    } else if (mapping instanceof CompositeObjectMapping) {
        processXMLCompositeMapping((CompositeObjectMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors, false);
    } else if (mapping instanceof AnyAttributeMapping) {
        AnyAttribute anyAttribute = new AnyAttribute();
        anyAttribute.setProcessContents(AnyAttribute.LAX);
        ct.setAnyAttribute(anyAttribute);
    } else if (mapping instanceof AnyObjectMapping) {
        processAnyMapping(seq, false);
    } else if (mapping instanceof AnyCollectionMapping) {
        processAnyMapping(seq, true);
    } else if (mapping instanceof ChoiceObjectMapping) {
        processXMLChoiceObjectMapping((ChoiceObjectMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors);
    } else if (mapping instanceof ChoiceCollectionMapping) {
        processXMLChoiceCollectionMapping((ChoiceCollectionMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors);
    } else if (mapping instanceof CollectionReferenceMapping) {
        processXMLObjectReferenceMapping((CollectionReferenceMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors, true);
    } else if (mapping instanceof ObjectReferenceMapping) {
        processXMLObjectReferenceMapping((ObjectReferenceMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors, false);
    }
}
Also used : AnyAttribute(org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute) ObjectReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping) AnyObjectMapping(org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping) AnyCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) CollectionReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) AnyAttributeMapping(org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping)

Example 3 with ChoiceObjectMapping

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

the class XPathObjectBuilder method lazyInitialize.

void lazyInitialize() {
    if (initialized) {
        return;
    }
    synchronized (this) {
        if (initialized) {
            return;
        }
        Descriptor xmlDescriptor = (Descriptor) descriptor;
        // MAPPINGS
        Iterator mappingIterator = xmlDescriptor.getMappings().iterator();
        Iterator fieldTransformerIterator;
        Mapping xmlMapping;
        // Transformation Mapping
        TransformationMapping transformationMapping;
        FieldTransformerNodeValue fieldTransformerNodeValue;
        Object[] nextFieldToTransformer;
        // Simple Type Translator
        TypeNodeValue typeNodeValue;
        NodeValue mappingNodeValue = null;
        Field xmlField;
        while (mappingIterator.hasNext()) {
            xmlMapping = (Mapping) mappingIterator.next();
            xmlField = (Field) xmlMapping.getField();
            if (xmlMapping.isTransformationMapping()) {
                transformationMapping = (TransformationMapping) xmlMapping;
                addTransformationMapping(transformationMapping);
                fieldTransformerIterator = transformationMapping.getFieldToTransformers().iterator();
                while (fieldTransformerIterator.hasNext()) {
                    fieldTransformerNodeValue = new FieldTransformerNodeValue(transformationMapping);
                    nextFieldToTransformer = (Object[]) fieldTransformerIterator.next();
                    xmlField = (Field) nextFieldToTransformer[0];
                    fieldTransformerNodeValue.setXMLField(xmlField);
                    fieldTransformerNodeValue.setFieldTransformer((CoreFieldTransformer) nextFieldToTransformer[1]);
                    addChild(xmlField.getXPathFragment(), fieldTransformerNodeValue, xmlDescriptor.getNamespaceResolver());
                }
            } else {
                if (xmlMapping.isAbstractDirectMapping()) {
                    mappingNodeValue = new XMLDirectMappingNodeValue((DirectMapping) xmlMapping);
                } else if (xmlMapping.isAbstractCompositeObjectMapping()) {
                    mappingNodeValue = new XMLCompositeObjectMappingNodeValue((CompositeObjectMapping) xmlMapping);
                } else if (xmlMapping.isAbstractCompositeCollectionMapping()) {
                    CompositeCollectionMapping collectionMapping = (CompositeCollectionMapping) xmlMapping;
                    mappingNodeValue = new XMLCompositeCollectionMappingNodeValue(collectionMapping);
                    if (collectionMapping.getWrapperNullPolicy() != null) {
                        addChild(xmlField.getXPathFragment(), new CollectionGroupingElementNodeValue((ContainerValue) mappingNodeValue), xmlDescriptor.getNamespaceResolver());
                    }
                } else if (xmlMapping.isAbstractCompositeDirectCollectionMapping()) {
                    DirectCollectionMapping collectionMapping = (DirectCollectionMapping) xmlMapping;
                    mappingNodeValue = new XMLCompositeDirectCollectionMappingNodeValue(collectionMapping);
                    if (collectionMapping.getWrapperNullPolicy() != null) {
                        addChild(xmlField.getXPathFragment(), new CollectionGroupingElementNodeValue((ContainerValue) mappingNodeValue), xmlDescriptor.getNamespaceResolver());
                    }
                } else if (xmlMapping instanceof InverseReferenceMapping) {
                    xmlMapping = (Mapping) ((InverseReferenceMapping) xmlMapping).getInlineMapping();
                    if (xmlMapping == null) {
                        continue;
                    }
                    xmlField = (Field) xmlMapping.getField();
                    if (xmlMapping.isAbstractCompositeCollectionMapping()) {
                        mappingNodeValue = new XMLCompositeCollectionMappingNodeValue((CompositeCollectionMapping) xmlMapping, true);
                    }
                    if (xmlMapping.isAbstractCompositeObjectMapping()) {
                        mappingNodeValue = new XMLCompositeObjectMappingNodeValue((CompositeObjectMapping) xmlMapping, true);
                    }
                } else if (xmlMapping instanceof VariableXPathCollectionMapping) {
                    mappingNodeValue = new XMLVariableXPathCollectionMappingNodeValue((VariableXPathCollectionMapping) xmlMapping);
                } else if (xmlMapping instanceof VariableXPathObjectMapping) {
                    mappingNodeValue = new XMLVariableXPathObjectMappingNodeValue((VariableXPathObjectMapping) xmlMapping);
                } else if (xmlMapping instanceof AnyObjectMapping) {
                    mappingNodeValue = new XMLAnyObjectMappingNodeValue((AnyObjectMapping) xmlMapping);
                } else if (xmlMapping instanceof AnyCollectionMapping) {
                    mappingNodeValue = new XMLAnyCollectionMappingNodeValue((AnyCollectionMapping) xmlMapping);
                } else if (xmlMapping instanceof AnyAttributeMapping) {
                    mappingNodeValue = new XMLAnyAttributeMappingNodeValue((AnyAttributeMapping) xmlMapping);
                } else if (xmlMapping instanceof BinaryDataMapping) {
                    mappingNodeValue = new XMLBinaryDataMappingNodeValue((BinaryDataMapping) xmlMapping);
                } else if (xmlMapping instanceof BinaryDataCollectionMapping) {
                    mappingNodeValue = new XMLBinaryDataCollectionMappingNodeValue((BinaryDataCollectionMapping) xmlMapping);
                } else if (xmlMapping instanceof FragmentMapping) {
                    mappingNodeValue = new XMLFragmentMappingNodeValue((FragmentMapping) xmlMapping);
                } else if (xmlMapping instanceof FragmentCollectionMapping) {
                    mappingNodeValue = new XMLFragmentCollectionMappingNodeValue((FragmentCollectionMapping) xmlMapping);
                } else if (xmlMapping instanceof CollectionReferenceMapping) {
                    CollectionReferenceMapping xmlColMapping = (CollectionReferenceMapping) xmlMapping;
                    List fields = xmlColMapping.getFields();
                    Field xmlColMappingField = (Field) xmlColMapping.getField();
                    XPathNode branchNode;
                    if (null == xmlColMappingField) {
                        if (fields.size() > 1 && !xmlColMapping.usesSingleNode()) {
                            addChild(XPathFragment.SELF_FRAGMENT, new XMLCollectionReferenceMappingMarshalNodeValue(xmlColMapping), xmlDescriptor.getNamespaceResolver());
                        }
                        branchNode = rootXPathNode;
                    } else {
                        branchNode = addChild(((Field) xmlColMapping.getField()).getXPathFragment(), new XMLCollectionReferenceMappingMarshalNodeValue(xmlColMapping), xmlDescriptor.getNamespaceResolver());
                    }
                    int containerIndex = -1;
                    for (int i = 0, size = fields.size(); i < size; i++) {
                        Field xmlFld = (Field) fields.get(i);
                        mappingNodeValue = new XMLCollectionReferenceMappingNodeValue(xmlColMapping, xmlFld);
                        if (i == 0) {
                            addContainerValue((ContainerValue) mappingNodeValue);
                            containerIndex = ((ContainerValue) mappingNodeValue).getIndex();
                        } else {
                            ((ContainerValue) mappingNodeValue).setIndex(containerIndex);
                        }
                        branchNode.addChild(xmlFld.getXPathFragment(), mappingNodeValue, xmlDescriptor.getNamespaceResolver());
                    }
                    continue;
                } else if (xmlMapping instanceof ObjectReferenceMapping) {
                    ObjectReferenceMapping xmlORMapping = (ObjectReferenceMapping) xmlMapping;
                    Iterator fieldIt = xmlORMapping.getFields().iterator();
                    while (fieldIt.hasNext()) {
                        Field xmlFld = (Field) fieldIt.next();
                        mappingNodeValue = new XMLObjectReferenceMappingNodeValue(xmlORMapping, xmlFld);
                        addChild(xmlFld.getXPathFragment(), mappingNodeValue, xmlDescriptor.getNamespaceResolver());
                    }
                    continue;
                } else if (xmlMapping instanceof ChoiceObjectMapping) {
                    ChoiceObjectMapping xmlChoiceMapping = (ChoiceObjectMapping) xmlMapping;
                    Iterator fields = xmlChoiceMapping.getChoiceElementMappings().keySet().iterator();
                    Field firstField = (Field) fields.next();
                    XMLChoiceObjectMappingNodeValue firstNodeValue = new XMLChoiceObjectMappingNodeValue(xmlChoiceMapping, firstField);
                    firstNodeValue.setNullCapableNodeValue(firstNodeValue);
                    addChild(firstField.getXPathFragment(), firstNodeValue, xmlDescriptor.getNamespaceResolver());
                    while (fields.hasNext()) {
                        Field next = (Field) fields.next();
                        XMLChoiceObjectMappingNodeValue nodeValue = new XMLChoiceObjectMappingNodeValue(xmlChoiceMapping, next);
                        nodeValue.setNullCapableNodeValue(firstNodeValue);
                        addChild(next.getXPathFragment(), nodeValue, xmlDescriptor.getNamespaceResolver());
                    }
                    continue;
                } else if (xmlMapping instanceof ChoiceCollectionMapping) {
                    ChoiceCollectionMapping xmlChoiceMapping = (ChoiceCollectionMapping) xmlMapping;
                    Iterator<Entry<Field, Mapping>> fields = xmlChoiceMapping.getChoiceElementMappings().entrySet().iterator();
                    Entry<Field, Mapping> firstEntry = fields.next();
                    Field firstField = firstEntry.getKey();
                    XMLChoiceCollectionMappingUnmarshalNodeValue unmarshalValue = new XMLChoiceCollectionMappingUnmarshalNodeValue(xmlChoiceMapping, firstField);
                    XMLChoiceCollectionMappingMarshalNodeValue marshalValue = new XMLChoiceCollectionMappingMarshalNodeValue(xmlChoiceMapping, firstField);
                    // The reason behind LinkedHashMap is the order of items when for-cycling HashMap.getEntrySet() or HashMap.getKeySet().
                    // This change fixes non-determinism (implementation in JDK8 has changed so the order is different (sometimes) than in JDK6 and JDK7).
                    HashMap<Field, NodeValue> fieldToNodeValues = new LinkedHashMap<>();
                    unmarshalValue.setContainerNodeValue(unmarshalValue);
                    unmarshalValue.setFieldToNodeValues(fieldToNodeValues);
                    if (xmlChoiceMapping.isMixedContent() && (xmlChoiceMapping.getMixedContentMapping() == firstEntry.getValue())) {
                        unmarshalValue.setIsMixedNodeValue(true);
                        marshalValue.setIsMixedNodeValue(true);
                    }
                    this.addContainerValue(unmarshalValue);
                    ((ContainerValue) unmarshalValue.getChoiceElementNodeValue()).setIndex(unmarshalValue.getIndex());
                    fieldToNodeValues.put(firstField, unmarshalValue);
                    addChild(firstField.getXPathFragment(), unmarshalValue, xmlDescriptor.getNamespaceResolver());
                    addChild(firstField.getXPathFragment(), marshalValue, xmlDescriptor.getNamespaceResolver());
                    while (fields.hasNext()) {
                        Entry<Field, Mapping> nextEntry = fields.next();
                        Field nextField = nextEntry.getKey();
                        XMLChoiceCollectionMappingUnmarshalNodeValue nodeValue = new XMLChoiceCollectionMappingUnmarshalNodeValue(xmlChoiceMapping, nextField);
                        nodeValue.setContainerNodeValue(unmarshalValue);
                        nodeValue.setIndex(unmarshalValue.getIndex());
                        ((ContainerValue) nodeValue.getChoiceElementNodeValue()).setIndex(unmarshalValue.getIndex());
                        addChild(nextField.getXPathFragment(), nodeValue, xmlDescriptor.getNamespaceResolver());
                        fieldToNodeValues.put(nextField, nodeValue);
                        if (xmlChoiceMapping.isMixedContent() && (xmlChoiceMapping.getMixedContentMapping() == nextEntry.getValue())) {
                            nodeValue.setIsMixedNodeValue(true);
                        }
                    }
                    if (xmlChoiceMapping.isAny()) {
                        XMLChoiceCollectionMappingUnmarshalNodeValue nodeValue = new XMLChoiceCollectionMappingUnmarshalNodeValue(xmlChoiceMapping, null, xmlChoiceMapping.getAnyMapping());
                        nodeValue.setContainerNodeValue(unmarshalValue);
                        nodeValue.setIndex(unmarshalValue.getIndex());
                        ((ContainerValue) nodeValue.getChoiceElementNodeValue()).setIndex(unmarshalValue.getIndex());
                        addChild(null, nodeValue, xmlDescriptor.getNamespaceResolver());
                        fieldToNodeValues.put(null, nodeValue);
                        if (xmlChoiceMapping.isMixedContent()) {
                            nodeValue.setIsMixedNodeValue(true);
                        }
                    }
                    marshalValue.setFieldToNodeValues(fieldToNodeValues);
                    continue;
                }
                if (mappingNodeValue.isContainerValue()) {
                    addContainerValue((ContainerValue) mappingNodeValue);
                }
                if (mappingNodeValue.isNullCapableValue()) {
                    addNullCapableValue((NullCapableValue) mappingNodeValue);
                }
                if (xmlField != null) {
                    addChild(xmlField.getXPathFragment(), mappingNodeValue, xmlDescriptor.getNamespaceResolver());
                } else {
                    addChild(null, mappingNodeValue, xmlDescriptor.getNamespaceResolver());
                }
            }
        }
        if (descriptor.hasInheritance()) {
            Field indicatorField = (Field) descriptor.getInheritancePolicy().getClassIndicatorField();
            if (indicatorField != null) {
                if (indicatorField.getLastXPathFragment().getNamespaceURI() != null && indicatorField.getLastXPathFragment().getNamespaceURI().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI) && indicatorField.getLastXPathFragment().getLocalName().equals(Constants.SCHEMA_TYPE_ATTRIBUTE)) {
                    xsiTypeIndicatorField = true;
                }
            }
        }
        initialized = true;
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) VariableXPathCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathCollectionMapping) TransformationMapping(org.eclipse.persistence.internal.oxm.mappings.TransformationMapping) ObjectReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping) AnyObjectMapping(org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) InverseReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping) VariableXPathCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathCollectionMapping) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) AnyCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) FragmentMapping(org.eclipse.persistence.internal.oxm.mappings.FragmentMapping) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping) FragmentCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.FragmentCollectionMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) AnyAttributeMapping(org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) VariableXPathObjectMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathObjectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) CollectionReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) CollectionReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping) FragmentCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.FragmentCollectionMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) List(java.util.List) ArrayList(java.util.ArrayList) InverseReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping) ObjectReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping) TransformationMapping(org.eclipse.persistence.internal.oxm.mappings.TransformationMapping) AnyCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) CoreDescriptor(org.eclipse.persistence.core.descriptors.CoreDescriptor) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) SequencedObject(org.eclipse.persistence.oxm.sequenced.SequencedObject) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping) AnyObjectMapping(org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) Field(org.eclipse.persistence.internal.oxm.mappings.Field) CoreField(org.eclipse.persistence.internal.core.helper.CoreField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) VariableXPathObjectMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathObjectMapping) FragmentMapping(org.eclipse.persistence.internal.oxm.mappings.FragmentMapping) AnyAttributeMapping(org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping)

Example 4 with ChoiceObjectMapping

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

the class MappingsGenerator method generateMappingForReferenceProperty.

public Mapping generateMappingForReferenceProperty(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo) {
    boolean isCollection = helper.isCollectionType(property.getType()) || property.getType().isArray();
    Mapping mapping;
    if (isCollection) {
        mapping = new XMLChoiceCollectionMapping();
        initializeXMLContainerMapping((ChoiceCollectionMapping) mapping, property.getType().isArray());
        JavaClass collectionType = property.getType();
        collectionType = containerClassImpl(collectionType);
        ((ChoiceCollectionMapping) mapping).useCollectionClassName(collectionType.getRawName());
        JAXBElementRootConverter jaxbERConverter = new JAXBElementRootConverter(Object.class);
        if (property.isSetXmlJavaTypeAdapter()) {
            JavaClass adapterClass = helper.getJavaClass(property.getXmlJavaTypeAdapter().getValue());
            jaxbERConverter.setNestedConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
        ((ChoiceCollectionMapping) mapping).setConverter(jaxbERConverter);
        if (property.isSetWriteOnly()) {
            ((ChoiceCollectionMapping) mapping).setIsWriteOnly(property.isWriteOnly());
        }
        if (property.isSetXmlElementWrapper()) {
            ((ChoiceCollectionMapping) mapping).setWrapperNullPolicy(getWrapperNullPolicyFromProperty(property));
        }
    } else {
        mapping = new XMLChoiceObjectMapping();
        JAXBElementRootConverter jaxbERConverter = new JAXBElementRootConverter(Object.class);
        if (property.isSetXmlJavaTypeAdapter()) {
            JavaClass adapterClass = helper.getJavaClass(property.getXmlJavaTypeAdapter().getValue());
            jaxbERConverter.setNestedConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
        ((ChoiceObjectMapping) mapping).setConverter(jaxbERConverter);
        if (property.isSetWriteOnly()) {
            ((ChoiceObjectMapping) mapping).setIsWriteOnly(property.isWriteOnly());
        }
    }
    initializeXMLMapping((XMLMapping) mapping, property);
    List<ElementDeclaration> referencedElements = property.getReferencedElements();
    JavaClass propertyType = property.getType();
    if (propertyType.isArray()) {
        JAXBArrayAttributeAccessor accessor = new JAXBArrayAttributeAccessor(mapping.getAttributeAccessor(), mapping.getContainerPolicy(), helper.getClassLoader());
        accessor.setComponentClassName(property.getType().getComponentType().getQualifiedName());
        JavaClass componentType = propertyType.getComponentType();
        if (componentType.isArray()) {
            Class<?> adaptedClass = classToGeneratedClasses.get(componentType.getQualifiedName());
            accessor.setAdaptedClassName(adaptedClass.getName());
        }
        mapping.setAttributeAccessor(accessor);
    }
    String wrapperXPath = "";
    // handle XmlElementWrapper
    if (property.isSetXmlElementWrapper()) {
        XmlElementWrapper wrapper = property.getXmlElementWrapper();
        String namespace = wrapper.getNamespace();
        if (namespace.equals(XMLProcessor.DEFAULT)) {
            if (namespaceInfo.isElementFormQualified()) {
                namespace = namespaceInfo.getNamespace();
            } else {
                namespace = "";
            }
        }
        if (namespace.equals("")) {
            wrapperXPath += (wrapper.getName() + "/");
        } else {
            String prefix = getPrefixForNamespace(namespace, getNamespaceResolverForDescriptor(namespaceInfo));
            wrapperXPath += getQualifiedString(prefix, wrapper.getName() + "/");
        }
    }
    if (property.isMixedContent() && isCollection) {
        if (wrapperXPath.length() == 0) {
            ((ChoiceCollectionMapping) mapping).setMixedContent(true);
        } else {
            ((ChoiceCollectionMapping) mapping).setMixedContent(wrapperXPath.substring(0, wrapperXPath.length() - 1));
        }
    }
    for (ElementDeclaration element : referencedElements) {
        QName elementName = element.getElementName();
        JavaClass pType = element.getJavaType();
        String pTypeName = element.getJavaTypeName();
        boolean isBinaryType = (areEquals(pType, AnnotationsProcessor.JAVAX_ACTIVATION_DATAHANDLER) || areEquals(pType, byte[].class) || areEquals(pType, Image.class) || areEquals(pType, Source.class) || areEquals(pType, AnnotationsProcessor.JAVAX_MAIL_INTERNET_MIMEMULTIPART));
        boolean isText = pType.isEnum() || (!isBinaryType && !(this.typeInfo.containsKey(element.getJavaTypeName())) && !(element.getJavaTypeName().equals(OBJECT_CLASS_NAME)));
        String xPath = wrapperXPath;
        Field xmlField = this.getXPathForElement(xPath, elementName, namespaceInfo, isText);
        // ensure byte[] goes to base64 instead of the default hex.
        if (helper.getXMLToJavaTypeMap().get(pType.getRawName()) == Constants.BASE_64_BINARY_QNAME) {
            xmlField.setSchemaType(Constants.BASE_64_BINARY_QNAME);
        }
        if (areEquals(pType, Object.class)) {
            setTypedTextField(xmlField);
        }
        Mapping nestedMapping;
        AbstractNullPolicy nullPolicy = null;
        if (isCollection) {
            ChoiceCollectionMapping xmlChoiceCollectionMapping = (ChoiceCollectionMapping) mapping;
            xmlChoiceCollectionMapping.addChoiceElement(xmlField, pTypeName);
            nestedMapping = (Mapping) xmlChoiceCollectionMapping.getChoiceElementMappings().get(xmlField);
            if (nestedMapping.isAbstractCompositeCollectionMapping()) {
                ((CompositeCollectionMapping) nestedMapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
                nullPolicy = ((CompositeCollectionMapping) nestedMapping).getNullPolicy();
            }
            if (nestedMapping.isAbstractCompositeDirectCollectionMapping()) {
                DirectCollectionMapping nestedCompositeDirectCollectionMapping = (DirectCollectionMapping) nestedMapping;
                nullPolicy = nestedCompositeDirectCollectionMapping.getNullPolicy();
                if (pType.isEnum()) {
                    TypeInfo enumTypeInfo = typeInfo.get(pType.getQualifiedName());
                    nestedCompositeDirectCollectionMapping.setValueConverter(buildJAXBEnumTypeConverter(nestedCompositeDirectCollectionMapping, (EnumTypeInfo) enumTypeInfo));
                }
                if (element.isList()) {
                    XMLListConverter listConverter = new XMLListConverter();
                    listConverter.setObjectClassName(pType.getQualifiedName());
                    ((DirectCollectionMapping) nestedMapping).setValueConverter(listConverter);
                }
            } else if (nestedMapping instanceof BinaryDataCollectionMapping) {
                nullPolicy = ((BinaryDataCollectionMapping) nestedMapping).getNullPolicy();
                if (element.isList()) {
                    ((XMLField) nestedMapping.getField()).setUsesSingleNode(true);
                }
            }
        } else {
            ChoiceObjectMapping xmlChoiceObjectMapping = (ChoiceObjectMapping) mapping;
            xmlChoiceObjectMapping.addChoiceElement(xmlField, pTypeName);
            nestedMapping = (Mapping) xmlChoiceObjectMapping.getChoiceElementMappings().get(xmlField);
            if (pType.isEnum()) {
                TypeInfo enumTypeInfo = typeInfo.get(pType.getQualifiedName());
                ((DirectMapping) nestedMapping).setConverter(buildJAXBEnumTypeConverter(nestedMapping, (EnumTypeInfo) enumTypeInfo));
            }
            if (nestedMapping.isAbstractCompositeObjectMapping()) {
                ((CompositeObjectMapping) nestedMapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
                nullPolicy = ((CompositeObjectMapping) nestedMapping).getNullPolicy();
            } else if (nestedMapping instanceof BinaryDataMapping) {
                nullPolicy = ((BinaryDataMapping) nestedMapping).getNullPolicy();
            } else if (nestedMapping instanceof DirectMapping) {
                nullPolicy = ((DirectMapping) nestedMapping).getNullPolicy();
            }
        }
        if (nullPolicy != null) {
            nullPolicy.setNullRepresentedByEmptyNode(false);
            nullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
            nullPolicy.setNullRepresentedByXsiNil(true);
            nullPolicy.setIgnoreAttributesForNil(false);
        }
        if (!element.isXmlRootElement()) {
            Class<?> scopeClass = element.getScopeClass();
            if (scopeClass == jakarta.xml.bind.annotation.XmlElementDecl.GLOBAL.class) {
                scopeClass = JAXBElement.GlobalScope.class;
            }
            Class<?> declaredType = null;
            if (element.getAdaptedJavaType() != null) {
                declaredType = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(element.getAdaptedJavaType().getQualifiedName(), helper.getClassLoader());
            } else {
                declaredType = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(pType.getQualifiedName(), helper.getClassLoader());
            }
            JAXBElementConverter converter = new JAXBElementConverter(xmlField, declaredType, scopeClass);
            if (isCollection) {
                ChoiceCollectionMapping xmlChoiceCollectionMapping = (ChoiceCollectionMapping) mapping;
                if (element.getJavaTypeAdapterClass() != null) {
                    converter.setNestedConverter(new XMLJavaTypeConverter(element.getJavaTypeAdapterClass().getName()));
                } else {
                    CoreConverter originalConverter = xmlChoiceCollectionMapping.getConverter(xmlField);
                    converter.setNestedConverter(originalConverter);
                }
                xmlChoiceCollectionMapping.addConverter(xmlField, converter);
            } else {
                ChoiceObjectMapping xmlChoiceObjectMapping = (ChoiceObjectMapping) mapping;
                if (element.getJavaTypeAdapterClass() != null) {
                    converter.setNestedConverter(new XMLJavaTypeConverter(element.getJavaTypeAdapterClass().getName()));
                } else {
                    CoreConverter originalConverter = xmlChoiceObjectMapping.getConverter(xmlField);
                    converter.setNestedConverter(originalConverter);
                }
                xmlChoiceObjectMapping.addConverter(xmlField, converter);
            }
        }
    }
    if (property.isAny()) {
        if (isCollection) {
            XMLChoiceCollectionMapping xmlChoiceCollectionMapping = (XMLChoiceCollectionMapping) mapping;
            xmlChoiceCollectionMapping.setIsAny(true);
        }
    }
    return mapping;
}
Also used : XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) XMLVariableXPathObjectMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathObjectMapping) AnyObjectMapping(org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) VariableXPathCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathCollectionMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping) XMLVariableXPathCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathCollectionMapping) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) XMLMapping(org.eclipse.persistence.oxm.mappings.XMLMapping) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) VariableXPathObjectMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathObjectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) CollectionReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) TransformationMapping(org.eclipse.persistence.internal.oxm.mappings.TransformationMapping) ObjectReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping) XMLAnyAttributeMapping(org.eclipse.persistence.oxm.mappings.XMLAnyAttributeMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) InverseReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) AnyCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) AnyAttributeMapping(org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) XMLContainerMapping(org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) Source(javax.xml.transform.Source) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) XMLField(org.eclipse.persistence.oxm.XMLField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) Field(org.eclipse.persistence.internal.oxm.mappings.Field) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) CoreConverter(org.eclipse.persistence.core.mappings.converters.CoreConverter) XmlElementWrapper(org.eclipse.persistence.jaxb.xmlmodel.XmlElementWrapper) XMLJavaTypeConverter(org.eclipse.persistence.internal.jaxb.XMLJavaTypeConverter) XmlAbstractNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy) AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy) QName(javax.xml.namespace.QName) JAXBElementConverter(org.eclipse.persistence.internal.jaxb.JAXBElementConverter) JAXBElement(jakarta.xml.bind.JAXBElement) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) XMLListConverter(org.eclipse.persistence.oxm.mappings.converters.XMLListConverter) JAXBElementRootConverter(org.eclipse.persistence.internal.jaxb.JAXBElementRootConverter) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping)

Aggregations

AnyAttributeMapping (org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping)4 AnyCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping)4 AnyObjectMapping (org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping)4 BinaryDataCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping)4 BinaryDataMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping)4 ChoiceCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping)4 ChoiceObjectMapping (org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping)4 CollectionReferenceMapping (org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping)4 CompositeCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping)4 CompositeObjectMapping (org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping)4 DirectCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping)4 DirectMapping (org.eclipse.persistence.internal.oxm.mappings.DirectMapping)4 ObjectReferenceMapping (org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping)4 CoreMapping (org.eclipse.persistence.core.mappings.CoreMapping)3 InverseReferenceMapping (org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping)3 Mapping (org.eclipse.persistence.internal.oxm.mappings.Mapping)3 TransformationMapping (org.eclipse.persistence.internal.oxm.mappings.TransformationMapping)3 VariableXPathCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.VariableXPathCollectionMapping)3 VariableXPathObjectMapping (org.eclipse.persistence.internal.oxm.mappings.VariableXPathObjectMapping)3 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)3