Search in sources :

Example 1 with BinaryDataMapping

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

the class JsonSchemaGenerator method generateProperty.

private Property generateProperty(Mapping next, XMLDescriptor descriptor, Map<String, Property> properties) {
    Property prop = null;
    if (next.isCollectionMapping()) {
        if (next instanceof CollectionReferenceMapping) {
            CollectionReferenceMapping mapping = (CollectionReferenceMapping) next;
            Set<XMLField> sourceFields = mapping.getSourceToTargetKeyFieldAssociations().keySet();
            XMLDescriptor reference = (XMLDescriptor) mapping.getReferenceDescriptor();
            for (XMLField nextField : sourceFields) {
                XPathFragment frag = nextField.getXPathFragment();
                String propertyName = getNameForFragment(frag);
                XMLField targetField = (XMLField) mapping.getSourceToTargetKeyFieldAssociations().get(nextField);
                Class<?> type = CoreClassConstants.STRING;
                if (reference != null) {
                    type = getTypeForTargetField(targetField, reference);
                }
                prop = properties.get(propertyName);
                if (prop == null) {
                    prop = new Property();
                    prop.setName(propertyName);
                }
                Property nestedProperty = getNestedPropertyForFragment(frag, prop);
                nestedProperty.setType(JsonType.ARRAY);
                nestedProperty.setItem(new Property());
                nestedProperty.getItem().setType(getJsonTypeForJavaType(type));
                if (!properties.containsKey(prop.getName())) {
                    properties.put(prop.getName(), prop);
                }
            }
            return prop;
        } else if (next.isAbstractCompositeCollectionMapping()) {
            CompositeCollectionMapping mapping = (CompositeCollectionMapping) next;
            XMLField field = (XMLField) mapping.getField();
            XPathFragment frag = field.getXPathFragment();
            String propName = getNameForFragment(frag);
            // for paths, there may already be an existing property
            prop = properties.get(propName);
            if (prop == null) {
                prop = new Property();
                prop.setName(propName);
            }
            Property nestedProperty = getNestedPropertyForFragment(frag, prop);
            nestedProperty.setType(JsonType.ARRAY);
            nestedProperty.setItem(new Property());
            XMLDescriptor referenceDescriptor = (XMLDescriptor) mapping.getReferenceDescriptor();
            if (referenceDescriptor != null && referenceDescriptor.hasInheritance()) {
                // handle inheritence
                // schema.setAnyOf(new Property[descriptor.getInheritancePolicy().getAllChildDescriptors().size()]);
                List<ClassDescriptor> descriptors = getAllDescriptorsForInheritance(referenceDescriptor);
                Property[] props = new Property[descriptors.size()];
                for (int i = 0; i < props.length; i++) {
                    XMLDescriptor nextDescriptor = null;
                    nextDescriptor = (XMLDescriptor) descriptors.get(i);
                    Property ref = new Property();
                    ref.setRef(getReferenceForDescriptor(nextDescriptor, true));
                    props[i] = ref;
                }
                nestedProperty.getItem().setAnyOf(props);
            } else {
                nestedProperty.getItem().setRef(getReferenceForDescriptor(referenceDescriptor, false));
            // populateProperties(nestedProperty.getItem().getProperties(), (XMLDescriptor)mapping.getReferenceDescriptor());
            }
        } else if (next.isAbstractCompositeDirectCollectionMapping()) {
            DirectCollectionMapping mapping = (DirectCollectionMapping) next;
            XMLField field = (XMLField) mapping.getField();
            XPathFragment frag = field.getXPathFragment();
            List<String> enumeration = null;
            if (mapping.getValueConverter() instanceof JAXBEnumTypeConverter) {
                enumeration = getEnumeration((DatabaseMapping) next);
            }
            String propertyName = getNameForFragment(frag);
            if (frag.nameIsText()) {
                propertyName = (String) this.contextProperties.get(MarshallerProperties.JSON_VALUE_WRAPPER);
            }
            if (frag.isAttribute() && this.attributePrefix != null) {
                propertyName = attributePrefix + propertyName;
            }
            prop = properties.get(propertyName);
            if (prop == null) {
                prop = new Property();
                prop.setName(propertyName);
            }
            Property nestedProperty = getNestedPropertyForFragment(frag, prop);
            nestedProperty.setType(JsonType.ARRAY);
            nestedProperty.setItem(new Property());
            if (enumeration != null) {
                nestedProperty.getItem().setEnumeration(enumeration);
            }
            Class<?> type = mapping.getAttributeElementClass();
            if (type == null) {
                type = CoreClassConstants.STRING;
            }
            nestedProperty.getItem().setType(getJsonTypeForJavaType(type));
            return prop;
        } else if (next instanceof BinaryDataCollectionMapping) {
            BinaryDataCollectionMapping mapping = (BinaryDataCollectionMapping) next;
            XMLField field = (XMLField) mapping.getField();
            XPathFragment frag = field.getXPathFragment();
            String propertyName = getNameForFragment(frag);
            if (frag.isSelfFragment()) {
                propertyName = Constants.VALUE_WRAPPER;
                if (this.contextProperties != null) {
                    String valueWrapper = (String) this.contextProperties.get(JAXBContextProperties.JSON_VALUE_WRAPPER);
                    if (valueWrapper != null) {
                        propertyName = valueWrapper;
                    }
                }
            }
            if (frag.isAttribute() && this.attributePrefix != null) {
                propertyName = attributePrefix + propertyName;
            }
            prop = properties.get(propertyName);
            if (prop == null) {
                prop = new Property();
                prop.setName(propertyName);
            }
            Property nestedProperty = getNestedPropertyForFragment(frag, prop);
            nestedProperty.setType(JsonType.ARRAY);
            nestedProperty.setItem(new Property());
            if (mapping.shouldInlineBinaryData()) {
                nestedProperty.getItem().setType(JsonType.STRING);
            } else {
                nestedProperty.getItem().setAnyOf(getXopIncludeProperties());
            }
            return prop;
        }
    } else {
        if (next.isAbstractDirectMapping()) {
            // handle direct mapping
            DirectMapping directMapping = (DirectMapping) next;
            XMLField field = (XMLField) directMapping.getField();
            XPathFragment frag = field.getXPathFragment();
            List<String> enumeration = null;
            if (directMapping.getConverter() instanceof JAXBEnumTypeConverter) {
                enumeration = getEnumeration((DatabaseMapping) directMapping);
            }
            String propertyName = getNameForFragment(frag);
            if (frag.nameIsText()) {
                propertyName = Constants.VALUE_WRAPPER;
                if (this.contextProperties != null) {
                    String valueWrapper = (String) this.contextProperties.get(JAXBContextProperties.JSON_VALUE_WRAPPER);
                    if (valueWrapper != null) {
                        propertyName = valueWrapper;
                    }
                }
            }
            if (frag.isAttribute() && this.attributePrefix != null) {
                propertyName = attributePrefix + propertyName;
            }
            prop = properties.get(propertyName);
            if (prop == null) {
                prop = new Property();
                prop.setName(propertyName);
            }
            Property nestedProperty = getNestedPropertyForFragment(frag, prop);
            if (enumeration != null) {
                nestedProperty.setEnumeration(enumeration);
            }
            if (directMapping instanceof BinaryDataMapping) {
                BinaryDataMapping binaryMapping = (BinaryDataMapping) directMapping;
                if (binaryMapping.shouldInlineBinaryData() || binaryMapping.isSwaRef()) {
                    nestedProperty.setType(JsonType.STRING);
                } else {
                    if (this.xopIncludeProp == null) {
                        initXopIncludeProp();
                    }
                    nestedProperty.setAnyOf(this.xopIncludeProp);
                }
            } else {
                nestedProperty.setType(getJsonTypeForJavaType(directMapping.getAttributeClassification()));
            }
            return prop;
        } else if (next instanceof ObjectReferenceMapping) {
            ObjectReferenceMapping mapping = (ObjectReferenceMapping) next;
            Set<XMLField> sourceFields = mapping.getSourceToTargetKeyFieldAssociations().keySet();
            XMLDescriptor reference = (XMLDescriptor) mapping.getReferenceDescriptor();
            for (XMLField nextField : sourceFields) {
                XPathFragment frag = nextField.getXPathFragment();
                String propName = getNameForFragment(frag);
                XMLField targetField = (XMLField) mapping.getSourceToTargetKeyFieldAssociations().get(nextField);
                Class<?> type = CoreClassConstants.STRING;
                if (reference != null) {
                    type = getTypeForTargetField(targetField, reference);
                }
                prop = properties.get(propName);
                if (prop == null) {
                    prop = new Property();
                    prop.setName(propName);
                }
                Property nestedProperty = getNestedPropertyForFragment(frag, prop);
                // nestedProperty.setType(JsonType.ARRAY);
                // nestedProperty.setItem(new Property());
                nestedProperty.setType(getJsonTypeForJavaType(type));
                if (!properties.containsKey(prop.getName())) {
                    properties.put(prop.getName(), prop);
                }
            }
            return prop;
        } else if (next.isAbstractCompositeObjectMapping()) {
            CompositeObjectMapping mapping = (CompositeObjectMapping) next;
            XMLDescriptor nextDescriptor = (XMLDescriptor) mapping.getReferenceDescriptor();
            XMLField field = (XMLField) mapping.getField();
            XPathFragment firstFragment = field.getXPathFragment();
            if (firstFragment.isSelfFragment() || firstFragment.nameIsText()) {
                if (nextDescriptor != null) {
                    populateProperties(properties, nextDescriptor);
                }
            } else {
                String propName = getNameForFragment(firstFragment);
                prop = properties.get(propName);
                if (prop == null) {
                    prop = new Property();
                    prop.setName(propName);
                }
                // prop.setType(JsonType.OBJECT);
                prop.setName(propName);
                Property nestedProperty = getNestedPropertyForFragment(firstFragment, prop);
                XMLDescriptor referenceDescriptor = (XMLDescriptor) mapping.getReferenceDescriptor();
                if (referenceDescriptor != null && referenceDescriptor.hasInheritance()) {
                    // handle inheritence
                    // schema.setAnyOf(new Property[descriptor.getInheritancePolicy().getAllChildDescriptors().size()]);
                    List<ClassDescriptor> descriptors = getAllDescriptorsForInheritance(referenceDescriptor);
                    Property[] props = new Property[descriptors.size()];
                    for (int i = 0; i < props.length; i++) {
                        XMLDescriptor nextDesc = (XMLDescriptor) descriptors.get(i);
                        Property ref = new Property();
                        ref.setRef(getReferenceForDescriptor(nextDesc, true));
                        props[i] = ref;
                    }
                    nestedProperty.setAnyOf(props);
                } else {
                    nestedProperty.setRef(getReferenceForDescriptor(referenceDescriptor, false));
                // populateProperties(nestedProperty.getItem().getProperties(), (XMLDescriptor)mapping.getReferenceDescriptor());
                }
            // populateProperties(nestedProperty.getProperties(), nextDescriptor);
            }
        } else if (next instanceof BinaryDataMapping) {
            BinaryDataMapping binaryMapping = (BinaryDataMapping) next;
            XMLField field = (XMLField) binaryMapping.getField();
            XPathFragment frag = field.getXPathFragment();
            String propertyName = getNameForFragment(frag);
            if (frag.isSelfFragment()) {
                propertyName = Constants.VALUE_WRAPPER;
                if (this.contextProperties != null) {
                    String valueWrapper = (String) this.contextProperties.get(MarshallerProperties.JSON_VALUE_WRAPPER);
                    if (valueWrapper != null) {
                        propertyName = valueWrapper;
                    }
                }
            }
            if (frag.isAttribute() && this.attributePrefix != null) {
                propertyName = attributePrefix + propertyName;
            }
            prop = properties.get(propertyName);
            if (prop == null) {
                prop = new Property();
                prop.setName(propertyName);
            }
            Property nestedProperty = getNestedPropertyForFragment(frag, prop);
            if (binaryMapping.shouldInlineBinaryData() || binaryMapping.isSwaRef()) {
                nestedProperty.setType(JsonType.STRING);
            } else {
                if (this.xopIncludeProp == null) {
                    initXopIncludeProp();
                }
                nestedProperty.setAnyOf(this.xopIncludeProp);
            }
            return prop;
        }
    }
    return prop;
}
Also used : Set(java.util.Set) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) CollectionReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping) ArrayList(java.util.ArrayList) List(java.util.List) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) JAXBEnumTypeConverter(org.eclipse.persistence.jaxb.JAXBEnumTypeConverter) Property(org.eclipse.persistence.internal.jaxb.json.schema.model.Property) XMLField(org.eclipse.persistence.oxm.XMLField) ObjectReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping)

