Search in sources :

Example 11 with DotName

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

the class PassivationAnnotationParsingProcessor method deploy.

public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
    for (DotName annotationName : PASSIVATION_ANNOTATIONS) {
        final List<AnnotationInstance> lifecycles = index.getAnnotations(annotationName);
        for (AnnotationInstance annotation : lifecycles) {
            processPassivation(eeModuleDescription, annotation.target(), annotationName, applicationClasses);
        }
    }
}
Also used : EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DotName(org.jboss.jandex.DotName) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Example 12 with DotName

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

the class MessageDrivenComponentDescriptionFactory method getMessageListenerInterface.

private String getMessageListenerInterface(final CompositeIndex compositeIndex, final AnnotationInstance messageBeanAnnotation) throws DeploymentUnitProcessingException {
    final AnnotationValue value = messageBeanAnnotation.value("messageListenerInterface");
    if (value != null)
        return value.asClass().name().toString();
    final ClassInfo beanClass = (ClassInfo) messageBeanAnnotation.target();
    final Set<DotName> interfaces = new HashSet<DotName>(getPotentialViewInterfaces(beanClass));
    // check super class(es) of the bean
    DotName superClassDotName = beanClass.superName();
    while (interfaces.isEmpty() && superClassDotName != null && !superClassDotName.toString().equals(Object.class.getName())) {
        final ClassInfo superClass = compositeIndex.getClassByName(superClassDotName);
        if (superClass == null) {
            break;
        }
        interfaces.addAll(getPotentialViewInterfaces(superClass));
        // move to next super class
        superClassDotName = superClass.superName();
    }
    if (interfaces.size() != 1)
        throw EjbLogger.ROOT_LOGGER.mdbDoesNotImplementNorSpecifyMessageListener(beanClass);
    return interfaces.iterator().next().toString();
}
Also used : AnnotationValue(org.jboss.jandex.AnnotationValue) DotName(org.jboss.jandex.DotName) ClassInfo(org.jboss.jandex.ClassInfo) HashSet(java.util.HashSet)

Example 13 with DotName

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

the class JPAAnnotationProcessor method processField.

private void processField(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final FieldInfo fieldInfo, final EEModuleClassDescription eeModuleClassDescription) throws DeploymentUnitProcessingException {
    final String fieldName = fieldInfo.name();
    final AnnotationValue declaredNameValue = annotation.value("name");
    final String declaredName = declaredNameValue != null ? declaredNameValue.asString() : null;
    final String localContextName;
    if (declaredName == null || declaredName.isEmpty()) {
        localContextName = fieldInfo.declaringClass().name().toString() + "/" + fieldName;
    } else {
        localContextName = declaredName;
    }
    //final AnnotationValue declaredTypeValue = annotation.value("type");
    final DotName declaredTypeDotName = fieldInfo.type().name();
    final DotName injectionTypeDotName = declaredTypeDotName == null || declaredTypeDotName.toString().equals(Object.class.getName()) ? fieldInfo.type().name() : declaredTypeDotName;
    final String injectionType = injectionTypeDotName.toString();
    final InjectionSource bindingSource = this.getBindingSource(deploymentUnit, annotation, injectionType, eeModuleClassDescription);
    if (bindingSource != null) {
        final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, bindingSource);
        eeModuleClassDescription.getBindingConfigurations().add(bindingConfiguration);
        // setup the injection target
        final InjectionTarget injectionTarget = new FieldInjectionTarget(fieldInfo.declaringClass().name().toString(), fieldName, fieldInfo.type().name().toString());
        // source is always local ENC jndi
        final InjectionSource injectionSource = new LookupInjectionSource(localContextName);
        final ResourceInjectionConfiguration injectionConfiguration = new ResourceInjectionConfiguration(injectionTarget, injectionSource);
        eeModuleClassDescription.addResourceInjection(injectionConfiguration);
    }
}
Also used : LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) InjectionSource(org.jboss.as.ee.component.InjectionSource) PersistenceContextInjectionSource(org.jboss.as.jpa.injectors.PersistenceContextInjectionSource) PersistenceUnitInjectionSource(org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource) AnnotationValue(org.jboss.jandex.AnnotationValue) FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget) MethodInjectionTarget(org.jboss.as.ee.component.MethodInjectionTarget) InjectionTarget(org.jboss.as.ee.component.InjectionTarget) FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget) DotName(org.jboss.jandex.DotName) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) ResourceInjectionConfiguration(org.jboss.as.ee.component.ResourceInjectionConfiguration)

Example 14 with DotName

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

the class ASHelper method isJaxwsService.

public static boolean isJaxwsService(final ClassInfo current, final Index index) {
    ClassInfo tmp = current;
    while (tmp != null) {
        final DotName superName = tmp.superName();
        if (JAXWS_SERVICE_CLASS.equals(superName)) {
            return true;
        }
        tmp = index.getClassByName(superName);
    }
    return false;
}
Also used : DotName(org.jboss.jandex.DotName) ClassInfo(org.jboss.jandex.ClassInfo)

Example 15 with DotName

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

the class ClassAnnotationInformationFactory method createAnnotationInformation.

