Search in sources :

Example 1 with InjectionTarget

use of javax.enterprise.inject.spi.InjectionTarget 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)

Example 2 with InjectionTarget

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

the class WeldClassIntrospector method createFactory.

@Override
public ManagedReferenceFactory createFactory(Class<?> clazz) {
    final BeanManager beanManager = this.beanManager.getValue();
    final InjectionTarget injectionTarget = getInjectionTarget(clazz);
    return new ManagedReferenceFactory() {

        @Override
        public ManagedReference getReference() {
            final CreationalContext context = beanManager.createCreationalContext(null);
            final Object instance = injectionTarget.produce(context);
            injectionTarget.inject(instance, context);
            injectionTarget.postConstruct(instance);
            return new WeldManagedReference(injectionTarget, context, instance);
        }
    };
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) InjectionTarget(javax.enterprise.inject.spi.InjectionTarget) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 3 with InjectionTarget

use of javax.enterprise.inject.spi.InjectionTarget in project meecrowave by apache.

the class MeecrowaveRuleBase method doInject.

private static CreationalContext<Object> doInject(final Object instance) {
    final BeanManager bm = CDI.current().getBeanManager();
    final AnnotatedType<?> annotatedType = bm.createAnnotatedType(instance.getClass());
    final InjectionTarget injectionTarget = bm.createInjectionTarget(annotatedType);
    final CreationalContext<Object> creationalContext = bm.createCreationalContext(null);
    injectionTarget.inject(instance, creationalContext);
    return creationalContext;
}
Also used : InjectionTarget(javax.enterprise.inject.spi.InjectionTarget) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 4 with InjectionTarget

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

the class WeldClassIntrospector method createInstance.

@Override
public ManagedReference createInstance(final Object instance) {
    final BeanManager beanManager = this.beanManager.getValue();
    final InjectionTarget injectionTarget = getInjectionTarget(instance.getClass());
    final CreationalContext context = beanManager.createCreationalContext(null);
    injectionTarget.inject(instance, context);
    injectionTarget.postConstruct(instance);
    return new WeldManagedReference(injectionTarget, context, instance);
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) InjectionTarget(javax.enterprise.inject.spi.InjectionTarget) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 5 with InjectionTarget

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

the class WeldComponentService method start.

@Override
public synchronized void start(final StartContext context) throws StartException {
    final ClassLoader cl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    try {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader);
        beanManager = weldContainer.getValue().getBeanManager(beanDeploymentArchiveId);
        for (final Class<?> interceptor : interceptorClasses) {
            AnnotatedType<?> type = beanManager.createAnnotatedType(interceptor);
            @SuppressWarnings("rawtypes") InjectionTarget injectionTarget = beanManager.getInjectionTargetFactory(type).createInterceptorInjectionTarget();
            interceptorInjections.put(interceptor, beanManager.fireProcessInjectionTarget(type, injectionTarget));
        }
        if (ejbName != null) {
            EjbDescriptor<Object> descriptor = beanManager.getEjbDescriptor(ejbName);
            //may happen if the EJB was vetoed
            if (descriptor != null) {
                bean = beanManager.getBean(descriptor);
            }
        }
        if (bean instanceof SessionBean<?>) {
            SessionBean<?> sessionBean = (SessionBean<?>) bean;
            this.injectionTarget = sessionBean.getInjectionTarget();
            return;
        }
        WeldInjectionTarget<?> injectionTarget = InjectionTargets.createInjectionTarget(componentClass, bean, beanManager, !isComponentWithView);
        for (ComponentSupport support : ServiceLoader.load(ComponentSupport.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldComponentService.class))) {
            if (support.isProcessing(componentDescription)) {
                this.injectionTarget = support.processInjectionTarget(injectionTarget, componentDescription, beanManager);
                break;
            }
        }
        if (this.injectionTarget == null) {
            this.injectionTarget = injectionTarget;
        }
        beanManager.getServices().get(InjectionTargetService.class).validateProducer(injectionTarget);
    } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(cl);
    }
}
Also used : ComponentSupport(org.jboss.as.weld.spi.ComponentSupport) SessionBean(org.jboss.weld.bean.SessionBean) InjectionTargetService(org.jboss.weld.injection.producer.InjectionTargetService) WeldInjectionTarget(org.jboss.weld.manager.api.WeldInjectionTarget) InjectionTarget(javax.enterprise.inject.spi.InjectionTarget)

Aggregations

InjectionTarget (javax.enterprise.inject.spi.InjectionTarget)12 BeanManager (javax.enterprise.inject.spi.BeanManager)6 CreationalContext (javax.enterprise.context.spi.CreationalContext)4 AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Field (java.lang.reflect.Field)1 Member (java.lang.reflect.Member)1 Method (java.lang.reflect.Method)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 InjectionTargetFactory (javax.enterprise.inject.spi.InjectionTargetFactory)1 ProcessInjectionTarget (javax.enterprise.inject.spi.ProcessInjectionTarget)1 BeanAttributesImpl (org.apache.webbeans.component.BeanAttributesImpl)1 WebBeansContext (org.apache.webbeans.config.WebBeansContext)1 InjectionTargetFactoryImpl (org.apache.webbeans.container.InjectionTargetFactoryImpl)1 AnnotatedElementFactory (org.apache.webbeans.portable.AnnotatedElementFactory)1 WebBeansConfigurationListener (org.apache.webbeans.servlet.WebBeansConfigurationListener)1 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)1 ComponentSupport (org.jboss.as.weld.spi.ComponentSupport)1