Example 2 with BinaryDataMapping

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

the class MappingsGenerator method generateWrapperClassAndDescriptor.

private Class<?> generateWrapperClassAndDescriptor(TypeInfo type, QName next, ElementDeclaration nextElement, String nextClassName, String attributeTypeName) {
    String namespaceUri = null;
    if (next != null) {
        // generate a class/descriptor for this element
        namespaceUri = next.getNamespaceURI();
        if (namespaceUri == null || namespaceUri.equals(XMLProcessor.DEFAULT)) {
            namespaceUri = "";
        }
    }
    TypeMappingInfo tmi = nextElement.getTypeMappingInfo();
    Class<?> generatedClass = null;
    JaxbClassLoader loader = getJaxbClassLoader();
    if (tmi != null) {
        generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfoToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
        if (generatedClass == null) {
            generatedClass = this.generateWrapperClass(loader.nextAvailableGeneratedClassName(), attributeTypeName, nextElement.isList(), next);
        }
        typeMappingInfoToGeneratedClasses.put(tmi, generatedClass);
    } else {
        generatedClass = this.generateWrapperClass(loader.nextAvailableGeneratedClassName(), attributeTypeName, nextElement.isList(), next);
    }
    this.qNamesToGeneratedClasses.put(next, generatedClass);
    try {
        Class<Object> declaredClass = PrivilegedAccessHelper.getClassForName(nextClassName, false, helper.getClassLoader());
        this.qNamesToDeclaredClasses.put(next, declaredClass);
    } catch (Exception e) {
    }
    Descriptor desc = (Descriptor) project.getDescriptor(generatedClass);
    if (desc == null) {
        desc = new XMLDescriptor();
        desc.setJavaClass(generatedClass);
        if (nextElement.isList()) {
            DirectCollectionMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, Session, XMLUnmarshaller, XMLRecord> mapping = new XMLCompositeDirectCollectionMapping();
            mapping.setAttributeName("value");
            mapping.setXPath("text()");
            mapping.setUsesSingleNode(true);
            mapping.setReuseContainer(true);
            if (type != null && type.isEnumerationType()) {
                mapping.setValueConverter(buildJAXBEnumTypeConverter(mapping, (EnumTypeInfo) type));
            } else {
                try {
                    Class<Object> fieldElementClass = PrivilegedAccessHelper.getClassForName(nextClassName, false, helper.getClassLoader());
                    mapping.setFieldElementClass(fieldElementClass);
                } catch (ClassNotFoundException e) {
                }
            }
            if (nextClassName.equals("[B") || nextClassName.equals("[Ljava.lang.Byte;")) {
                ((Field) mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
            } else if (nextClassName.equals("javax.xml.namespace.QName")) {
                ((Field) mapping.getField()).setSchemaType(Constants.QNAME_QNAME);
            }
            desc.addMapping((CoreMapping) mapping);
        } else {
            if (nextElement.getJavaTypeName().equals(OBJECT_CLASS_NAME)) {
                CompositeObjectMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, Session, UnmarshalKeepAsElementPolicy, XMLUnmarshaller, XMLRecord> mapping = new XMLCompositeObjectMapping();
                mapping.setAttributeName("value");
                mapping.setSetMethodName("setValue");
                mapping.setGetMethodName("getValue");
                mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
                mapping.setXPath(".");
                setTypedTextField((Field) mapping.getField());
                desc.addMapping((CoreMapping) mapping);
            } else if (isBinaryData(nextElement.getJavaType())) {
                BinaryDataMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, MimeTypePolicy, Session, XMLUnmarshaller, XMLRecord> mapping = new XMLBinaryDataMapping();
                mapping.setAttributeName("value");
                mapping.setXPath(".");
                ((Field) mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
                mapping.setSetMethodName("setValue");
                mapping.setGetMethodName("getValue");
                mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
                mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
                Class<?> attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(attributeTypeName, helper.getClassLoader());
                mapping.setAttributeClassification(attributeClassification);
                mapping.setShouldInlineBinaryData(false);
                // if(nextElement.getTypeMappingInfo() != null) {
                mapping.setSwaRef(nextElement.isXmlAttachmentRef());
                mapping.setMimeType(nextElement.getXmlMimeType());
                // }
                desc.addMapping((CoreMapping) mapping);
            } else {
                DirectMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, Session, XMLUnmarshaller, XMLRecord> mapping = new XMLDirectMapping();
                mapping.setNullValueMarshalled(true);
                mapping.setAttributeName("value");
                mapping.setXPath("text()");
                mapping.setSetMethodName("setValue");
                mapping.setGetMethodName("getValue");
                if (nextElement.getDefaultValue() != null) {
                    mapping.setNullValue(nextElement.getDefaultValue());
                    mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
                }
                if (helper.isBuiltInJavaType(nextElement.getJavaType())) {
                    Class<?> attributeClassification = null;
                    if (nextElement.getJavaType().isPrimitive()) {
                        attributeClassification = XMLConversionManager.getDefaultManager().convertClassNameToClass(attributeTypeName);
                    } else {
                        attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(attributeTypeName, helper.getClassLoader());
                    }
                    mapping.setAttributeClassification(attributeClassification);
                }
                IsSetNullPolicy nullPolicy = new IsSetNullPolicy("isSetValue", false, true, XMLNullRepresentationType.ABSENT_NODE);
                // nullPolicy.setNullRepresentedByEmptyNode(true);
                mapping.setNullPolicy(nullPolicy);
                if (type != null && type.isEnumerationType()) {
                    mapping.setConverter(buildJAXBEnumTypeConverter(mapping, (EnumTypeInfo) type));
                }
                if (nextClassName.equals("[B") || nextClassName.equals("[Ljava.lang.Byte;")) {
                    ((Field) mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
                } else if (nextClassName.equals("javax.xml.namespace.QName")) {
                    ((Field) mapping.getField()).setSchemaType(Constants.QNAME_QNAME);
                }
                if (nextElement.getJavaTypeAdapterClass() != null) {
                    mapping.setConverter(new XMLJavaTypeConverter(nextElement.getJavaTypeAdapterClass()));
                }
                desc.addMapping((CoreMapping) mapping);
            }
        }
        if (next != null) {
            NamespaceInfo info = getNamespaceInfoForURI(namespaceUri);
            if (info != null) {
                NamespaceResolver resolver = getNamespaceResolverForDescriptor(info);
                String prefix = null;
                if (namespaceUri != Constants.EMPTY_STRING) {
                    prefix = resolver.resolveNamespaceURI(namespaceUri);
                    if (prefix == null) {
                        prefix = getPrefixForNamespace(namespaceUri, resolver);
                    }
                }
                desc.setNamespaceResolver(resolver);
                if (nextElement.isXmlRootElement()) {
                    desc.setDefaultRootElement(getQualifiedString(prefix, next.getLocalPart()));
                } else {
                    desc.setDefaultRootElement("");
                    desc.addRootElement(getQualifiedString(prefix, next.getLocalPart()));
                    desc.setResultAlwaysXMLRoot(true);
                }
            } else {
                if (namespaceUri.equals("")) {
                    desc.setDefaultRootElement(next.getLocalPart());
                } else {
                    NamespaceResolver resolver = new org.eclipse.persistence.oxm.NamespaceResolver();
                    String prefix = getPrefixForNamespace(namespaceUri, resolver);
                    desc.setNamespaceResolver(resolver);
                    if (nextElement.isXmlRootElement()) {
                        desc.setDefaultRootElement(getQualifiedString(prefix, next.getLocalPart()));
                    } else {
                        desc.setDefaultRootElement("");
                        desc.addRootElement(getQualifiedString(prefix, next.getLocalPart()));
                        desc.setResultAlwaysXMLRoot(true);
                    }
                }
            }
        }
        project.addDescriptor((CoreDescriptor) desc);
    }
    return generatedClass;
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) IsSetNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy) XmlIsSetNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy) 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) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) 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) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) UnmarshalKeepAsElementPolicy(org.eclipse.persistence.oxm.mappings.UnmarshalKeepAsElementPolicy) TypeMappingInfo(org.eclipse.persistence.jaxb.TypeMappingInfo) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession) XMLJavaTypeConverter(org.eclipse.persistence.internal.jaxb.XMLJavaTypeConverter) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) JAXBException(org.eclipse.persistence.exceptions.JAXBException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) CoreDescriptor(org.eclipse.persistence.core.descriptors.CoreDescriptor) NamespaceResolver(org.eclipse.persistence.internal.oxm.NamespaceResolver) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) 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) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) Session(org.eclipse.persistence.sessions.Session) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 3 with BinaryDataMapping

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