public Map<String, ClassAnnotationInformation<A, T>> createAnnotationInformation(final CompositeIndex index, final PropertyReplacer propertyReplacer) {
    final List<TargetAnnotation> annotations = new ArrayList<TargetAnnotation>();
    if (multiAnnotationDotName != null) {
        for (AnnotationInstance multiInstance : index.getAnnotations(multiAnnotationDotName)) {
            annotations.addAll(fromMultiAnnotation(multiInstance));
        }
    }
    final List<AnnotationInstance> simpleAnnotations = index.getAnnotations(annotationDotName);
    if (simpleAnnotations != null) {
        for (AnnotationInstance annotation : simpleAnnotations) {
            annotations.add(new TargetAnnotation(annotation, annotation.target()));
        }
    }
    final Map<DotName, List<TargetAnnotation>> classLevel = new HashMap<DotName, List<TargetAnnotation>>();
    final Map<DotName, List<TargetAnnotation>> methodLevel = new HashMap<DotName, List<TargetAnnotation>>();
    final Map<DotName, List<TargetAnnotation>> fieldLevel = new HashMap<DotName, List<TargetAnnotation>>();
    for (TargetAnnotation instance : annotations) {
        final DotName targetClass = getAnnotationClass(instance.target()).name();
        if (instance.target() instanceof ClassInfo) {
            List<TargetAnnotation> data = classLevel.get(targetClass);
            if (data == null)
                classLevel.put(targetClass, data = new ArrayList<TargetAnnotation>(1));
            data.add(instance);
        } else if (instance.target() instanceof MethodInfo) {
            List<TargetAnnotation> data = methodLevel.get(targetClass);
            if (data == null)
                methodLevel.put(targetClass, data = new ArrayList<TargetAnnotation>(1));
            data.add(instance);
        } else if (instance.target() instanceof FieldInfo) {
            List<TargetAnnotation> data = fieldLevel.get(targetClass);
            if (data == null)
                fieldLevel.put(targetClass, data = new ArrayList<TargetAnnotation>(1));
            data.add(instance);
        } else if (instance.target() instanceof MethodParameterInfo) {
        //ignore for now
        } else {
            throw EeLogger.ROOT_LOGGER.unknownAnnotationTargetType(instance.target());
        }
    }
    final Map<String, ClassAnnotationInformation<A, T>> ret = new HashMap<String, ClassAnnotationInformation<A, T>>();
    final Set<DotName> allClasses = new HashSet<DotName>(classLevel.keySet());
    allClasses.addAll(methodLevel.keySet());
    allClasses.addAll(fieldLevel.keySet());
    for (DotName clazz : allClasses) {
        final List<TargetAnnotation> classAnnotations = classLevel.get(clazz);
        final List<T> classData;
        if (classAnnotations == null) {
            classData = Collections.emptyList();
        } else {
            classData = new ArrayList<T>(classAnnotations.size());
            for (TargetAnnotation instance : classAnnotations) {
                classData.add(fromAnnotation(instance.instance(), propertyReplacer));
            }
        }
        final List<TargetAnnotation> fieldAnnotations = fieldLevel.get(clazz);
        final Map<String, List<T>> fieldData;
        //field level annotations
        if (fieldAnnotations == null) {
            fieldData = Collections.emptyMap();
        } else {
            fieldData = new HashMap<String, List<T>>();
            for (TargetAnnotation instance : fieldAnnotations) {
                final String name = ((FieldInfo) instance.target()).name();
                List<T> data = fieldData.get(name);
                if (data == null) {
                    fieldData.put(name, data = new ArrayList<T>(1));
                }
                data.add(fromAnnotation(instance.instance(), propertyReplacer));
            }
        }
        final List<TargetAnnotation> methodAnnotations = methodLevel.get(clazz);
        final Map<MethodIdentifier, List<T>> methodData;
        //method level annotations
        if (methodAnnotations == null) {
            methodData = Collections.emptyMap();
        } else {
            methodData = new HashMap<MethodIdentifier, List<T>>();
            for (TargetAnnotation instance : methodAnnotations) {
                final MethodIdentifier identifier = getMethodIdentifier(instance.target());
                List<T> data = methodData.get(identifier);
                if (data == null) {
                    methodData.put(identifier, data = new ArrayList<T>(1));
                }
                data.add(fromAnnotation(instance.instance(), propertyReplacer));
            }
        }
        ClassAnnotationInformation<A, T> information = new ClassAnnotationInformation<A, T>(annotationType, classData, methodData, fieldData);
        ret.put(clazz.toString(), information);
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DotName(org.jboss.jandex.DotName) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) MethodInfo(org.jboss.jandex.MethodInfo) MethodParameterInfo(org.jboss.jandex.MethodParameterInfo) AnnotationInstance(org.jboss.jandex.AnnotationInstance) FieldInfo(org.jboss.jandex.FieldInfo) ClassInfo(org.jboss.jandex.ClassInfo)

Aggregations

DotName (org.jboss.jandex.DotName)15 ClassInfo (org.jboss.jandex.ClassInfo)10 AnnotationInstance (org.jboss.jandex.AnnotationInstance)7 HashSet (java.util.HashSet)6 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)6 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)5 HashMap (java.util.HashMap)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3 Set (java.util.Set)2 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)2 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)2 AnnotationTarget (org.jboss.jandex.AnnotationTarget)2 AnnotationValue (org.jboss.jandex.AnnotationValue)2 Module (org.jboss.modules.Module)2 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ServletContainerInitializer (javax.servlet.ServletContainerInitializer)1 HandlesTypes (javax.servlet.annotation.HandlesTypes)1 FieldInjectionTarget (org.jboss.as.ee.component.FieldInjectionTarget)1