use of org.jboss.weld.contexts.CreationalContextImpl in project Payara by payara.
the class JCDIServiceImpl method getAroundConstructInterceptorInstance.
private <T> T getAroundConstructInterceptorInstance(Interceptor<T> interceptor, CreationalContext<T> creationalContext) {
T instance = null;
if (creationalContext instanceof CreationalContextImpl<?>) {
CreationalContextImpl<T> weldContext = Reflections.cast(creationalContext);
@SuppressWarnings("unchecked") InterceptorImpl<T> interceptorImpl = (InterceptorImpl) interceptor;
InterceptorClassMetadata<T> interceptorClassMetadata = interceptorImpl.getInterceptorMetadata();
InterceptionContext interceptionContext = weldContext.getAroundConstructInterceptionContext();
instance = interceptionContext.getInterceptorInstance(interceptorClassMetadata);
}
return instance;
}
use of org.jboss.weld.contexts.CreationalContextImpl in project core by weld.
the class InterceptorApplyingInstantiator method newInstance.
@Override
public T newInstance(CreationalContext<T> ctx, BeanManagerImpl manager) {
InterceptionContext interceptionContext = null;
if (ctx instanceof CreationalContextImpl<?>) {
CreationalContextImpl<T> weldCtx = Reflections.cast(ctx);
interceptionContext = weldCtx.getAroundConstructInterceptionContext();
}
if (interceptionContext == null) {
// There is no interception context to reuse
interceptionContext = InterceptionContext.forNonConstructorInterception(interceptionModel, ctx, manager, annotatedType);
}
T instance = delegate().newInstance(ctx, manager);
applyInterceptors(instance, interceptionContext);
return instance;
}
use of org.jboss.weld.contexts.CreationalContextImpl 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();
}
}
Aggregations