the class MappingsGenerator method generateDescriptorForJAXBElementSubclass.

public void generateDescriptorForJAXBElementSubclass(JavaClass javaClass, CoreProject project, NamespaceResolver nsr) {
    String jClassName = javaClass.getQualifiedName();
    TypeInfo info = typeInfo.get(jClassName);
    Descriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClassName(jClassName);
    String[] factoryMethodParamTypes = info.getFactoryMethodParamTypes();
    MultiArgInstantiationPolicy policy = new MultiArgInstantiationPolicy();
    policy.useFactoryInstantiationPolicy(info.getObjectFactoryClassName(), info.getFactoryMethodName());
    policy.setParameterTypeNames(factoryMethodParamTypes);
    policy.setDefaultValues(new String[] { null });
    xmlDescriptor.setInstantiationPolicy(policy);
    JavaClass paramClass = helper.getJavaClass(factoryMethodParamTypes[0]);
    boolean isObject = paramClass.getName().equals("java.lang.Object");
    if (helper.isBuiltInJavaType(paramClass) && !isObject) {
        if (isBinaryData(paramClass)) {
            BinaryDataMapping mapping = new XMLBinaryDataMapping();
            mapping.setAttributeName("value");
            mapping.setXPath(".");
            ((Field) mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
            mapping.setSetMethodName("setValue");
            mapping.setGetMethodName("getValue");
            Class<?> attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(factoryMethodParamTypes[0], helper.getClassLoader());
            mapping.setAttributeClassification(attributeClassification);
            mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
            mapping.setShouldInlineBinaryData(false);
            if (mapping.getMimeType() == null) {
                if (areEquals(paramClass, javax.xml.transform.Source.class)) {
                    mapping.setMimeTypePolicy(new FixedMimeTypePolicy("application/xml"));
                } else {
                    mapping.setMimeTypePolicy(new FixedMimeTypePolicy("application/octet-stream"));
                }
            }
            xmlDescriptor.addMapping((CoreMapping) mapping);
        } else {
            DirectMapping mapping = new XMLDirectMapping();
            mapping.setNullValueMarshalled(true);
            mapping.setAttributeName("value");
            mapping.setGetMethodName("getValue");
            mapping.setSetMethodName("setValue");
            mapping.setXPath("text()");
            Class<?> attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(factoryMethodParamTypes[0], helper.getClassLoader());
            mapping.setAttributeClassification(attributeClassification);
            xmlDescriptor.addMapping((CoreMapping) mapping);
        }
    } else if (paramClass.isEnum()) {
        EnumTypeInfo enumInfo = (EnumTypeInfo) typeInfo.get(paramClass.getQualifiedName());
        DirectMapping mapping = new XMLDirectMapping();
        mapping.setConverter(buildJAXBEnumTypeConverter(mapping, enumInfo));
        mapping.setNullValueMarshalled(true);
        mapping.setAttributeName("value");
        mapping.setGetMethodName("getValue");
        mapping.setSetMethodName("setValue");
        mapping.setXPath("text()");
        Class<?> attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(factoryMethodParamTypes[0], helper.getClassLoader());
        mapping.setAttributeClassification(attributeClassification);
        xmlDescriptor.addMapping((CoreMapping) mapping);
    } else {
        CompositeObjectMapping mapping = new XMLCompositeObjectMapping();
        mapping.setAttributeName("value");
        mapping.setGetMethodName("getValue");
        mapping.setSetMethodName("setValue");
        mapping.setXPath(".");
        if (isObject) {
            mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
        } else {
            mapping.setReferenceClassName(factoryMethodParamTypes[0]);
        }
        xmlDescriptor.addMapping((CoreMapping) mapping);
    }
    xmlDescriptor.setNamespaceResolver(nsr);
    setSchemaContext(xmlDescriptor, info);
    project.addDescriptor((CoreDescriptor) xmlDescriptor);
    info.setDescriptor(xmlDescriptor);
}
Also used : FixedMimeTypePolicy(org.eclipse.persistence.oxm.mappings.FixedMimeTypePolicy) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) MultiArgInstantiationPolicy(org.eclipse.persistence.internal.jaxb.MultiArgInstantiationPolicy) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) 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) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) CoreDescriptor(org.eclipse.persistence.core.descriptors.CoreDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) 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 BinaryDataMapping

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

