Search in sources :

Example 1 with Mapping

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

the class MappingsGenerator method generateMappings.

/**
 * Generate mappings for a given TypeInfo.
 */
public void generateMappings(TypeInfo info, Descriptor descriptor, JavaClass descriptorJavaClass, NamespaceInfo namespaceInfo) {
    if (info.isAnonymousComplexType()) {
        // may need to generate inherited mappings
        generateInheritedMappingsForAnonymousType(info, descriptor, descriptorJavaClass, namespaceInfo);
    }
    List<Property> propertiesInOrder = info.getNonTransientPropertiesInPropOrder();
    for (int i = 0; i < propertiesInOrder.size(); i++) {
        Property next = propertiesInOrder.get(i);
        if (next != null && (!next.isTransient() || (next.isTransient() && next.isXmlLocation()))) {
            Mapping mapping = generateMapping(next, descriptor, descriptorJavaClass, namespaceInfo);
            if (next.isVirtual()) {
                VirtualAttributeAccessor accessor = new VirtualAttributeAccessor();
                accessor.setAttributeName(mapping.getAttributeName());
                String getMethod = info.getXmlVirtualAccessMethods().getGetMethod();
                String setMethod = info.getXmlVirtualAccessMethods().getSetMethod();
                // Check to see if get/set were overridden in the mapping
                if (mapping.getAttributeAccessor().isMethodAttributeAccessor()) {
                    getMethod = ((MethodAttributeAccessor) mapping.getAttributeAccessor()).getGetMethodName();
                    setMethod = ((MethodAttributeAccessor) mapping.getAttributeAccessor()).getSetMethodName();
                    accessor.setValueType(mapping.getAttributeClassification());
                }
                accessor.setGetMethodName(getMethod);
                accessor.setSetMethodName(setMethod);
                if (mapping.getAttributeAccessor() instanceof JAXBArrayAttributeAccessor) {
                    JAXBArrayAttributeAccessor jaa = (JAXBArrayAttributeAccessor) mapping.getAttributeAccessor();
                    jaa.setNestedAccessor(accessor);
                } else {
                    mapping.setAttributeAccessor(accessor);
                }
            }
            if (mapping != null) {
                descriptor.addMapping((CoreMapping) mapping);
            }
            // set user-defined properties if necessary
            if (next.isSetUserProperties()) {
                mapping.setProperties(next.getUserProperties());
            }
            // get package info
            AccessorFactoryWrapper accessorFactory = info.getXmlAccessorFactory();
            if (accessorFactory == null) {
                accessorFactory = info.getPackageLevelXmlAccessorFactory();
            }
            if (accessorFactory != null) {
                try {
                    Object accessor = CompilerHelper.createAccessorFor(descriptorJavaClass, next, helper, accessorFactory);
                    if (accessor != null) {
                        CustomAccessorAttributeAccessor attributeAccessor = new CustomAccessorAttributeAccessor(accessor);
                        mapping.setAttributeAccessor(attributeAccessor);
                    }
                } catch (Exception ex) {
                }
            }
        }
        next.postInitialize();
    }
}
Also used : VirtualAttributeAccessor(org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor) CustomAccessorAttributeAccessor(org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) AccessorFactoryWrapper(org.eclipse.persistence.internal.jaxb.AccessorFactoryWrapper) 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) JAXBException(org.eclipse.persistence.exceptions.JAXBException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException)

Example 2 with Mapping

use of org.eclipse.persistence.internal.oxm.mappings.Mapping 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 3 with Mapping

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

the class MappingsGenerator method generateMappingForType.

