Search in sources :

Example 1 with CreationalContextImpl

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;
}
Also used : InterceptionContext(org.jboss.weld.interceptor.proxy.InterceptionContext) CreationalContextImpl(org.jboss.weld.contexts.CreationalContextImpl) InterceptorImpl(org.jboss.weld.bean.InterceptorImpl)

Example 2 with CreationalContextImpl

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;
}
Also used : InterceptionContext(org.jboss.weld.interceptor.proxy.InterceptionContext) CreationalContextImpl(org.jboss.weld.contexts.CreationalContextImpl)

Example 3 with CreationalContextImpl

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();
    }
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) WeldCreationalContext(org.jboss.weld.contexts.WeldCreationalContext) Context(javax.enterprise.context.spi.Context) SlimAnnotatedType(org.jboss.weld.annotated.slim.SlimAnnotatedType) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) Type(java.lang.reflect.Type) EnhancedAnnotatedType(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType) AnnotatedTypeValidator.validateAnnotatedType(org.jboss.weld.annotated.AnnotatedTypeValidator.validateAnnotatedType) InterceptionType(javax.enterprise.inject.spi.InterceptionType) CurrentInjectionPoint(org.jboss.weld.injection.CurrentInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) EmptyInjectionPoint(org.jboss.weld.injection.EmptyInjectionPoint) ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) CreationalContextImpl(org.jboss.weld.contexts.CreationalContextImpl)

Aggregations

CreationalContextImpl (org.jboss.weld.contexts.CreationalContextImpl)3 InterceptionContext (org.jboss.weld.interceptor.proxy.InterceptionContext)2 Type (java.lang.reflect.Type)1 Context (javax.enterprise.context.spi.Context)1 CreationalContext (javax.enterprise.context.spi.CreationalContext)1 AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 InterceptionType (javax.enterprise.inject.spi.InterceptionType)1 ProcessInjectionPoint (javax.enterprise.inject.spi.ProcessInjectionPoint)1 AnnotatedTypeValidator.validateAnnotatedType (org.jboss.weld.annotated.AnnotatedTypeValidator.validateAnnotatedType)1 EnhancedAnnotatedType (org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType)1 SlimAnnotatedType (org.jboss.weld.annotated.slim.SlimAnnotatedType)1 InterceptorImpl (org.jboss.weld.bean.InterceptorImpl)1 WeldCreationalContext (org.jboss.weld.contexts.WeldCreationalContext)1 CurrentInjectionPoint (org.jboss.weld.injection.CurrentInjectionPoint)1 EmptyInjectionPoint (org.jboss.weld.injection.EmptyInjectionPoint)1