Search in sources :

Example 1 with AnnotatedMember

use of javax.enterprise.inject.spi.AnnotatedMember in project wildfly by wildfly.

the class WeldResourceInjectionServices method resolveResource.

@Override
public Object resolveResource(InjectionPoint injectionPoint) {
    final Member member = injectionPoint.getMember();
    AnnotatedMember<?> annotatedMember;
    if (injectionPoint.getAnnotated() instanceof AnnotatedField) {
        annotatedMember = (AnnotatedField<?>) injectionPoint.getAnnotated();
    } else {
        annotatedMember = ((AnnotatedParameter<?>) injectionPoint.getAnnotated()).getDeclaringCallable();
    }
    if (!annotatedMember.isAnnotationPresent(Resource.class)) {
        throw WeldLogger.ROOT_LOGGER.annotationNotFound(Resource.class, member);
    }
    if (member instanceof Method && ((Method) member).getParameterTypes().length != 1) {
        throw WeldLogger.ROOT_LOGGER.injectionPointNotAJavabean((Method) member);
    }
    String name = getResourceName(injectionPoint);
    for (ResourceInjectionResolver resolver : resourceResolvers) {
        Object result = resolver.resolve(name);
        if (result != null) {
            return result;
        }
    }
    try {
        return context.lookup(name);
    } catch (NamingException e) {
        throw WeldLogger.ROOT_LOGGER.couldNotFindResource(name, injectionPoint.getMember().toString(), e);
    }
}
Also used : Resource(javax.annotation.Resource) ResourceInjectionResolver(org.jboss.as.weld.spi.ResourceInjectionResolver) NamingException(javax.naming.NamingException) Method(java.lang.reflect.Method) AnnotatedField(javax.enterprise.inject.spi.AnnotatedField) AnnotatedMember(javax.enterprise.inject.spi.AnnotatedMember) Member(java.lang.reflect.Member)

Example 2 with AnnotatedMember

use of javax.enterprise.inject.spi.AnnotatedMember in project deltaspike by apache.

the class DefaultMockFilter method isMockedImplementationSupported.

@Override
public boolean isMockedImplementationSupported(BeanManager beanManager, Annotated annotated) {
    if (!isMockSupportEnabled(annotated)) {
        return false;
    }
    Class origin = null;
    if (annotated instanceof AnnotatedType) {
        origin = ((AnnotatedType) annotated).getJavaClass();
        Set<Annotation> annotations = new HashSet<Annotation>();
        annotations.addAll(annotated.getAnnotations());
        for (AnnotatedMethod annotatedMethod : (Set<javax.enterprise.inject.spi.AnnotatedMethod>) ((AnnotatedType) annotated).getMethods()) {
            annotations.addAll(annotatedMethod.getAnnotations());
        }
        if (isEjbOrAnnotatedTypeWithInterceptorAnnotation(beanManager, annotations, origin.getName())) {
            return false;
        }
    } else if (annotated instanceof AnnotatedMember) {
        Member member = ((AnnotatedMember) annotated).getJavaMember();
        origin = member.getDeclaringClass();
        if (isEjbOrAnnotatedTypeWithInterceptorAnnotation(beanManager, annotated.getAnnotations(), member.toString())) {
            return false;
        }
    }
    if (origin != null && origin.getPackage() == null) {
        LOG.warning("Please don't use the default-package for " + origin.getName());
        return true;
    }
    return origin != null && !isInternalPackage(origin.getPackage().getName());
}
Also used : AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) Set(java.util.Set) HashSet(java.util.HashSet) AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod) AnnotatedMember(javax.enterprise.inject.spi.AnnotatedMember) AnnotatedMember(javax.enterprise.inject.spi.AnnotatedMember) Member(java.lang.reflect.Member) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet)

Aggregations

Member (java.lang.reflect.Member)2 AnnotatedMember (javax.enterprise.inject.spi.AnnotatedMember)2 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Resource (javax.annotation.Resource)1 AnnotatedField (javax.enterprise.inject.spi.AnnotatedField)1 AnnotatedMethod (javax.enterprise.inject.spi.AnnotatedMethod)1 AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)1 NamingException (javax.naming.NamingException)1 ResourceInjectionResolver (org.jboss.as.weld.spi.ResourceInjectionResolver)1