private Mapping generateMappingForType(JavaClass theType, String attributeName) {
    Mapping mapping;
    boolean typeIsObject = theType.getRawName().equals(OBJECT_CLASS_NAME);
    TypeInfo info = typeInfo.get(theType.getQualifiedName());
    if ((info != null && !(info.isEnumerationType())) || typeIsObject) {
        mapping = new XMLCompositeObjectMapping();
        mapping.setAttributeName(attributeName);
        ((CompositeObjectMapping) mapping).setXPath(attributeName);
        if (typeIsObject) {
            ((CompositeObjectMapping) mapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
            setTypedTextField((Field) mapping.getField());
        } else {
            ((CompositeObjectMapping) mapping).setReferenceClassName(theType.getQualifiedName());
        }
    } else if (theType.isArray() || helper.isCollectionType(theType)) {
        DirectCollectionMapping directCollectionMapping;
        mapping = directCollectionMapping = new XMLCompositeDirectCollectionMapping();
        initializeXMLContainerMapping(directCollectionMapping, theType.isArray());
        directCollectionMapping.setAttributeName(attributeName);
        if (theType.isArray()) {
            JAXBArrayAttributeAccessor accessor = new JAXBArrayAttributeAccessor(directCollectionMapping.getAttributeAccessor(), directCollectionMapping.getContainerPolicy(), helper.getClassLoader());
            String componentClassName = theType.getComponentType().getQualifiedName();
            if (theType.getComponentType().isPrimitive()) {
                Class<Object> primitiveClass = XMLConversionManager.getDefaultManager().convertClassNameToClass(componentClassName);
                accessor.setComponentClass(primitiveClass);
                directCollectionMapping.setAttributeAccessor(accessor);
                Class<Object> declaredClass = XMLConversionManager.getObjectClass(primitiveClass);
                directCollectionMapping.setAttributeElementClass(declaredClass);
            } else {
                accessor.setComponentClassName(componentClassName);
                directCollectionMapping.setAttributeAccessor(accessor);
                JavaClass componentType = theType.getComponentType();
                Class<?> declaredClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> PrivilegedAccessHelper.getClassForName(componentType.getRawName(), false, helper.getClassLoader()), (ex) -> JAXBException.classNotFoundException(componentType.getRawName()));
                directCollectionMapping.setAttributeElementClass(declaredClass);
            }
        } else if (helper.isCollectionType(theType)) {
            Collection args = theType.getActualTypeArguments();
            if (args.size() > 0) {
                JavaClass itemType = (JavaClass) args.iterator().next();
                Class<?> declaredClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> PrivilegedAccessHelper.getClassForName(itemType.getRawName(), false, helper.getClassLoader()), (ex) -> JAXBException.classNotFoundException(itemType.getRawName()));
                if (declaredClass != String.class) {
                    directCollectionMapping.setAttributeElementClass(declaredClass);
                }
            }
        }
        theType = containerClassImpl(theType);
        directCollectionMapping.useCollectionClassName(theType.getRawName());
        directCollectionMapping.setXPath(attributeName + TXT);
    } else {
        mapping = new XMLDirectMapping();
        mapping.setAttributeName(attributeName);
        ((DirectMapping) mapping).setNullValueMarshalled(true);
        ((DirectMapping) mapping).setXPath(attributeName + TXT);
        QName schemaType = userDefinedSchemaTypes.get(theType.getQualifiedName());
        if (schemaType == null) {
            schemaType = helper.getXMLToJavaTypeMap().get(theType.getName());
        }
        ((Field) mapping.getField()).setSchemaType(schemaType);
        if (info != null && info.isEnumerationType()) {
            ((DirectMapping) mapping).setConverter(buildJAXBEnumTypeConverter(mapping, (EnumTypeInfo) info));
        }
    }
    return mapping;
}
Also used : IsSetNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy) XMLVariableXPathObjectMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathObjectMapping) MethodVisitor(org.eclipse.persistence.internal.libraries.asm.MethodVisitor) CoreConverter(org.eclipse.persistence.core.mappings.converters.CoreConverter) AnyObjectMapping(org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping) JAXBEnumTypeConverter(org.eclipse.persistence.jaxb.JAXBEnumTypeConverter) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) NormalizedStringAdapter(jakarta.xml.bind.annotation.adapters.NormalizedStringAdapter) Type(org.eclipse.persistence.internal.libraries.asm.Type) XmlJavaTypeAdapter(org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) Map(java.util.Map) Constants(org.eclipse.persistence.internal.oxm.Constants) VariableXPathCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathCollectionMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) XmlTransformation(org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) UnmarshalRecord(org.eclipse.persistence.internal.oxm.record.UnmarshalRecord) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) Project(org.eclipse.persistence.sessions.Project) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping) AbstractSessionLog(org.eclipse.persistence.logging.AbstractSessionLog) Set(java.util.Set) XmlJoinNode(org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode) UnmarshalKeepAsElementPolicy(org.eclipse.persistence.oxm.mappings.UnmarshalKeepAsElementPolicy) XMLVariableXPathCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathCollectionMapping) XMLNullRepresentationType(org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType) JAXBException(org.eclipse.persistence.exceptions.JAXBException) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping) QName(javax.xml.namespace.QName) VirtualAttributeAccessor(org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor) JAXBElementConverter(org.eclipse.persistence.internal.jaxb.JAXBElementConverter) XmlIsSetNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy) AccessorFactoryWrapper(org.eclipse.persistence.internal.jaxb.AccessorFactoryWrapper) Opcodes(org.eclipse.persistence.internal.libraries.asm.Opcodes) XMLConstants(org.eclipse.persistence.oxm.XMLConstants) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) Source(javax.xml.transform.Source) FixedMimeTypePolicy(org.eclipse.persistence.oxm.mappings.FixedMimeTypePolicy) TreeSet(java.util.TreeSet) XMLTransformationRecord(org.eclipse.persistence.internal.oxm.record.XMLTransformationRecord) ArrayList(java.util.ArrayList) Introspector(java.beans.Introspector) XmlAttribute(jakarta.xml.bind.annotation.XmlAttribute) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) XMLMapping(org.eclipse.persistence.oxm.mappings.XMLMapping) XMLListConverter(org.eclipse.persistence.oxm.mappings.converters.XMLListConverter) StringTokenizer(java.util.StringTokenizer) CollapsedStringAdapter(jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter) CoreClassConstants(org.eclipse.persistence.internal.core.helper.CoreClassConstants) CustomAccessorAttributeAccessor(org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) AttributeGroup(org.eclipse.persistence.queries.AttributeGroup) CoreProject(org.eclipse.persistence.core.sessions.CoreProject) XmlElementWrapper(org.eclipse.persistence.jaxb.xmlmodel.XmlElementWrapper) EclipseLinkASMClassWriter(org.eclipse.persistence.internal.libraries.asm.EclipseLinkASMClassWriter) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) XmlMixed(jakarta.xml.bind.annotation.XmlMixed) VariableXPathObjectMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathObjectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) XmlNamedSubgraph(org.eclipse.persistence.jaxb.xmlmodel.XmlNamedSubgraph) XMLConverter(org.eclipse.persistence.oxm.mappings.converters.XMLConverter) Session(org.eclipse.persistence.sessions.Session) XMLField(org.eclipse.persistence.oxm.XMLField) JAXBSetMethodAttributeAccessor(org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) CollectionReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping) DescriptorCustomizer(org.eclipse.persistence.config.DescriptorCustomizer) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) TransformationMapping(org.eclipse.persistence.internal.oxm.mappings.TransformationMapping) SortedSet(java.util.SortedSet) ObjectReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) Converter(org.eclipse.persistence.mappings.converters.Converter) Field(org.eclipse.persistence.internal.oxm.mappings.Field) XmlReadTransformer(org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlReadTransformer) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) XMLAnyAttributeMapping(org.eclipse.persistence.oxm.mappings.XMLAnyAttributeMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) InverseReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping) SessionLog(org.eclipse.persistence.logging.SessionLog) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) MapValueAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor) NullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy) XmlNamedObjectGraph(org.eclipse.persistence.jaxb.xmlmodel.XmlNamedObjectGraph) AnyCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping) TypeMappingInfo(org.eclipse.persistence.jaxb.TypeMappingInfo) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) MethodAttributeAccessor(org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) Image(java.awt.Image) XmlValue(jakarta.xml.bind.annotation.XmlValue) Collection(java.util.Collection) XmlNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy) NamespaceResolver(org.eclipse.persistence.internal.oxm.NamespaceResolver) NavigableSet(java.util.NavigableSet) CoreAttributeGroup(org.eclipse.persistence.core.queries.CoreAttributeGroup) DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) XmlAbstractNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy) InstanceVariableAttributeAccessor(org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor) JAXBLocalization(org.eclipse.persistence.internal.localization.JAXBLocalization) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) XMLSchemaReference(org.eclipse.persistence.oxm.schema.XMLSchemaReference) MapValue(org.eclipse.persistence.internal.jaxb.many.MapValue) WrappedValue(org.eclipse.persistence.internal.jaxb.WrappedValue) List(java.util.List) JavaMethod(org.eclipse.persistence.jaxb.javamodel.JavaMethod) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) DefaultElementConverter(org.eclipse.persistence.internal.jaxb.DefaultElementConverter) Entry(java.util.Map.Entry) DomHandlerConverter(org.eclipse.persistence.internal.jaxb.DomHandlerConverter) Queue(java.util.Queue) XmlTransient(jakarta.xml.bind.annotation.XmlTransient) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) PrivilegedAccessHelper(org.eclipse.persistence.internal.security.PrivilegedAccessHelper) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XmlNamedAttributeNode(org.eclipse.persistence.jaxb.xmlmodel.XmlNamedAttributeNode) AnyAttributeMapping(org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping) HashMap(java.util.HashMap) Deque(java.util.Deque) InstantiationPolicy(org.eclipse.persistence.internal.descriptors.InstantiationPolicy) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession) HashSet(java.util.HashSet) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) LinkedList(java.util.LinkedList) Helper(org.eclipse.persistence.jaxb.javamodel.Helper) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) JAXBElementRootConverter(org.eclipse.persistence.internal.jaxb.JAXBElementRootConverter) Iterator(java.util.Iterator) MultiArgInstantiationPolicy(org.eclipse.persistence.internal.jaxb.MultiArgInstantiationPolicy) XMLJavaTypeConverter(org.eclipse.persistence.internal.jaxb.XMLJavaTypeConverter) AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) CoreDescriptor(org.eclipse.persistence.core.descriptors.CoreDescriptor) XMLContainerMapping(org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping) MimeTypePolicy(org.eclipse.persistence.oxm.mappings.MimeTypePolicy) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) ManyValue(org.eclipse.persistence.internal.jaxb.many.ManyValue) XmlWriteTransformer(org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlWriteTransformer) JAXBElement(jakarta.xml.bind.JAXBElement) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) QName(javax.xml.namespace.QName) 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) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) Collection(java.util.Collection) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Example 4 with Mapping

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

