Search in sources :

Example 1 with JavaAnnotation

use of org.eclipse.persistence.jaxb.javamodel.JavaAnnotation in project eclipselink by eclipse-ee4j.

the class AnnotationsProcessor method processAdditionalClasses.

private void processAdditionalClasses(JavaClass cls, TypeMappingInfo tmi, ArrayList<JavaClass> extraClasses, ArrayList<JavaClass> classesToProcess) {
    Class<?> xmlElementType = null;
    JavaClass javaClass = cls;
    if (tmi != null) {
        Class<?> adapterClass = this.typeMappingInfoToAdapterClasses.get(tmi);
        if (adapterClass != null) {
            JavaClass adapterJavaClass = helper.getJavaClass(adapterClass);
            JavaClass newType = helper.getJavaClass(Object.class);
            // look for marshal method
            for (Object nextMethod : adapterJavaClass.getDeclaredMethods()) {
                JavaMethod method = (JavaMethod) nextMethod;
                if (method.getName().equals("marshal")) {
                    JavaClass returnType = method.getReturnType();
                    if (!returnType.getQualifiedName().equals(newType.getQualifiedName())) {
                        newType = returnType;
                        break;
                    }
                }
            }
            if (!helper.isBuiltInJavaType(javaClass)) {
                extraClasses.add(javaClass);
            }
            javaClass = newType;
        }
        java.lang.annotation.Annotation[] annotations = getAnnotations(tmi);
        if (annotations != null) {
            for (Annotation nextAnnotation : annotations) {
                if (nextAnnotation != null && nextAnnotation instanceof XmlElement) {
                    XmlElement javaAnnotation = (XmlElement) nextAnnotation;
                    if (javaAnnotation.type() != XmlElement.DEFAULT.class) {
                        xmlElementType = javaAnnotation.type();
                    }
                }
            }
        }
    }
    if (areEquals(javaClass, byte[].class) || areEquals(javaClass, JAVAX_ACTIVATION_DATAHANDLER) || areEquals(javaClass, Source.class) || areEquals(javaClass, Image.class) || areEquals(javaClass, JAVAX_MAIL_INTERNET_MIMEMULTIPART)) {
        if (tmi == null || tmi.getXmlTagName() == null) {
            ElementDeclaration declaration = new ElementDeclaration(null, javaClass, javaClass.getQualifiedName(), false, XmlElementDecl.GLOBAL.class);
            declaration.setTypeMappingInfo(tmi);
            this.localElements.add(declaration);
        }
    } else if (javaClass.isArray()) {
        if (!helper.isBuiltInJavaType(javaClass.getComponentType())) {
            extraClasses.add(javaClass.getComponentType());
        }
        Class<?> generatedClass;
        if (null == tmi) {
            generatedClass = arrayClassesToGeneratedClasses.get(javaClass.getName());
        } else {
            generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfosToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
        }
        if (generatedClass == null) {
            generatedClass = generateWrapperForArrayClass(javaClass, tmi, xmlElementType, extraClasses);
            extraClasses.add(helper.getJavaClass(generatedClass));
            arrayClassesToGeneratedClasses.put(javaClass.getName(), generatedClass);
        }
        generatedClassesToArrayClasses.put(generatedClass, javaClass);
        typeMappingInfosToGeneratedClasses.put(tmi, generatedClass);
    } else if (helper.isCollectionType(javaClass)) {
        JavaClass componentClass;
        Collection args = javaClass.getActualTypeArguments();
        if (!args.isEmpty()) {
            componentClass = (JavaClass) args.iterator().next();
            if (!componentClass.isPrimitive()) {
                extraClasses.add(componentClass);
            }
        } else {
            componentClass = helper.getJavaClass(Object.class);
        }
        Class<?> generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfosToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
        if (generatedClass == null) {
            generatedClass = generateCollectionValue(javaClass, tmi, xmlElementType, extraClasses);
            extraClasses.add(helper.getJavaClass(generatedClass));
        }
        typeMappingInfosToGeneratedClasses.put(tmi, generatedClass);
    } else if (helper.isMapType(javaClass)) {
        JavaClass keyClass;
        JavaClass valueClass;
        Collection args = javaClass.getActualTypeArguments();
        Iterator argsIter = args.iterator();
        if (!args.isEmpty()) {
            keyClass = (JavaClass) argsIter.next();
            if (!helper.isBuiltInJavaType(keyClass)) {
                extraClasses.add(keyClass);
            }
            valueClass = (JavaClass) argsIter.next();
            if (!helper.isBuiltInJavaType(valueClass)) {
                extraClasses.add(valueClass);
            }
        } else {
            keyClass = helper.getJavaClass(Object.class);
            valueClass = helper.getJavaClass(Object.class);
        }
        Class<?> generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfosToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
        if (generatedClass == null) {
            generatedClass = generateWrapperForMapClass(javaClass, keyClass, valueClass, tmi);
            extraClasses.add(helper.getJavaClass(generatedClass));
        }
        typeMappingInfosToGeneratedClasses.put(tmi, generatedClass);
    } else {
        // process @XmlRegistry, @XmlSeeAlso and inner classes
        processClass(javaClass, classesToProcess);
    }
}
Also used : XmlElementDecl(jakarta.xml.bind.annotation.XmlElementDecl) JavaAnnotation(org.eclipse.persistence.jaxb.javamodel.JavaAnnotation) Annotation(java.lang.annotation.Annotation) Source(javax.xml.transform.Source) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) Iterator(java.util.Iterator) JavaMethod(org.eclipse.persistence.jaxb.javamodel.JavaMethod) XmlElement(jakarta.xml.bind.annotation.XmlElement) Collection(java.util.Collection) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass)

Example 2 with JavaAnnotation

