Search in sources :

Example 1 with AccessorFactoryWrapper

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

the class MappingsGenerator method generateMappings.

/**
 * Generate mappings for a given TypeInfo.
 */
public void generateMappings(TypeInfo info, Descriptor descriptor, JavaClass descriptorJavaClass, NamespaceInfo namespaceInfo) {
    if (info.isAnonymousComplexType()) {
        // may need to generate inherited mappings
        generateInheritedMappingsForAnonymousType(info, descriptor, descriptorJavaClass, namespaceInfo);
    }
    List<Property> propertiesInOrder = info.getNonTransientPropertiesInPropOrder();
    for (int i = 0; i < propertiesInOrder.size(); i++) {
        Property next = propertiesInOrder.get(i);
        if (next != null && (!next.isTransient() || (next.isTransient() && next.isXmlLocation()))) {
            Mapping mapping = generateMapping(next, descriptor, descriptorJavaClass, namespaceInfo);
            if (next.isVirtual()) {
                VirtualAttributeAccessor accessor = new VirtualAttributeAccessor();
                accessor.setAttributeName(mapping.getAttributeName());
                String getMethod = info.getXmlVirtualAccessMethods().getGetMethod();
                String setMethod = info.getXmlVirtualAccessMethods().getSetMethod();
                // Check to see if get/set were overridden in the mapping
                if (mapping.getAttributeAccessor().isMethodAttributeAccessor()) {
                    getMethod = ((MethodAttributeAccessor) mapping.getAttributeAccessor()).getGetMethodName();
                    setMethod = ((MethodAttributeAccessor) mapping.getAttributeAccessor()).getSetMethodName();
                    accessor.setValueType(mapping.getAttributeClassification());
                }
                accessor.setGetMethodName(getMethod);
                accessor.setSetMethodName(setMethod);
                if (mapping.getAttributeAccessor() instanceof JAXBArrayAttributeAccessor) {
                    JAXBArrayAttributeAccessor jaa = (JAXBArrayAttributeAccessor) mapping.getAttributeAccessor();
                    jaa.setNestedAccessor(accessor);
                } else {
                    mapping.setAttributeAccessor(accessor);
                }
            }
            if (mapping != null) {
                descriptor.addMapping((CoreMapping) mapping);
            }
            // set user-defined properties if necessary
            if (next.isSetUserProperties()) {
                mapping.setProperties(next.getUserProperties());
            }
            // get package info
            AccessorFactoryWrapper accessorFactory = info.getXmlAccessorFactory();
            if (accessorFactory == null) {
                accessorFactory = info.getPackageLevelXmlAccessorFactory();
            }
            if (accessorFactory != null) {
                try {
                    Object accessor = CompilerHelper.createAccessorFor(descriptorJavaClass, next, helper, accessorFactory);
                    if (accessor != null) {
                        CustomAccessorAttributeAccessor attributeAccessor = new CustomAccessorAttributeAccessor(accessor);
                        mapping.setAttributeAccessor(attributeAccessor);
                    }
                } catch (Exception ex) {
                }
            }
        }
        next.postInitialize();
    }
}
Also used : VirtualAttributeAccessor(org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor) CustomAccessorAttributeAccessor(org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) AccessorFactoryWrapper(org.eclipse.persistence.internal.jaxb.AccessorFactoryWrapper) XMLVariableXPathObjectMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathObjectMapping) AnyObjectMapping(org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) VariableXPathCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathCollectionMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping) XMLVariableXPathCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathCollectionMapping) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) XMLMapping(org.eclipse.persistence.oxm.mappings.XMLMapping) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) VariableXPathObjectMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathObjectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) CollectionReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) TransformationMapping(org.eclipse.persistence.internal.oxm.mappings.TransformationMapping) ObjectReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping) XMLAnyAttributeMapping(org.eclipse.persistence.oxm.mappings.XMLAnyAttributeMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) InverseReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) AnyCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) AnyAttributeMapping(org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) XMLContainerMapping(org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) JAXBException(org.eclipse.persistence.exceptions.JAXBException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException)

Example 2 with AccessorFactoryWrapper

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

the class AnnotationsProcessor method processAccessorFactory.

