Search in sources :

Example 16 with AnnotationTarget

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

the class ServletContainerInitializerDeploymentProcessor method processHandlesType.

private Set<ClassInfo> processHandlesType(DotName typeName, Class<?> type, CompositeIndex index) throws DeploymentUnitProcessingException {
    Set<ClassInfo> classes = new HashSet<ClassInfo>();
    if (type.isAnnotation()) {
        List<AnnotationInstance> instances = index.getAnnotations(typeName);
        for (AnnotationInstance instance : instances) {
            AnnotationTarget annotationTarget = instance.target();
            if (annotationTarget instanceof ClassInfo) {
                classes.add((ClassInfo) annotationTarget);
            } else if (annotationTarget instanceof FieldInfo) {
                classes.add(((FieldInfo) annotationTarget).declaringClass());
            } else if (annotationTarget instanceof MethodInfo) {
                classes.add(((MethodInfo) annotationTarget).declaringClass());
            } else if (annotationTarget instanceof MethodParameterInfo) {
                classes.add(((MethodParameterInfo) annotationTarget).method().declaringClass());
            }
        }
    } else {
        classes.addAll(index.getAllKnownSubclasses(typeName));
        classes.addAll(index.getAllKnownImplementors(typeName));
    }
    return classes;
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) MethodInfo(org.jboss.jandex.MethodInfo) MethodParameterInfo(org.jboss.jandex.MethodParameterInfo) AnnotationInstance(org.jboss.jandex.AnnotationInstance) FieldInfo(org.jboss.jandex.FieldInfo) HashSet(java.util.HashSet) ClassInfo(org.jboss.jandex.ClassInfo)

Example 17 with AnnotationTarget

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

the class WSRefAnnotationProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit unit = phaseContext.getDeploymentUnit();
    // Process @WebServiceRef annotations
    final List<AnnotationInstance> webServiceRefAnnotations = getAnnotations(unit, WEB_SERVICE_REF_ANNOTATION);
    for (final AnnotationInstance annotation : webServiceRefAnnotations) {
        final AnnotationTarget annotationTarget = annotation.target();
        final WSRefAnnotationWrapper annotationWrapper = new WSRefAnnotationWrapper(annotation);
        if (annotationTarget instanceof FieldInfo) {
            processFieldRef(unit, annotationWrapper, (FieldInfo) annotationTarget);
        } else if (annotationTarget instanceof MethodInfo) {
            processMethodRef(unit, annotationWrapper, (MethodInfo) annotationTarget);
        } else if (annotationTarget instanceof ClassInfo) {
            processClassRef(unit, annotationWrapper, (ClassInfo) annotationTarget);
        }
    }
    // Process @WebServiceRefs annotations
    final List<AnnotationInstance> webServiceRefsAnnotations = getAnnotations(unit, WEB_SERVICE_REFS_ANNOTATION);
    for (final AnnotationInstance outerAnnotation : webServiceRefsAnnotations) {
        final AnnotationTarget annotationTarget = outerAnnotation.target();
        if (annotationTarget instanceof ClassInfo) {
            final AnnotationInstance[] values = outerAnnotation.value("value").asNestedArray();
            for (final AnnotationInstance annotation : values) {
                final WSRefAnnotationWrapper annotationWrapper = new WSRefAnnotationWrapper(annotation);
                processClassRef(unit, annotationWrapper, (ClassInfo) annotationTarget);
            }
        }
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) MethodInfo(org.jboss.jandex.MethodInfo) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) FieldInfo(org.jboss.jandex.FieldInfo) ClassInfo(org.jboss.jandex.ClassInfo)

Example 18 with AnnotationTarget

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

the class SessionBeanComponentDescriptionFactory method processSessionBeans.

