Search in sources :

Example 1 with XmlAccessorType

use of jakarta.xml.bind.annotation.XmlAccessorType in project eclipselink by eclipse-ee4j.

the class AnnotationsProcessor method preProcessXmlAccessorType.

/**
 * Process @XmlAccessorType annotation on a given JavaClass and update the
 * TypeInfo for pre-processing.
 */
private void preProcessXmlAccessorType(JavaClass javaClass, TypeInfo info, NamespaceInfo packageNamespace) {
    org.eclipse.persistence.jaxb.xmlmodel.XmlAccessType xmlAccessType;
    if (javaClass.getDeclaredAnnotation(helper.getJavaClass(XmlAccessorType.class)) != null) {
        XmlAccessorType accessorType = (XmlAccessorType) helper.getAnnotation(javaClass, XmlAccessorType.class);
        xmlAccessType = org.eclipse.persistence.jaxb.xmlmodel.XmlAccessType.fromValue(accessorType.value().name());
        info.setXmlAccessType(xmlAccessType);
    }
}
Also used : XmlAccessorType(jakarta.xml.bind.annotation.XmlAccessorType) XmlAccessType(org.eclipse.persistence.jaxb.xmlmodel.XmlAccessType)

Example 2 with XmlAccessorType

use of jakarta.xml.bind.annotation.XmlAccessorType 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

XmlAccessorType (jakarta.xml.bind.annotation.XmlAccessorType)2 XmlAccessorOrder (jakarta.xml.bind.annotation.XmlAccessorOrder)1 XmlSchema (jakarta.xml.bind.annotation.XmlSchema)1 Annotation (java.lang.annotation.Annotation)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ConversionException (org.eclipse.persistence.exceptions.ConversionException)1 JAXBException (org.eclipse.persistence.exceptions.JAXBException)1 AccessorFactoryWrapper (org.eclipse.persistence.internal.jaxb.AccessorFactoryWrapper)1 JavaAnnotation (org.eclipse.persistence.jaxb.javamodel.JavaAnnotation)1 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)1 XmlAccessType (org.eclipse.persistence.jaxb.xmlmodel.XmlAccessType)1