Search in sources :

Example 1 with JAXBArrayAttributeAccessor

use of org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method generateCompositeCollectionMapping.

public CompositeCollectionMapping generateCompositeCollectionMapping(Property property, Descriptor descriptor, JavaClass javaClass, NamespaceInfo namespaceInfo, String referenceClassName) {
    boolean nestedArray = false;
    CompositeCollectionMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, Session, UnmarshalKeepAsElementPolicy, XMLUnmarshaller, XMLRecord> mapping = new XMLCompositeCollectionMapping();
    initializeXMLMapping((XMLMapping) mapping, property);
    initializeXMLContainerMapping(mapping, property.getType().isArray());
    JavaClass manyValueJavaClass = helper.getJavaClass(ManyValue.class);
    if (manyValueJavaClass.isAssignableFrom(javaClass)) {
        mapping.setReuseContainer(false);
    }
    // handle null policy set via xml metadata
    if (property.isSetNullPolicy()) {
        mapping.setNullPolicy(getNullPolicyFromProperty(property, getNamespaceResolverForDescriptor(namespaceInfo)));
    } else if (property.isNillable()) {
        mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
        mapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
    }
    if (property.isSetXmlElementWrapper()) {
        mapping.setWrapperNullPolicy(getWrapperNullPolicyFromProperty(property));
    }
    JavaClass collectionType = property.getType();
    if (collectionType.isArray()) {
        JAXBArrayAttributeAccessor accessor = new JAXBArrayAttributeAccessor(mapping.getAttributeAccessor(), mapping.getContainerPolicy(), helper.getClassLoader());
        JavaClass componentType = collectionType.getComponentType();
        if (componentType.isArray()) {
            Class<?> adaptedClass = classToGeneratedClasses.get(componentType.getName());
            referenceClassName = adaptedClass.getName();
            accessor.setAdaptedClassName(referenceClassName);
            JavaClass baseComponentType = getBaseComponentType(componentType);
            if (baseComponentType.isPrimitive()) {
                Class<Object> primitiveClass = XMLConversionManager.getDefaultManager().convertClassNameToClass(baseComponentType.getRawName());
                accessor.setComponentClass(primitiveClass);
            } else {
                accessor.setComponentClassName(baseComponentType.getQualifiedName());
            }
        } else {
            accessor.setComponentClassName(componentType.getQualifiedName());
        }
        mapping.setAttributeAccessor(accessor);
    } else if (helper.isMapType(property.getType())) {
        Class<?> generatedClass = generateMapEntryClassAndDescriptor(property, descriptor.getNonNullNamespaceResolver());
        referenceClassName = generatedClass.getName();
        String mapClassName = property.getType().getRawName();
        mapping.setAttributeAccessor(new MapValueAttributeAccessor(mapping.getAttributeAccessor(), mapping.getContainerPolicy(), generatedClass, mapClassName, helper.getClassLoader()));
    }
    // Nested array check (used in JSON marshalling)
    if (collectionType.getComponentType() == null) {
        if ((collectionType.isArray() || helper.isCollectionType(collectionType)) && (referenceClassName != null && referenceClassName.contains(AnnotationsProcessor.ARRAY_PACKAGE_NAME))) {
            nestedArray = true;
        }
    } else if ((collectionType.isArray() || helper.isCollectionType(collectionType)) && (collectionType.getComponentType().isArray() || helper.isCollectionType(collectionType.getComponentType()))) {
        nestedArray = true;
    }
    collectionType = containerClassImpl(collectionType);
    mapping.useCollectionClassName(collectionType.getRawName());
    // if the XPath is set (via xml-path) use it; otherwise figure it out
    Field xmlField = getXPathForField(property, namespaceInfo, false, false);
    if (helper.isMapType(property.getType())) {
        JavaClass mapValueClass = helper.getJavaClass(MapValue.class);
        if (mapValueClass.isAssignableFrom(javaClass)) {
            mapping.setXPath("entry");
        } else {
            mapping.setXPath(xmlField.getXPath() + "/entry");
        }
    } else {
        mapping.setXPath(xmlField.getXPath());
    }
    if (referenceClassName == null) {
        setTypedTextField((Field) mapping.getField());
    } else {
        mapping.setReferenceClassName(referenceClassName);
    }
    if (property.isTransientType()) {
        mapping.setReferenceClassName(Constants.UNKNOWN_OR_TRANSIENT_CLASS);
    }
    if (property.isRequired()) {
        ((Field) mapping.getField()).setRequired(true);
    }
    ((Field) mapping.getField()).setNestedArray(nestedArray);
    return mapping;
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) MapValueAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) 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) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) CoreConverter(org.eclipse.persistence.core.mappings.converters.CoreConverter) JAXBEnumTypeConverter(org.eclipse.persistence.jaxb.JAXBEnumTypeConverter) JAXBElementConverter(org.eclipse.persistence.internal.jaxb.JAXBElementConverter) XMLListConverter(org.eclipse.persistence.oxm.mappings.converters.XMLListConverter) XMLConverter(org.eclipse.persistence.oxm.mappings.converters.XMLConverter) Converter(org.eclipse.persistence.mappings.converters.Converter) DefaultElementConverter(org.eclipse.persistence.internal.jaxb.DefaultElementConverter) DomHandlerConverter(org.eclipse.persistence.internal.jaxb.DomHandlerConverter) JAXBElementRootConverter(org.eclipse.persistence.internal.jaxb.JAXBElementRootConverter) XMLJavaTypeConverter(org.eclipse.persistence.internal.jaxb.XMLJavaTypeConverter) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) UnmarshalKeepAsElementPolicy(org.eclipse.persistence.oxm.mappings.UnmarshalKeepAsElementPolicy) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) VirtualAttributeAccessor(org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor) CustomAccessorAttributeAccessor(org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor) JAXBSetMethodAttributeAccessor(org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) MapValueAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor) MethodAttributeAccessor(org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor) InstanceVariableAttributeAccessor(org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession) Session(org.eclipse.persistence.sessions.Session) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 2 with JAXBArrayAttributeAccessor

