Search in sources :

Example 1 with ProcessInjectionTarget

use of javax.enterprise.inject.spi.ProcessInjectionTarget in project jersey by jersey.

the class CdiComponentProvider method processInjectionTarget.

@SuppressWarnings("unused")
private void processInjectionTarget(@Observes final ProcessInjectionTarget event) {
    final InjectionTarget it = event.getInjectionTarget();
    final Class<?> componentClass = event.getAnnotatedType().getJavaClass();
    final Set<InjectionPoint> cdiInjectionPoints = filterHk2InjectionPointsOut(it.getInjectionPoints());
    for (final InjectionPoint injectionPoint : cdiInjectionPoints) {
        final Member member = injectionPoint.getMember();
        if (member instanceof Field) {
            addInjecteeToSkip(componentClass, fieldsToSkip, (Field) member);
        } else if (member instanceof Method) {
            addInjecteeToSkip(componentClass, methodsToSkip, (Method) member);
        }
    }
    InjectionManagerInjectedCdiTarget target = null;
    if (isJerseyOrDependencyType(componentClass)) {
        target = new InjectionManagerInjectedCdiTarget(it) {

            @Override
            public Set<InjectionPoint> getInjectionPoints() {
                // CDI will not treat these classes as CDI beans (as they are not).
                return Collections.emptySet();
            }
        };
    } else if (isJaxRsComponentType(componentClass) || jaxrsInjectableTypes.contains(event.getAnnotatedType().getBaseType())) {
        target = new InjectionManagerInjectedCdiTarget(it) {

            @Override
            public Set<InjectionPoint> getInjectionPoints() {
                // Inject CDI beans into JAX-RS resources/providers/application.
                return cdiInjectionPoints;
            }
        };
    }
    if (target != null) {
        notify(target);
        //noinspection unchecked
        event.setInjectionTarget(target);
    }
}
Also used : Field(java.lang.reflect.Field) Set(java.util.Set) HashSet(java.util.HashSet) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) InjectionTarget(javax.enterprise.inject.spi.InjectionTarget) ProcessInjectionTarget(javax.enterprise.inject.spi.ProcessInjectionTarget) Method(java.lang.reflect.Method) Member(java.lang.reflect.Member)

Aggregations

Field (java.lang.reflect.Field)1 Member (java.lang.reflect.Member)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 InjectionTarget (javax.enterprise.inject.spi.InjectionTarget)1 ProcessInjectionTarget (javax.enterprise.inject.spi.ProcessInjectionTarget)1