use of org.eclipse.persistence.jaxb.javamodel.JavaAnnotation in project eclipselink by eclipse-ee4j.

the class XJCJavaPackageImpl method getAnnotations.

/**
 * Return all of the <code>Annotations</code> for this <code>JavaPackage</code>.
 *
 * @return A <code>Collection</code> containing this <code>JavaPackage's</code> <code>JavaAnnotations</code>.
 */
@Override
@SuppressWarnings("unchecked")
public Collection<JavaAnnotation> getAnnotations() {
    ArrayList<JavaAnnotation> annotationsList = new ArrayList<>();
    Collection<JAnnotationUse> annotations = xjcPackage.annotations();
    for (JAnnotationUse annotationUse : annotations) {
        XJCJavaAnnotationImpl xjcAnnotation = new XJCJavaAnnotationImpl(annotationUse, dynamicClassLoader);
        annotationsList.add(xjcAnnotation);
    }
    return annotationsList;
}
Also used : ArrayList(java.util.ArrayList) JAnnotationUse(com.sun.codemodel.JAnnotationUse) JavaAnnotation(org.eclipse.persistence.jaxb.javamodel.JavaAnnotation)

Example 3 with JavaAnnotation

use of org.eclipse.persistence.jaxb.javamodel.JavaAnnotation in project eclipselink by eclipse-ee4j.

the class JavaClassImpl method getDeclaredAnnotation.

@Override
public JavaAnnotation getDeclaredAnnotation(JavaClass arg0) {
    // the only annotation we will return if isMetadataComplete == true is XmlRegistry
    if (arg0 != null && (!isMetadataComplete || arg0.getQualifiedName().equals(XML_REGISTRY_CLASS_NAME))) {
        Class<?> annotationClass = ((JavaClassImpl) arg0).getJavaClass();
        Annotation[] annotations = javaModelImpl.getAnnotationHelper().getDeclaredAnnotations(getAnnotatedElement());
        for (Annotation annotation : annotations) {
            if (annotation.annotationType().equals(annotationClass)) {
                return new JavaAnnotationImpl(annotation);
            }
        }
    }
    return null;
}
Also used : JavaAnnotation(org.eclipse.persistence.jaxb.javamodel.JavaAnnotation) Annotation(java.lang.annotation.Annotation)

Example 4 with JavaAnnotation

use of org.eclipse.persistence.jaxb.javamodel.JavaAnnotation in project eclipselink by eclipse-ee4j.

the class XJCJavaFieldImpl method getAnnotations.

/**
 * Return all of the <code>Annotations</code> for this <code>JavaField</code>.
 *
 * @return A <code>Collection</code> containing this <code>JavaField's</code> <code>JavaAnnotations</code>.
 */
@Override
@SuppressWarnings("unchecked")
public Collection<JavaAnnotation> getAnnotations() {
    ArrayList<JavaAnnotation> annotationsList = new ArrayList<>();
    Collection<JAnnotationUse> annotations = xjcField.annotations();
    for (JAnnotationUse annotationUse : annotations) {
        XJCJavaAnnotationImpl xjcAnnotation = new XJCJavaAnnotationImpl(annotationUse, dynamicClassLoader);
        annotationsList.add(xjcAnnotation);
    }
    return annotationsList;
}
Also used : ArrayList(java.util.ArrayList) JAnnotationUse(com.sun.codemodel.JAnnotationUse) JavaAnnotation(org.eclipse.persistence.jaxb.javamodel.JavaAnnotation)

Example 5 with JavaAnnotation

use of org.eclipse.persistence.jaxb.javamodel.JavaAnnotation in project eclipselink by eclipse-ee4j.

the class XJCJavaMethodImpl method getAnnotations.

/**
 * Return all of the <code>Annotations</code> for this <code>JavaMethod</code>.
 *
 * @return A <code>Collection</code> containing this <code>JavaMethod's</code> <code>JavaAnnotations</code>.
 */
@Override
@SuppressWarnings("unchecked")
public Collection<JavaAnnotation> getAnnotations() {
    ArrayList<JavaAnnotation> annotationsList = new ArrayList<>();
    Collection<JAnnotationUse> annotations = xjcMethod.annotations();
    for (JAnnotationUse annotationUse : annotations) {
        XJCJavaAnnotationImpl xjcAnnotation = new XJCJavaAnnotationImpl(annotationUse, dynamicClassLoader);
        annotationsList.add(xjcAnnotation);
    }
    return annotationsList;
}
Also used : ArrayList(java.util.ArrayList) JAnnotationUse(com.sun.codemodel.JAnnotationUse) JavaAnnotation(org.eclipse.persistence.jaxb.javamodel.JavaAnnotation)

Aggregations

JavaAnnotation (org.eclipse.persistence.jaxb.javamodel.JavaAnnotation)8 Annotation (java.lang.annotation.Annotation)5 JAnnotationUse (com.sun.codemodel.JAnnotationUse)4 ArrayList (java.util.ArrayList)4 Source (javax.xml.transform.Source)2 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)2 JAnnotationArrayMember (com.sun.codemodel.JAnnotationArrayMember)1 JAnnotationClassValue (com.sun.codemodel.JAnnotationClassValue)1 JAnnotationStringValue (com.sun.codemodel.JAnnotationStringValue)1 JAnnotationValue (com.sun.codemodel.JAnnotationValue)1 JClass (com.sun.codemodel.JClass)1 XmlAttachmentRef (jakarta.xml.bind.annotation.XmlAttachmentRef)1 XmlElement (jakarta.xml.bind.annotation.XmlElement)1 XmlElementDecl (jakarta.xml.bind.annotation.XmlElementDecl)1 XmlMimeType (jakarta.xml.bind.annotation.XmlMimeType)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 QName (javax.xml.namespace.QName)1