private void processAccessorFactory(JavaClass javaClass, TypeInfo info) {
    if (!xmlAccessorFactorySupport) {
        return;
    }
    Annotation xmlAccessorFactory = helper.getAnnotation(javaClass, CompilerHelper.ACCESSOR_FACTORY_ANNOTATION_CLASS);
    Method valueMethod = null;
    if (xmlAccessorFactory != null) {
        valueMethod = CompilerHelper.ACCESSOR_FACTORY_VALUE_METHOD;
    } else {
        // try for internal annotation
        xmlAccessorFactory = helper.getAnnotation(javaClass, CompilerHelper.INTERNAL_ACCESSOR_FACTORY_ANNOTATION_CLASS);
        if (xmlAccessorFactory != null) {
            valueMethod = CompilerHelper.INTERNAL_ACCESSOR_FACTORY_VALUE_METHOD;
        }
    }
    if (xmlAccessorFactory != null) {
        Class<?> xmlAccessorFactoryClass = null;
        try {
            xmlAccessorFactoryClass = PrivilegedAccessHelper.invokeMethod(valueMethod, xmlAccessorFactory, new Object[] {});
            info.setXmlAccessorFactory(new AccessorFactoryWrapper(PrivilegedAccessHelper.newInstanceFromClass(xmlAccessorFactoryClass)));
        } catch (Exception ex) {
            throw JAXBException.errorInstantiatingAccessorFactory(xmlAccessorFactoryClass, ex);
        }
    }
    PackageInfo pInfo = getPackageInfoForPackage(javaClass);
    if (pInfo != null) {
        info.setPackageLevelXmlAccessorFactory(pInfo.getAccessorFactory());
    }
}
Also used : AccessorFactoryWrapper(org.eclipse.persistence.internal.jaxb.AccessorFactoryWrapper) Method(java.lang.reflect.Method) JavaMethod(org.eclipse.persistence.jaxb.javamodel.JavaMethod) JavaAnnotation(org.eclipse.persistence.jaxb.javamodel.JavaAnnotation) Annotation(java.lang.annotation.Annotation) InvocationTargetException(java.lang.reflect.InvocationTargetException) JAXBException(org.eclipse.persistence.exceptions.JAXBException) ConversionException(org.eclipse.persistence.exceptions.ConversionException)

Example 3 with AccessorFactoryWrapper

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

the class AnnotationsProcessor method getPackageInfoForPackage.

