Search in sources :

Example 1 with TargetBeanInstance

use of org.jboss.weld.bean.proxy.TargetBeanInstance in project core by weld.

the class ProxyClassConstructorInjectionPointWrapper method newInstance.

@Override
protected T newInstance(Object[] parameterValues) {
    // Once the instance is created, a method handler is required regardless of whether
    // an actual bean instance is known yet.
    final T instance = super.newInstance(parameterValues);
    if (decorator) {
        BeanInstance beanInstance = null;
        if (hasDelegateInjectionPoint()) {
            Object decoratorDelegate = parameterValues[delegateInjectionPointPosition];
            beanInstance = new TargetBeanInstance(decoratorDelegate);
        }
        ProxyFactory.setBeanInstance(contextId, instance, beanInstance, bean);
    } else {
        if (instance instanceof ProxyObject) {
            ((ProxyObject) instance).setHandler(new CombinedInterceptorAndDecoratorStackMethodHandler());
            // Set method handler for private methods if necessary
            InterceptedSubclassFactory.setPrivateMethodHandler(instance);
        }
    }
    return instance;
}
Also used : ProxyObject(org.jboss.weld.bean.proxy.ProxyObject) CombinedInterceptorAndDecoratorStackMethodHandler(org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler) TargetBeanInstance(org.jboss.weld.bean.proxy.TargetBeanInstance) BeanInstance(org.jboss.weld.bean.proxy.BeanInstance) ProxyObject(org.jboss.weld.bean.proxy.ProxyObject) TargetBeanInstance(org.jboss.weld.bean.proxy.TargetBeanInstance)

Example 2 with TargetBeanInstance

use of org.jboss.weld.bean.proxy.TargetBeanInstance in project core by weld.

the class Decorators method getOuterDelegate.

public static <T> T getOuterDelegate(Bean<T> bean, T instance, CreationalContext<T> creationalContext, Class<T> proxyClass, InjectionPoint originalInjectionPoint, BeanManagerImpl manager, List<Decorator<?>> decorators) {
    TargetBeanInstance beanInstance = new TargetBeanInstance(bean, instance);
    DecorationHelper<T> decorationHelper = new DecorationHelper<T>(beanInstance, bean, proxyClass, manager, manager.getServices().get(ContextualStore.class), decorators);
    DecorationHelper.push(decorationHelper);
    try {
        final T outerDelegate = decorationHelper.getNextDelegate(originalInjectionPoint, creationalContext);
        if (outerDelegate == null) {
            throw new WeldException(BeanLogger.LOG.proxyInstantiationFailed(bean));
        }
        return outerDelegate;
    } finally {
        DecorationHelper.pop();
    }
}
Also used : DecorationHelper(org.jboss.weld.bean.proxy.DecorationHelper) WeldException(org.jboss.weld.exceptions.WeldException) ContextualStore(org.jboss.weld.serialization.spi.ContextualStore) TargetBeanInstance(org.jboss.weld.bean.proxy.TargetBeanInstance)

Example 3 with TargetBeanInstance

use of org.jboss.weld.bean.proxy.TargetBeanInstance in project core by weld.

the class AbstractDecoratorApplyingInstantiator method getOuterDelegate.

protected T getOuterDelegate(T instance, CreationalContext<T> creationalContext, InjectionPoint originalInjectionPoint, BeanManagerImpl manager) {
    TargetBeanInstance beanInstance = new TargetBeanInstance(bean, instance);
    DecorationHelper<T> decorationHelper = new DecorationHelper<T>(beanInstance, bean, proxyClass, manager, manager.getServices().get(ContextualStore.class), decorators);
    DecorationHelper.push(decorationHelper);
    try {
        final T outerDelegate = decorationHelper.getNextDelegate(originalInjectionPoint, creationalContext);
        if (outerDelegate == null) {
            throw new WeldException(BeanLogger.LOG.proxyInstantiationFailed(this));
        }
        return outerDelegate;
    } finally {
        DecorationHelper.pop();
    }
}
Also used : DecorationHelper(org.jboss.weld.bean.proxy.DecorationHelper) WeldException(org.jboss.weld.exceptions.WeldException) ContextualStore(org.jboss.weld.serialization.spi.ContextualStore) TargetBeanInstance(org.jboss.weld.bean.proxy.TargetBeanInstance)

Example 4 with TargetBeanInstance

use of org.jboss.weld.bean.proxy.TargetBeanInstance in project core by weld.

the class DecoratorInjectionTarget method inject.

@Override
public void inject(T instance, CreationalContext<T> ctx) {
    super.inject(instance, ctx);
    if (accessibleField != null && instance instanceof DecoratorProxy) {
        // this code is only applicable if the delegate is injected into a field
        // as the proxy can't intercept the delegate when setting the field
        // we need to now read the delegate from the field
        // this is only needed for fields, as constructor and method injection are handed
        // at injection time
        Object delegate;
        try {
            delegate = accessibleField.get(instance);
        } catch (IllegalAccessException e) {
            throw UtilLogger.LOG.accessErrorOnField(accessibleField.getName(), accessibleField.getDeclaringClass(), e);
        }
        final ProxyMethodHandler handler = new ProxyMethodHandler(beanManager.getContextId(), new TargetBeanInstance(delegate), getBean());
        ((ProxyObject) instance).setHandler(handler);
    }
}
Also used : ProxyObject(org.jboss.weld.bean.proxy.ProxyObject) DecoratorProxy(org.jboss.weld.bean.proxy.DecoratorProxy) ProxyObject(org.jboss.weld.bean.proxy.ProxyObject) TargetBeanInstance(org.jboss.weld.bean.proxy.TargetBeanInstance) ProxyMethodHandler(org.jboss.weld.bean.proxy.ProxyMethodHandler)

Aggregations

TargetBeanInstance (org.jboss.weld.bean.proxy.TargetBeanInstance)4 DecorationHelper (org.jboss.weld.bean.proxy.DecorationHelper)2 ProxyObject (org.jboss.weld.bean.proxy.ProxyObject)2 WeldException (org.jboss.weld.exceptions.WeldException)2 ContextualStore (org.jboss.weld.serialization.spi.ContextualStore)2 BeanInstance (org.jboss.weld.bean.proxy.BeanInstance)1 CombinedInterceptorAndDecoratorStackMethodHandler (org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler)1 DecoratorProxy (org.jboss.weld.bean.proxy.DecoratorProxy)1 ProxyMethodHandler (org.jboss.weld.bean.proxy.ProxyMethodHandler)1