Search in sources :

Example 16 with ClassInfo

use of org.jboss.jandex.ClassInfo 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)

Example 17 with ClassInfo

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

the class LifecycleAnnotationParsingProcessor method processLifeCycle.

private void processLifeCycle(final EEModuleDescription eeModuleDescription, final AnnotationTarget target, final DotName annotationType, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
    if (!(target instanceof MethodInfo)) {
        throw EeLogger.ROOT_LOGGER.methodOnlyAnnotation(annotationType);
    }
    final MethodInfo methodInfo = MethodInfo.class.cast(target);
    final ClassInfo classInfo = methodInfo.declaringClass();
    final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
    final Type[] args = methodInfo.args();
    if (args.length > 1) {
        ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidNumberOfArguments(methodInfo.name(), annotationType, classInfo.name()));
        return;
    } else if (args.length == 1 && !args[0].name().toString().equals(InvocationContext.class.getName())) {
        ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidSignature(methodInfo.name(), annotationType, classInfo.name(), "void methodName(InvocationContext ctx)"));
        return;
    }
    final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription());
    if (annotationType == POST_CONSTRUCT_ANNOTATION) {
        builder.setPostConstruct(getMethodIdentifier(args, methodInfo));
    } else if (annotationType == PRE_DESTROY_ANNOTATION) {
        builder.setPreDestroy(getMethodIdentifier(args, methodInfo));
    } else if (annotationType == AROUND_CONSTRUCT_ANNOTATION) {
        builder.setAroundConstruct(getMethodIdentifier(args, methodInfo));
    }
    classDescription.setInterceptorClassDescription(builder.build());
}
Also used : Type(org.jboss.jandex.Type) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) MethodInfo(org.jboss.jandex.MethodInfo) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) ClassInfo(org.jboss.jandex.ClassInfo)

Example 18 with ClassInfo

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

the class ResourceInjectionAnnotationParsingProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
    final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final PropertyReplacer replacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
    if (module == null) {
        return;
    }
    final List<AnnotationInstance> resourceAnnotations = index.getAnnotations(RESOURCE_ANNOTATION_NAME);
    for (AnnotationInstance annotation : resourceAnnotations) {
        final AnnotationTarget annotationTarget = annotation.target();
        final AnnotationValue nameValue = annotation.value("name");
        final String name = (nameValue != null) ? replacer.replaceProperties(nameValue.asString()) : null;
        final AnnotationValue typeValue = annotation.value("type");
        final String type = typeValue != null ? typeValue.asClass().name().toString() : null;
        if (annotationTarget instanceof FieldInfo) {
            final FieldInfo fieldInfo = (FieldInfo) annotationTarget;
            final ClassInfo classInfo = fieldInfo.declaringClass();
            EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
            processFieldResource(phaseContext, fieldInfo, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer);
        } else if (annotationTarget instanceof MethodInfo) {
            final MethodInfo methodInfo = (MethodInfo) annotationTarget;
            ClassInfo classInfo = methodInfo.declaringClass();
            EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
            processMethodResource(phaseContext, methodInfo, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer);
        } else if (annotationTarget instanceof ClassInfo) {
            final ClassInfo classInfo = (ClassInfo) annotationTarget;
            EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
            processClassResource(phaseContext, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer);
        }
    }
    final List<AnnotationInstance> resourcesAnnotations = index.getAnnotations(RESOURCES_ANNOTATION_NAME);
    for (AnnotationInstance outerAnnotation : resourcesAnnotations) {
        final AnnotationTarget annotationTarget = outerAnnotation.target();
        if (annotationTarget instanceof ClassInfo) {
            final ClassInfo classInfo = (ClassInfo) annotationTarget;
            final AnnotationInstance[] values = outerAnnotation.value("value").asNestedArray();
            for (AnnotationInstance annotation : values) {
                final AnnotationValue nameValue = annotation.value("name");
                final String name = (nameValue != null) ? replacer.replaceProperties(nameValue.asString()) : null;
                final AnnotationValue typeValue = annotation.value("type");
                final String type = (typeValue != null) ? typeValue.asClass().name().toString() : null;
                EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
                processClassResource(phaseContext, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer);
            }
        }
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) AnnotationValue(org.jboss.jandex.AnnotationValue) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) MethodInfo(org.jboss.jandex.MethodInfo) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) FieldInfo(org.jboss.jandex.FieldInfo) ClassInfo(org.jboss.jandex.ClassInfo)

Example 19 with ClassInfo

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

the class ManagedBeanAnnotationProcessor method deploy.

