use of javax.enterprise.context.spi.CreationalContext 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.context.spi.CreationalContext in project kie-wb-common by kiegroup.
the class PackageNameWhiteListLoaderTest method setUp.
@Before
public void setUp() throws Exception {
final SimpleFileSystemProvider fs = new SimpleFileSystemProvider();
// Bootstrap WELD container
weld = new Weld();
final BeanManager beanManager = weld.initialize().getBeanManager();
// Instantiate Paths used in tests for Path conversion
final Bean pathsBean = (Bean) beanManager.getBeans(Paths.class).iterator().next();
final CreationalContext cc = beanManager.createCreationalContext(pathsBean);
Paths paths = (Paths) beanManager.getReference(pathsBean, Paths.class, cc);
// Ensure URLs use the default:// scheme
fs.forceAsDefault();
tempFiles = new TempFiles();
final File tempFile = tempFiles.createTempFile("white-list");
final org.uberfire.java.nio.file.Path nioPackagePath = fs.getPath(tempFile.toURI());
pathToWhiteList = paths.convert(nioPackagePath);
loader = new PackageNameWhiteListLoader(packageNameSearchProvider, ioService);
}
use of javax.enterprise.context.spi.CreationalContext in project microservice_framework by CJSCommonPlatform.
the class SynchronousDirectAdapterCache method adapterFromContext.
private SynchronousDirectAdapter adapterFromContext(final String component) {
final Bean<?> bean = beanManager.getBeans(SynchronousDirectAdapter.class).stream().filter(b -> component.equals(b.getBeanClass().getAnnotation(DirectAdapter.class).value())).findAny().orElseThrow(() -> new IllegalArgumentException(format("Direct adapter for component %s not found", component)));
final CreationalContext ctx = beanManager.createCreationalContext(bean);
return (SynchronousDirectAdapter) beanManager.getReference(bean, SynchronousDirectAdapter.class, ctx);
}
use of javax.enterprise.context.spi.CreationalContext in project core by weld.
the class BeanManagerImpl method getInjectableReference.
/**
* Get a reference, registering the injection point used.
*
* @param injectionPoint the injection point to register
* @param resolvedBean the bean to get a reference to
* @param creationalContext the creationalContext
* @return the injectable reference
*/
public Object getInjectableReference(InjectionPoint injectionPoint, Bean<?> resolvedBean, CreationalContext<?> creationalContext) {
Preconditions.checkArgumentNotNull(resolvedBean, "resolvedBean");
Preconditions.checkArgumentNotNull(creationalContext, CREATIONAL_CONTEXT);
boolean registerInjectionPoint = isRegisterableInjectionPoint(injectionPoint);
boolean delegateInjectionPoint = injectionPoint != null && injectionPoint.isDelegate();
final ThreadLocalStackReference<InjectionPoint> stack = currentInjectionPoint.pushConditionally(injectionPoint, registerInjectionPoint);
try {
Type requestedType = null;
if (injectionPoint != null) {
requestedType = injectionPoint.getType();
}
if (clientProxyOptimization && injectionPoint != null && injectionPoint.getBean() != null) {
// For certain combinations of scopes, the container is permitted to optimize an injectable reference lookup
// This should also partially solve circular @PostConstruct invocation
CreationalContextImpl<?> weldCreationalContext = null;
Bean<?> bean = injectionPoint.getBean();
// Do not optimize for self injection
if (!bean.equals(resolvedBean)) {
if (creationalContext instanceof CreationalContextImpl) {
weldCreationalContext = (CreationalContextImpl<?>) creationalContext;
}
if (weldCreationalContext != null && Dependent.class.equals(bean.getScope()) && isNormalScope(resolvedBean.getScope())) {
bean = findNormalScopedDependant(weldCreationalContext);
}
if (InjectionPoints.isInjectableReferenceLookupOptimizationAllowed(bean, resolvedBean)) {
if (weldCreationalContext != null) {
final Object incompleteInstance = weldCreationalContext.getIncompleteInstance(resolvedBean);
if (incompleteInstance != null) {
return incompleteInstance;
}
}
Context context = internalGetContext(resolvedBean.getScope());
if (context != null) {
@SuppressWarnings({ "unchecked", "rawtypes" }) final Object existinInstance = context.get(Reflections.<Contextual>cast(resolvedBean));
if (existinInstance != null) {
return existinInstance;
}
}
}
}
}
return getReference(resolvedBean, requestedType, creationalContext, delegateInjectionPoint);
} finally {
stack.pop();
}
}
use of javax.enterprise.context.spi.CreationalContext in project core by weld.
the class SimpleInterceptorTest method testSimpleInterceptor.
@Test
public void testSimpleInterceptor() {
Bean bean = beanManager.getBeans(SimpleBeanImpl.class).iterator().next();
CreationalContext creationalContext = beanManager.createCreationalContext(bean);
SimpleBeanImpl simpleBean = (SimpleBeanImpl) bean.create(creationalContext);
String result = simpleBean.doSomething();
assert "decorated-Hello!-decorated".equals(result);
bean.destroy(simpleBean, creationalContext);
assert SimpleInterceptor.aroundInvokeCalled;
assert !SimpleInterceptor.postConstructCalled;
assert !SimpleInterceptor.preDestroyCalled;
assert TwoBindingsInterceptor.aroundInvokeCalled;
assert SimpleBeanImpl.postConstructCalled;
}
Aggregations