public PackageInfo getPackageInfoForPackage(JavaPackage pack, String packageName) {
    PackageInfo packageInfo = packageToPackageInfoMappings.get(packageName);
    if (packageInfo == null) {
        XmlSchema xmlSchema = (XmlSchema) helper.getAnnotation(pack, XmlSchema.class);
        packageInfo = new PackageInfo();
        NamespaceInfo namespaceInfo = processNamespaceInformation(xmlSchema);
        packageInfo.setNamespaceInfo(namespaceInfo);
        // if it's still null, generate based on package name
        if (namespaceInfo.getNamespace() == null) {
            namespaceInfo.setNamespace(EMPTY_STRING);
        }
        if (helper.isAnnotationPresent(pack, XmlAccessorType.class)) {
            XmlAccessorType xmlAccessorType = (XmlAccessorType) helper.getAnnotation(pack, XmlAccessorType.class);
            packageInfo.setAccessType(XmlAccessType.fromValue(xmlAccessorType.value().name()));
        }
        if (helper.isAnnotationPresent(pack, XmlAccessorOrder.class)) {
            XmlAccessorOrder xmlAccessorOrder = (XmlAccessorOrder) helper.getAnnotation(pack, XmlAccessorOrder.class);
            packageInfo.setAccessOrder(XmlAccessOrder.fromValue(xmlAccessorOrder.value().name()));
        }
        if (CompilerHelper.ACCESSOR_FACTORY_ANNOTATION_CLASS != null && helper.isAnnotationPresent(pack, CompilerHelper.ACCESSOR_FACTORY_ANNOTATION_CLASS)) {
            Annotation xmlAccessorFactory = helper.getAnnotation(pack, CompilerHelper.ACCESSOR_FACTORY_ANNOTATION_CLASS);
            Class<?> xmlAccessorFactoryClass = null;
            try {
                xmlAccessorFactoryClass = PrivilegedAccessHelper.invokeMethod(CompilerHelper.ACCESSOR_FACTORY_VALUE_METHOD, xmlAccessorFactory, new Object[] {});
                packageInfo.setAccessorFactory(new AccessorFactoryWrapper(PrivilegedAccessHelper.newInstanceFromClass(xmlAccessorFactoryClass)));
            } catch (Exception ex) {
                throw JAXBException.errorInstantiatingAccessorFactory(xmlAccessorFactoryClass, ex);
            }
        } else if (CompilerHelper.OLD_ACCESSOR_FACTORY_ANNOTATION_CLASS != null && helper.isAnnotationPresent(pack, CompilerHelper.OLD_ACCESSOR_FACTORY_ANNOTATION_CLASS)) {
            Annotation xmlAccessorFactory = helper.getAnnotation(pack, CompilerHelper.OLD_ACCESSOR_FACTORY_ANNOTATION_CLASS);
            Class<?> xmlAccessorFactoryClass = null;
            try {
                xmlAccessorFactoryClass = PrivilegedAccessHelper.invokeMethod(CompilerHelper.OLD_ACCESSOR_FACTORY_VALUE_METHOD, xmlAccessorFactory, new Object[] {});
                packageInfo.setAccessorFactory(new AccessorFactoryWrapper(PrivilegedAccessHelper.newInstanceFromClass(xmlAccessorFactoryClass)));
            } catch (Exception ex) {
                throw JAXBException.errorInstantiatingAccessorFactory(xmlAccessorFactoryClass, ex);
            }
        } else if (CompilerHelper.INTERNAL_ACCESSOR_FACTORY_ANNOTATION_CLASS != null && helper.isAnnotationPresent(pack, CompilerHelper.INTERNAL_ACCESSOR_FACTORY_ANNOTATION_CLASS)) {
            Annotation xmlAccessorFactory = helper.getAnnotation(pack, CompilerHelper.INTERNAL_ACCESSOR_FACTORY_ANNOTATION_CLASS);
            Class<?> xmlAccessorFactoryClass = null;
            try {
                xmlAccessorFactoryClass = PrivilegedAccessHelper.invokeMethod(CompilerHelper.INTERNAL_ACCESSOR_FACTORY_VALUE_METHOD, xmlAccessorFactory, new Object[] {});
                packageInfo.setAccessorFactory(new AccessorFactoryWrapper(PrivilegedAccessHelper.newInstanceFromClass(xmlAccessorFactoryClass)));
            } catch (Exception ex) {
                throw JAXBException.errorInstantiatingAccessorFactory(xmlAccessorFactoryClass, ex);
            }
        }
        packageToPackageInfoMappings.put(packageName, packageInfo);
    }
    return packageInfo;
}
Also used : XmlAccessorOrder(jakarta.xml.bind.annotation.XmlAccessorOrder) XmlSchema(jakarta.xml.bind.annotation.XmlSchema) AccessorFactoryWrapper(org.eclipse.persistence.internal.jaxb.AccessorFactoryWrapper) XmlAccessorType(jakarta.xml.bind.annotation.XmlAccessorType) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) JavaAnnotation(org.eclipse.persistence.jaxb.javamodel.JavaAnnotation) Annotation(java.lang.annotation.Annotation) InvocationTargetException(java.lang.reflect.InvocationTargetException) JAXBException(org.eclipse.persistence.exceptions.JAXBException) ConversionException(org.eclipse.persistence.exceptions.ConversionException)

Aggregations

JAXBException (org.eclipse.persistence.exceptions.JAXBException)3 AccessorFactoryWrapper (org.eclipse.persistence.internal.jaxb.AccessorFactoryWrapper)3 Annotation (java.lang.annotation.Annotation)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ConversionException (org.eclipse.persistence.exceptions.ConversionException)2 JavaAnnotation (org.eclipse.persistence.jaxb.javamodel.JavaAnnotation)2 XmlAccessorOrder (jakarta.xml.bind.annotation.XmlAccessorOrder)1 XmlAccessorType (jakarta.xml.bind.annotation.XmlAccessorType)1 XmlSchema (jakarta.xml.bind.annotation.XmlSchema)1 Method (java.lang.reflect.Method)1 CoreMapping (org.eclipse.persistence.core.mappings.CoreMapping)1 DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)1 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)1 CustomAccessorAttributeAccessor (org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor)1 JAXBArrayAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor)1 AnyAttributeMapping (org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping)1 AnyCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping)1 AnyObjectMapping (org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping)1 BinaryDataCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping)1 BinaryDataMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping)1