/**
     * Check the deployment annotation index for all classes with the @ManagedBean annotation.  For each class with the
     * annotation, collect all the required information to create a managed bean instance, and attach it to the context.
     *
     * @param phaseContext the deployment unit context
     * @throws DeploymentUnitProcessingException
     *
     */
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEResourceReferenceProcessorRegistry registry = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    final PropertyReplacer replacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
    if (compositeIndex == null) {
        return;
    }
    final List<AnnotationInstance> instances = compositeIndex.getAnnotations(MANAGED_BEAN_ANNOTATION_NAME);
    if (instances == null || instances.isEmpty()) {
        return;
    }
    for (AnnotationInstance instance : instances) {
        AnnotationTarget target = instance.target();
        if (!(target instanceof ClassInfo)) {
            throw EeLogger.ROOT_LOGGER.classOnlyAnnotation("@ManagedBean", target);
        }
        final ClassInfo classInfo = (ClassInfo) target;
        // skip if it's not a valid managed bean class
        if (!assertManagedBeanClassValidity(classInfo)) {
            continue;
        }
        final String beanClassName = classInfo.name().toString();
        // Get the managed bean name from the annotation
        final AnnotationValue nameValue = instance.value();
        final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? beanClassName : replacer.replaceProperties(nameValue.asString());
        final ManagedBeanComponentDescription componentDescription = new ManagedBeanComponentDescription(beanName, beanClassName, moduleDescription, deploymentUnit.getServiceName());
        // Add the view
        ViewDescription viewDescription = new ViewDescription(componentDescription, beanClassName);
        viewDescription.getConfigurators().addFirst(new ViewConfigurator() {

            public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
                // Add MB association interceptors
                configuration.addClientPostConstructInterceptor(ManagedBeanCreateInterceptor.FACTORY, InterceptorOrder.ClientPostConstruct.INSTANCE_CREATE);
                final ClassLoader classLoader = componentConfiguration.getModuleClassLoader();
                configuration.addViewInterceptor(AccessCheckingInterceptor.getFactory(), InterceptorOrder.View.CHECKING_INTERCEPTOR);
                configuration.addViewInterceptor(new ImmediateInterceptorFactory(new ContextClassLoaderInterceptor(classLoader)), InterceptorOrder.View.TCCL_INTERCEPTOR);
            }
        });
        viewDescription.getBindingNames().addAll(Arrays.asList("java:module/" + beanName, "java:app/" + moduleDescription.getModuleName() + "/" + beanName));
        componentDescription.getViews().add(viewDescription);
        moduleDescription.addComponent(componentDescription);
        // register an EEResourceReferenceProcessor which can process @Resource references to this managed bean.
        registry.registerResourceReferenceProcessor(new ManagedBeanResourceReferenceProcessor(beanClassName));
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ManagedBeanComponentDescription(org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) ContextClassLoaderInterceptor(org.jboss.invocation.ContextClassLoaderInterceptor) ManagedBeanResourceReferenceProcessor(org.jboss.as.ee.managedbean.component.ManagedBeanResourceReferenceProcessor) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) EEResourceReferenceProcessorRegistry(org.jboss.as.ee.component.deployers.EEResourceReferenceProcessorRegistry) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) AnnotationValue(org.jboss.jandex.AnnotationValue) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 20 with ClassInfo

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

the class ResourceDefinitionAnnotationProcessor method getAnnotatedClassBindingConfigurations.

private List<BindingConfiguration> getAnnotatedClassBindingConfigurations(EEModuleDescription moduleDescription, AnnotationInstance annotationInstance) throws DeploymentUnitProcessingException {
    final AnnotationTarget target = annotationInstance.target();
    if (!(target instanceof ClassInfo)) {
        throw ROOT_LOGGER.classOnlyAnnotation(annotationInstance.toString(), target);
    }
    final ClassInfo classInfo = (ClassInfo) target;
    return moduleDescription.addOrGetLocalClassDescription(classInfo.name().toString()).getBindingConfigurations();
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) ClassInfo(org.jboss.jandex.ClassInfo)

Aggregations

ClassInfo (org.jboss.jandex.ClassInfo)43 AnnotationInstance (org.jboss.jandex.AnnotationInstance)26 AnnotationTarget (org.jboss.jandex.AnnotationTarget)18 MethodInfo (org.jboss.jandex.MethodInfo)14 HashSet (java.util.HashSet)12 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)12 DotName (org.jboss.jandex.DotName)10 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)9 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)9 AnnotationValue (org.jboss.jandex.AnnotationValue)9 HashMap (java.util.HashMap)7 FieldInfo (org.jboss.jandex.FieldInfo)7 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)6 WebService (javax.jws.WebService)5 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)5 ArrayList (java.util.ArrayList)4 WebServiceProvider (javax.xml.ws.WebServiceProvider)4 InterceptorClassDescription (org.jboss.as.ee.component.interceptors.InterceptorClassDescription)4 PropertyReplacer (org.jboss.metadata.property.PropertyReplacer)4 Module (org.jboss.modules.Module)4