the class JAXBValueStore method unsetDeclaredProperty.

/**
 * For isMany=false properties set the value to null. For isMany=true set
 * the value to an empty container of the appropriate type.
 */
@Override
public void unsetDeclaredProperty(int propertyIndex) {
    SDOProperty declaredProperty = (SDOProperty) dataObject.getType().getDeclaredProperties().get(propertyIndex);
    Mapping mapping = this.getJAXBMappingForProperty(declaredProperty);
    if (declaredProperty.isMany()) {
        ContainerMapping containerMapping = (ContainerMapping) mapping;
        ContainerPolicy containerPolicy = containerMapping.getContainerPolicy();
        // OLD VALUE
        if (mapping.isAbstractCompositeCollectionMapping()) {
            XMLCompositeCollectionMapping compositeMapping = (XMLCompositeCollectionMapping) mapping;
            XMLInverseReferenceMapping inverseReferenceMapping = compositeMapping.getInverseReferenceMapping();
            if (inverseReferenceMapping != null && inverseReferenceMapping.getAttributeAccessor() != null) {
                Object oldContainer = mapping.getAttributeValueFromObject(entity);
                if (oldContainer != null) {
                    AbstractSession session = ((JAXBContext) jaxbHelperContext.getJAXBContext()).getXMLContext().getSession(entity);
                    Object iterator = containerPolicy.iteratorFor(oldContainer);
                    while (containerPolicy.hasNext(iterator)) {
                        Object oldValue = containerPolicy.next(iterator, session);
                        inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(oldValue, null);
                    }
                }
            }
        }
        // NEW VALUE
        Object container = containerPolicy.containerInstance();
        mapping.getAttributeAccessor().setAttributeValueInObject(entity, container);
    } else {
        // OLD VALUE
        Object oldValue = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
        if (mapping.isAbstractCompositeObjectMapping()) {
            XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
            final XMLInverseReferenceMapping inverseReferenceMapping = compositeMapping.getInverseReferenceMapping();
            if (inverseReferenceMapping != null && inverseReferenceMapping.getAttributeAccessor() != null) {
                if (oldValue != null) {
                    inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(oldValue, null);
                }
            }
        }
        // NEW VALUE
        mapping.getAttributeAccessor().setAttributeValueInObject(entity, null);
    }
}
Also used : CoreContainerPolicy(org.eclipse.persistence.internal.core.queries.CoreContainerPolicy) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) ContainerMapping(org.eclipse.persistence.mappings.ContainerMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) ContainerMapping(org.eclipse.persistence.mappings.ContainerMapping) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 5 with Mapping

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