use of org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor 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 3 with JAXBArrayAttributeAccessor

use of org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method generateVariableXPathCollectionMapping.

private Mapping generateVariableXPathCollectionMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo, JavaClass actualType) {
    XMLVariableXPathCollectionMapping mapping = new XMLVariableXPathCollectionMapping();
    mapping.setAttributeName(property.getPropertyName());
    if (property.isMap()) {
        actualType = property.getValueType();
    }
    initializeXMLContainerMapping(mapping, property.getType().isArray());
    initializeXMLMapping(mapping, property);
    initializeVariableXPathMapping(mapping, property, actualType);
    if (property.getXmlPath() != null) {
        mapping.setField(new XMLField(property.getXmlPath()));
    } else {
        if (property.isSetXmlElementWrapper()) {
            mapping.setField((XMLField) getXPathForField(property, namespaceInfo, false, true));
        }
    }
    if (property.isSetXmlElementWrapper()) {
        mapping.setWrapperNullPolicy(getWrapperNullPolicyFromProperty(property));
    }
    JavaClass collectionType = property.getType();
    if (collectionType.isArray()) {
        JAXBArrayAttributeAccessor accessor = new JAXBArrayAttributeAccessor(mapping.getAttributeAccessor(), mapping.getContainerPolicy(), helper.getClassLoader());
        JavaClass componentType = collectionType.getComponentType();
        if (componentType.isArray()) {
            JavaClass baseComponentType = getBaseComponentType(componentType);
            if (baseComponentType.isPrimitive()) {
                Class<Object> primitiveClass = XMLConversionManager.getDefaultManager().convertClassNameToClass(baseComponentType.getRawName());
                accessor.setComponentClass(primitiveClass);
            } else {
                accessor.setComponentClassName(baseComponentType.getQualifiedName());
            }
        } else {
            accessor.setComponentClassName(componentType.getQualifiedName());
        }
        mapping.setAttributeAccessor(accessor);
    }
    if (property.isMap()) {
        JavaClass mapType = property.getType();
        if (mapType.isInterface()) {
            mapping.useMapClass("java.util.HashMap");
        } else {
            mapping.useMapClass(property.getType().getName());
        }
    } else {
        collectionType = containerClassImpl(collectionType);
        mapping.useCollectionClass(helper.getClassForJavaClass(collectionType));
    }
    return mapping;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) XMLVariableXPathCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathCollectionMapping)

Example 4 with JAXBArrayAttributeAccessor

use of org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor 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 5 with JAXBArrayAttributeAccessor

use of org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor 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

JAXBArrayAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor)9 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)8 XMLField (org.eclipse.persistence.oxm.XMLField)8 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)6 Field (org.eclipse.persistence.internal.oxm.mappings.Field)6 JAXBElementRootConverter (org.eclipse.persistence.internal.jaxb.JAXBElementRootConverter)5 AnyCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping)5 DirectCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping)5 CoreMapping (org.eclipse.persistence.core.mappings.CoreMapping)4 CoreConverter (org.eclipse.persistence.core.mappings.converters.CoreConverter)4 DomHandlerConverter (org.eclipse.persistence.internal.jaxb.DomHandlerConverter)4 JAXBElementConverter (org.eclipse.persistence.internal.jaxb.JAXBElementConverter)4 XMLJavaTypeConverter (org.eclipse.persistence.internal.jaxb.XMLJavaTypeConverter)4 AnyAttributeMapping (org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping)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