Search in sources :

Example 1 with ResourceInjectionResolver

use of org.jboss.as.weld.spi.ResourceInjectionResolver 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)

Aggregations

Member (java.lang.reflect.Member)1 Method (java.lang.reflect.Method)1 Resource (javax.annotation.Resource)1 AnnotatedField (javax.enterprise.inject.spi.AnnotatedField)1 AnnotatedMember (javax.enterprise.inject.spi.AnnotatedMember)1 NamingException (javax.naming.NamingException)1 ResourceInjectionResolver (org.jboss.as.weld.spi.ResourceInjectionResolver)1