the class MappingsGenerator method generateBinaryMapping.

public BinaryDataMapping generateBinaryMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo) {
    BinaryDataMapping mapping = new XMLBinaryDataMapping();
    initializeXMLMapping((XMLMapping) mapping, property);
    // if the XPath is set (via xml-path) use it
    mapping.setField(getXPathForField(property, namespaceInfo, false, false));
    if (property.isSwaAttachmentRef()) {
        ((Field) mapping.getField()).setSchemaType(Constants.SWA_REF_QNAME);
        mapping.setSwaRef(true);
    } else if (property.isMtomAttachment()) {
        Field f = ((Field) mapping.getField());
        if (!f.getSchemaType().equals(Constants.HEX_BINARY_QNAME)) {
            f.setSchemaType(Constants.BASE_64_BINARY_QNAME);
        }
    }
    if (property.isInlineBinaryData()) {
        mapping.setShouldInlineBinaryData(true);
    }
    // use a non-dynamic implementation of MimeTypePolicy to wrap the MIME string
    if (property.getMimeType() != null) {
        mapping.setMimeTypePolicy(new FixedMimeTypePolicy(property.getMimeType(), (DatabaseMapping) mapping));
    } else {
        if (areEquals(property.getType(), javax.xml.transform.Source.class)) {
            mapping.setMimeTypePolicy(new FixedMimeTypePolicy("application/xml", (DatabaseMapping) mapping));
        } else if (areEquals(property.getType(), java.awt.Image.class)) {
            mapping.setMimeTypePolicy(new FixedMimeTypePolicy("image/png", (DatabaseMapping) mapping));
        } else {
            mapping.setMimeTypePolicy(new FixedMimeTypePolicy("application/octet-stream", (DatabaseMapping) mapping));
        }
    }
    if (property.isSetNullPolicy()) {
        mapping.setNullPolicy(getNullPolicyFromProperty(property, getNamespaceResolverForDescriptor(namespaceInfo)));
    } else {
        if (property.isNillable()) {
            mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
            mapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
        }
        mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
        if (!mapping.getXPath().equals("text()")) {
            ((NullPolicy) mapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
        }
    }
    mapping.setAttributeClassificationName(property.getActualType().getQualifiedName());
    return mapping;
}
Also used : XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) IsSetNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy) XmlIsSetNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy) NullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy) XmlNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy) XmlAbstractNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy) AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy) 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) FixedMimeTypePolicy(org.eclipse.persistence.oxm.mappings.FixedMimeTypePolicy) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) Image(java.awt.Image) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping)

Example 5 with BinaryDataMapping

use of org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping 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)

Aggregations

BinaryDataMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping)9 DirectMapping (org.eclipse.persistence.internal.oxm.mappings.DirectMapping)7 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)6 CompositeObjectMapping (org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping)6 Field (org.eclipse.persistence.internal.oxm.mappings.Field)6 CoreMapping (org.eclipse.persistence.core.mappings.CoreMapping)5 BinaryDataCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping)5 CollectionReferenceMapping (org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping)5 CompositeCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping)5 DirectCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping)5 ObjectReferenceMapping (org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping)5 XMLField (org.eclipse.persistence.oxm.XMLField)5 XMLBinaryDataMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping)5 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)5 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)4 XMLJavaTypeConverter (org.eclipse.persistence.internal.jaxb.XMLJavaTypeConverter)4 AnyAttributeMapping (org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping)4 AnyCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping)4 AnyObjectMapping (org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping)4 ChoiceCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping)4