Search in sources :

Example 1 with AnnotationTarget

use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.

the class JSFAnnotationProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Map<Class<? extends Annotation>, Set<Class<?>>> instances = new HashMap<Class<? extends Annotation>, Set<Class<?>>>();
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (compositeIndex == null) {
        // Can not continue without index
        return;
    }
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (module == null) {
        // Can not continue without module
        return;
    }
    final ClassLoader classLoader = module.getClassLoader();
    for (FacesAnnotation annotation : FacesAnnotation.values()) {
        final List<AnnotationInstance> annotationInstances = compositeIndex.getAnnotations(annotation.indexName);
        if (annotationInstances == null || annotationInstances.isEmpty()) {
            continue;
        }
        final Set<Class<?>> discoveredClasses = new HashSet<Class<?>>();
        instances.put(annotation.annotationClass, discoveredClasses);
        for (AnnotationInstance annotationInstance : annotationInstances) {
            final AnnotationTarget target = annotationInstance.target();
            if (target instanceof ClassInfo) {
                final DotName className = ClassInfo.class.cast(target).name();
                final Class<?> annotatedClass;
                try {
                    annotatedClass = classLoader.loadClass(className.toString());
                } catch (ClassNotFoundException e) {
                    throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.classLoadingFailed(className));
                }
                discoveredClasses.add(annotatedClass);
            } else {
                throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.invalidAnnotationLocation(annotation, target));
            }
        }
    }
    deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(FACES_ANNOTATIONS_SC_ATTR, instances));
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) DotName(org.jboss.jandex.DotName) Annotation(java.lang.annotation.Annotation) ServletContextAttribute(org.jboss.as.web.common.ServletContextAttribute) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) HashSet(java.util.HashSet) ClassInfo(org.jboss.jandex.ClassInfo)

Example 2 with AnnotationTarget

use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.

the class JPAAnnotationProcessor method processPersistenceAnnotations.

private void processPersistenceAnnotations(final DeploymentUnit deploymentUnit, final EEModuleDescription eeModuleDescription, List<AnnotationInstance> persistenceContexts, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
    for (AnnotationInstance annotation : persistenceContexts) {
        ClassInfo declaringClass;
        final AnnotationTarget annotationTarget = annotation.target();
        if (annotationTarget instanceof FieldInfo) {
            FieldInfo fieldInfo = (FieldInfo) annotationTarget;
            declaringClass = fieldInfo.declaringClass();
            EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString());
            this.processField(deploymentUnit, annotation, fieldInfo, eeModuleClassDescription);
        } else if (annotationTarget instanceof MethodInfo) {
            MethodInfo methodInfo = (MethodInfo) annotationTarget;
            declaringClass = methodInfo.declaringClass();
            EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString());
            this.processMethod(deploymentUnit, annotation, methodInfo, eeModuleClassDescription);
        } else if (annotationTarget instanceof ClassInfo) {
            declaringClass = (ClassInfo) annotationTarget;
            EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString());
            this.processClass(deploymentUnit, annotation, eeModuleClassDescription);
        }
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) MethodInfo(org.jboss.jandex.MethodInfo) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) AnnotationInstance(org.jboss.jandex.AnnotationInstance) FieldInfo(org.jboss.jandex.FieldInfo) ClassInfo(org.jboss.jandex.ClassInfo)

Example 3 with AnnotationTarget

use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.

the class WSClassVerificationProcessor method verifyApacheCXFModuleDependencyRequirement.