the class JAXBValueStore method getDeclaredProperty.

/**
 * Get the value from the wrapped POJO, wrapping in DataObjects as
 * necessary.
 */
@Override
public Object getDeclaredProperty(int propertyIndex) {
    SDOProperty declaredProperty = (SDOProperty) dataObject.getType().getDeclaredProperties().get(propertyIndex);
    if (declaredProperty.getType().isChangeSummaryType()) {
        return dataObject.getChangeSummary();
    }
    Mapping mapping = this.getJAXBMappingForProperty(declaredProperty);
    Object value = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
    if (declaredProperty.isMany()) {
        JAXBListWrapper listWrapper = listWrappers.get(declaredProperty);
        if (null != listWrapper) {
            return listWrapper;
        }
        listWrapper = new JAXBListWrapper(this, declaredProperty);
        listWrappers.put(declaredProperty, listWrapper);
        return listWrapper;
    } else if (null == value || declaredProperty.getType().isDataType()) {
        return value;
    } else {
        if (declaredProperty.isContainment()) {
            return jaxbHelperContext.wrap(value, declaredProperty, dataObject);
        } else {
            return jaxbHelperContext.wrap(value);
        }
    }
}
Also used : XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) ContainerMapping(org.eclipse.persistence.mappings.ContainerMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOProperty(org.eclipse.persistence.sdo.SDOProperty)

Aggregations

Mapping (org.eclipse.persistence.internal.oxm.mappings.Mapping)28 DirectMapping (org.eclipse.persistence.internal.oxm.mappings.DirectMapping)18 CompositeObjectMapping (org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping)16 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)14 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)14 CompositeCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping)13 BinaryDataCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping)12 ChoiceCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping)12 CollectionReferenceMapping (org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping)12 DirectCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping)12 ObjectReferenceMapping (org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping)12 TransformationMapping (org.eclipse.persistence.internal.oxm.mappings.TransformationMapping)12 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)12 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)12 XMLInverseReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping)12 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)12 AnyCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping)11 BinaryDataMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping)11 ChoiceObjectMapping (org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping)11 Field (org.eclipse.persistence.internal.oxm.mappings.Field)11