use of javax.enterprise.inject.spi.InjectionTarget in project meecrowave by apache.
the class Injector method inject.
public static CreationalContext<?> inject(final Object testInstance) {
if (testInstance == null) {
return null;
}
final BeanManager bm = CDI.current().getBeanManager();
final AnnotatedType<?> annotatedType = bm.createAnnotatedType(testInstance.getClass());
final InjectionTarget injectionTarget = bm.createInjectionTarget(annotatedType);
final CreationalContext<?> creationalContext = bm.createCreationalContext(null);
injectionTarget.inject(testInstance, creationalContext);
return creationalContext;
}
use of javax.enterprise.inject.spi.InjectionTarget in project meecrowave by apache.
the class Meecrowave method inject.
public <T> AutoCloseable inject(final T 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::release;
}
use of javax.enterprise.inject.spi.InjectionTarget in project meecrowave by apache.
the class CDIInstanceManager method newInstance.
@Override
public void newInstance(final Object o) throws IllegalAccessException, InvocationTargetException, NamingException {
if (WebBeansConfigurationListener.class.isInstance(o) || o.getClass().getName().startsWith("org.apache.catalina.servlets.")) {
return;
}
final BeanManager bm = CDI.current().getBeanManager();
final AnnotatedType<?> annotatedType = bm.createAnnotatedType(o.getClass());
final InjectionTarget injectionTarget = bm.createInjectionTarget(annotatedType);
final CreationalContext<Object> creationalContext = bm.createCreationalContext(null);
injectionTarget.inject(o, creationalContext);
try {
injectionTarget.postConstruct(o);
} catch (final RuntimeException e) {
creationalContext.release();
throw e;
}
destroyables.put(o, () -> {
try {
injectionTarget.preDestroy(o);
} finally {
creationalContext.release();
}
});
}
use of javax.enterprise.inject.spi.InjectionTarget in project ovirt-engine by oVirt.
the class Injector method injectMembers.
/**
* This method will take an instance and will fulfill all its dependencies, which are members
* annotated with <code>@Inject</code>.
* @param instance unmanaged CDI bean, essentially a regular object which is not managed by
* the CDI container.
* @param <T> an unmanaged CDI instance with some members containing <code>@Inject</code> annotated
* members
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> T injectMembers(T instance) {
AnnotatedType type = CDI.current().getBeanManager().createAnnotatedType(instance.getClass());
InjectionTarget injectionTarget = CDI.current().getBeanManager().createInjectionTarget(type);
injectionTarget.inject(instance, CDI.current().getBeanManager().createCreationalContext(null));
injectionTarget.postConstruct(instance);
return instance;
}
use of javax.enterprise.inject.spi.InjectionTarget in project datanucleus-core by datanucleus.
the class CDIHandler method close.
public void close() {
if (!injectionTargets.isEmpty()) {
Set keys = new HashSet<>();
synchronized (injectionTargets) {
keys.addAll(injectionTargets.keySet());
for (Object key : keys) {
try {
InjectionTarget target = injectionTargets.get(key);
target.preDestroy(key);
target.dispose(key);
injectionTargets.remove(key);
} catch (Exception e) {
}
}
}
}
if (!creationalContexts.isEmpty()) {
Iterator<CreationalContext> ctxIter = creationalContexts.iterator();
while (ctxIter.hasNext()) {
CreationalContext ctx = ctxIter.next();
ctx.release();
ctxIter.remove();
}
}
}
Aggregations