private void verifyApacheCXFModuleDependencyRequirement(DeploymentUnit unit) {
    if (!hasCxfModuleDependency(unit)) {
        //notify user if he clearly forgot the CXF module dependency
        final CompositeIndex index = unit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
        final DotName[] dotNames = { WEB_SERVICE_ANNOTATION, WEB_SERVICE_PROVIDER_ANNOTATION };
        for (final DotName dotName : dotNames) {
            for (AnnotationInstance ai : index.getAnnotations(dotName)) {
                AnnotationTarget at = ai.target();
                if (at instanceof ClassInfo) {
                    final ClassInfo clazz = (ClassInfo) ai.target();
                    for (DotName dn : clazz.annotations().keySet()) {
                        if (dn.toString().startsWith("org.apache.cxf")) {
                            WSLogger.ROOT_LOGGER.missingModuleDependency(dn.toString(), clazz.name().toString(), "org.apache.cxf");
                        }
                    }
                }
            }
        }
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) DotName(org.jboss.jandex.DotName) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 4 with AnnotationTarget

use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.

the class WSHandlerChainAnnotationProcessor method processHandlerChainAnnotations.

private static void processHandlerChainAnnotations(final ResourceRoot currentResourceRoot, final List<ResourceRoot> resourceRoots, final Index index, final WSEndpointHandlersMapping mapping) throws DeploymentUnitProcessingException {
    final List<AnnotationInstance> webServiceAnnotations = index.getAnnotations(WEB_SERVICE_ANNOTATION);
    final List<AnnotationInstance> webServiceProviderAnnotations = index.getAnnotations(WEB_SERVICE_PROVIDER_ANNOTATION);
    for (final AnnotationInstance annotationInstance : webServiceAnnotations) {
        final AnnotationTarget annotationTarget = annotationInstance.target();
        if (annotationTarget instanceof ClassInfo) {
            final ClassInfo classInfo = (ClassInfo) annotationTarget;
            if (isJaxwsEndpoint(classInfo, index)) {
                AnnotationInstance handlerChainAnnotationInstance = getHandlerChainAnnotationInstance(classInfo);
                //implementation bean. The service implementation bean’s @HandlerChain is used if @HandlerChain is present on both."
                if (handlerChainAnnotationInstance == null) {
                    handlerChainAnnotationInstance = getEndpointInterfaceHandlerChainAnnotationInstance(classInfo, index);
                }
                if (handlerChainAnnotationInstance != null) {
                    final String endpointClass = classInfo.name().toString();
                    processHandlerChainAnnotation(currentResourceRoot, resourceRoots, handlerChainAnnotationInstance, endpointClass, mapping);
                }
            }
        } else {
        // We ignore fields & methods annotated with @HandlerChain.
        // These are used always in combination with @WebServiceRef
        // which are always referencing JAXWS client proxies only.
        }
    }
    for (final AnnotationInstance annotationInstance : webServiceProviderAnnotations) {
        final AnnotationTarget annotationTarget = annotationInstance.target();
        if (annotationTarget instanceof ClassInfo) {
            final ClassInfo classInfo = (ClassInfo) annotationTarget;
            final AnnotationInstance handlerChainAnnotationInstance = getHandlerChainAnnotationInstance(classInfo);
            if (handlerChainAnnotationInstance != null && isJaxwsEndpoint(classInfo, index)) {
                final String endpointClass = classInfo.name().toString();
                processHandlerChainAnnotation(currentResourceRoot, resourceRoots, handlerChainAnnotationInstance, endpointClass, mapping);
            }
        } else {
        // We ignore fields & methods annotated with @HandlerChain.
        // These are used always in combination with @WebServiceRef
        // which are always referencing JAXWS client proxies only.
        }
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 5 with AnnotationTarget

use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.

the class JandexAnnotationRepositoryImpl method getAnnotation.

@Override
public Collection<Annotation> getAnnotation(Class<?> annotationClass) {
    List<AnnotationInstance> instances = backingRepository.getAnnotations(DotName.createSimple(annotationClass.getName()));
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(instances.size());
    for (AnnotationInstance instance : instances) {
        AnnotationTarget target = instance.target();
        Annotation annotation = null;
        if (target instanceof MethodInfo) {
            MethodInfo m = (MethodInfo) target;
            List<String> parameterTypes = new ArrayList<String>(m.args().length);
            for (Type type : m.args()) {
                parameterTypes.add(type.toString());
            }
            String declaringClass = m.declaringClass().name().toString();
            annotation = new AnnotationImpl(declaringClass, cl, parameterTypes, m.name(), true, false, annotationClass);
        }
        if (target instanceof FieldInfo) {
            FieldInfo f = (FieldInfo) target;
            String declaringClass = f.declaringClass().name().toString();
            annotation = new AnnotationImpl(declaringClass, cl, null, f.name(), false, true, annotationClass);
        }
        if (target instanceof ClassInfo) {
            ClassInfo c = (ClassInfo) target;
            annotation = new AnnotationImpl(c.name().toString(), cl, null, null, false, false, annotationClass);
        }
        if (annotation != null) {
            annotations.add(annotation);
        }
    }
    annotations.trimToSize();
    if (annotations.size() == 0) {
        return null;
    } else {
        return Collections.unmodifiableList(annotations);
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) ArrayList(java.util.ArrayList) Annotation(org.jboss.jca.common.spi.annotations.repository.Annotation) Type(org.jboss.jandex.Type) MethodInfo(org.jboss.jandex.MethodInfo) AnnotationInstance(org.jboss.jandex.AnnotationInstance) FieldInfo(org.jboss.jandex.FieldInfo) ClassInfo(org.jboss.jandex.ClassInfo)

Aggregations

AnnotationTarget (org.jboss.jandex.AnnotationTarget)18 ClassInfo (org.jboss.jandex.ClassInfo)18 AnnotationInstance (org.jboss.jandex.AnnotationInstance)16 AnnotationValue (org.jboss.jandex.AnnotationValue)7 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)6 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)6 FieldInfo (org.jboss.jandex.FieldInfo)6 MethodInfo (org.jboss.jandex.MethodInfo)6 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)4 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)4 PropertyReplacer (org.jboss.metadata.property.PropertyReplacer)4 HashSet (java.util.HashSet)3 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)2 EjbJarDescription (org.jboss.as.ejb3.deployment.EjbJarDescription)2 AbstractDeploymentUnitProcessor.getEjbJarDescription (org.jboss.as.ejb3.deployment.processors.AbstractDeploymentUnitProcessor.getEjbJarDescription)2 DotName (org.jboss.jandex.DotName)2 Module (org.jboss.modules.Module)2