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);
}
}
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);
}
};
}
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;
}
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);
}
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);
}
}
Aggregations