private void processSessionBeans(final DeploymentUnit deploymentUnit, final List<AnnotationInstance> sessionBeanAnnotations, final SessionBeanComponentDescription.SessionBeanType annotatedSessionBeanType) {
    final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
    final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName();
    PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
    // process these session bean annotations and create component descriptions out of it
    for (final AnnotationInstance sessionBeanAnnotation : sessionBeanAnnotations) {
        final AnnotationTarget target = sessionBeanAnnotation.target();
        if (!(target instanceof ClassInfo)) {
            // Let's just WARN and move on. No need to throw an error
            EjbLogger.DEPLOYMENT_LOGGER.warn(EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(sessionBeanAnnotation.name().toString(), target).getMessage());
            continue;
        }
        final ClassInfo sessionBeanClassInfo = (ClassInfo) target;
        // skip if it's not a valid class for session bean
        if (!assertSessionBeanClassValidity(sessionBeanClassInfo)) {
            continue;
        }
        final String ejbName = sessionBeanClassInfo.name().local();
        final AnnotationValue nameValue = sessionBeanAnnotation.value("name");
        final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? ejbName : propertyReplacer.replaceProperties(nameValue.asString());
        final SessionBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, SessionBeanMetaData.class);
        final SessionBeanComponentDescription.SessionBeanType sessionBeanType;
        final String beanClassName;
        if (beanMetaData != null) {
            beanClassName = override(sessionBeanClassInfo.name().toString(), beanMetaData.getEjbClass());
            sessionBeanType = override(annotatedSessionBeanType, descriptionOf(((SessionBeanMetaData) beanMetaData).getSessionType()));
        } else {
            beanClassName = sessionBeanClassInfo.name().toString();
            sessionBeanType = annotatedSessionBeanType;
        }
        final SessionBeanComponentDescription sessionBeanDescription;
        switch(sessionBeanType) {
            case STATELESS:
                sessionBeanDescription = new StatelessComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, beanMetaData);
                break;
            case STATEFUL:
                sessionBeanDescription = new StatefulComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, beanMetaData);
                // If passivation is disabled for the SFSB, either via annotation or via DD, then setup the component
                // description appropriately
                final boolean passivationCapableAnnotationValue = sessionBeanAnnotation.value("passivationCapable") == null ? true : sessionBeanAnnotation.value("passivationCapable").asBoolean();
                final Boolean passivationCapableDeploymentDescriptorValue;
                if ((beanMetaData instanceof SessionBean32MetaData)) {
                    passivationCapableDeploymentDescriptorValue = ((SessionBean32MetaData) beanMetaData).isPassivationCapable();
                } else {
                    passivationCapableDeploymentDescriptorValue = null;
                }
                final boolean passivationApplicable = override(passivationCapableDeploymentDescriptorValue, passivationCapableAnnotationValue);
                ((StatefulComponentDescription) sessionBeanDescription).setPassivationApplicable(passivationApplicable);
                break;
            case SINGLETON:
                sessionBeanDescription = new SingletonComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, beanMetaData);
                break;
            default:
                throw EjbLogger.ROOT_LOGGER.unknownSessionBeanType(sessionBeanType.name());
        }
        addComponent(deploymentUnit, sessionBeanDescription);
    }
    EjbDeploymentMarker.mark(deploymentUnit);
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) SessionBeanMetaData(org.jboss.metadata.ejb.spec.SessionBeanMetaData) ServiceName(org.jboss.msc.service.ServiceName) StatelessComponentDescription(org.jboss.as.ejb3.component.stateless.StatelessComponentDescription) StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) EjbJarDescription(org.jboss.as.ejb3.deployment.EjbJarDescription) AbstractDeploymentUnitProcessor.getEjbJarDescription(org.jboss.as.ejb3.deployment.processors.AbstractDeploymentUnitProcessor.getEjbJarDescription) SessionBean32MetaData(org.jboss.metadata.ejb.spec.SessionBean32MetaData) AnnotationValue(org.jboss.jandex.AnnotationValue) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) SingletonComponentDescription(org.jboss.as.ejb3.component.singleton.SingletonComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) AnnotationInstance(org.jboss.jandex.AnnotationInstance) 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