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(); } }
public TargetBeanInstance(Bean<?> bean, Object instance) { this.instance = instance; this.instanceType = computeInstanceType(bean); }
public DecorationHelper(TargetBeanInstance originalInstance, Bean<?> bean, Class<T> proxyClassForDecorator, BeanManagerImpl beanManager, ContextualStore contextualStore, List<Decorator<?>> decorators) { this.originalInstance = Reflections.<T>cast(originalInstance.getInstance()); this.targetBeanInstance = originalInstance; this.beanManager = beanManager; this.contextualStore = contextualStore; this.decorators = new LinkedList<Decorator<?>>(decorators); this.proxyClassForDecorator = proxyClassForDecorator; this.bean = bean; this.instantiator = beanManager.getServices().get(ProxyInstantiator.class); counter = 0; }
private T createProxy(InjectionPoint injectionPoint, CreationalContext<?> creationalContext) { final T proxy = (System.getSecurityManager() == null) ? run() : AccessController.doPrivileged(this); TargetBeanInstance newTargetBeanInstance = new TargetBeanInstance(targetBeanInstance); Decorator<Object> decorator = Reflections.cast(decorators.get(counter++)); DecoratorProxyMethodHandler methodHandler = createMethodHandler(injectionPoint, creationalContext, decorator); newTargetBeanInstance.setInterceptorsHandler(methodHandler); ProxyFactory.setBeanInstance(beanManager.getContextId(), proxy, newTargetBeanInstance, bean); return proxy; }
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable { if (thisMethod == null) { BeanLogger.LOG.methodHandlerProcessingReturningBeanInstance(self.getClass()); if (beanInstance == null) { throw BeanLogger.LOG.beanInstanceNotSetOnProxy(getBean()); BeanLogger.LOG.methodHandlerProcessingCall(thisMethod, self.getClass()); if (thisMethod.getDeclaringClass().equals(TargetInstanceProxy.class)) { if (beanInstance == null) { BeanLogger.LOG.settingNewMethodHandler(args[0], self.getClass()); return new ProxyMethodHandler(contextId, new TargetBeanInstance(args[0]), getBean()); } else { if (beanInstance == null) {
@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).weld_setHandler(handler); } }
@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).weld_setHandler(new CombinedInterceptorAndDecoratorStackMethodHandler()); // Set method handler for private methods if necessary InterceptedSubclassFactory.setPrivateMethodHandler(instance); } } return instance; }
private T createProxy(InjectionPoint injectionPoint, CreationalContext<?> creationalContext) { final T proxy = (System.getSecurityManager() == null) ? run() : AccessController.doPrivileged(this); TargetBeanInstance newTargetBeanInstance = new TargetBeanInstance(targetBeanInstance); Decorator<Object> decorator = Reflections.cast(decorators.get(counter++)); DecoratorProxyMethodHandler methodHandler = createMethodHandler(injectionPoint, creationalContext, decorator); newTargetBeanInstance.setInterceptorsHandler(methodHandler); ProxyFactory.setBeanInstance(beanManager.getContextId(), proxy, newTargetBeanInstance, bean); return proxy; }
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable { if (thisMethod == null) { BeanLogger.LOG.methodHandlerProcessingReturningBeanInstance(self.getClass()); if (beanInstance == null) { throw BeanLogger.LOG.beanInstanceNotSetOnProxy(getBean()); BeanLogger.LOG.methodHandlerProcessingCall(thisMethod, self.getClass()); if (thisMethod.getDeclaringClass().equals(TargetInstanceProxy.class)) { if (beanInstance == null) { BeanLogger.LOG.settingNewMethodHandler(args[0], self.getClass()); return new ProxyMethodHandler(contextId, new TargetBeanInstance(args[0]), getBean()); } else { if (beanInstance == null) {
@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).weld_setHandler(handler); } }
@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).weld_setHandler(new CombinedInterceptorAndDecoratorStackMethodHandler()); // Set method handler for private methods if necessary InterceptedSubclassFactory.setPrivateMethodHandler(instance); } } return instance; }
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(); } }
public DecorationHelper(TargetBeanInstance originalInstance, Bean<?> bean, Class<T> proxyClassForDecorator, BeanManagerImpl beanManager, ContextualStore contextualStore, List<Decorator<?>> decorators) { this.originalInstance = Reflections.<T>cast(originalInstance.getInstance()); this.targetBeanInstance = originalInstance; this.beanManager = beanManager; this.contextualStore = contextualStore; this.decorators = new LinkedList<Decorator<?>>(decorators); this.proxyClassForDecorator = proxyClassForDecorator; this.bean = bean; this.instantiator = beanManager.getServices().get(ProxyInstantiator.class); counter = 0; }
private T createProxy(InjectionPoint injectionPoint, CreationalContext<?> creationalContext) { final T proxy = (System.getSecurityManager() == null) ? run() : AccessController.doPrivileged(this); TargetBeanInstance newTargetBeanInstance = new TargetBeanInstance(targetBeanInstance); Decorator<Object> decorator = Reflections.cast(decorators.get(counter++)); DecoratorProxyMethodHandler methodHandler = createMethodHandler(injectionPoint, creationalContext, decorator); newTargetBeanInstance.setInterceptorsHandler(methodHandler); ProxyFactory.setBeanInstance(beanManager.getContextId(), proxy, newTargetBeanInstance, bean); return proxy; }
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable { if (thisMethod == null) { BeanLogger.LOG.methodHandlerProcessingReturningBeanInstance(self.getClass()); if (beanInstance == null) { throw BeanLogger.LOG.beanInstanceNotSetOnProxy(getBean()); BeanLogger.LOG.methodHandlerProcessingCall(thisMethod, self.getClass()); if (thisMethod.getDeclaringClass().equals(TargetInstanceProxy.class)) { if (beanInstance == null) { BeanLogger.LOG.settingNewMethodHandler(args[0], self.getClass()); return new ProxyMethodHandler(contextId, new TargetBeanInstance(args[0]), getBean()); } else { if (beanInstance == null) {
@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).weld_setHandler(handler); } }
public TargetBeanInstance(Bean<?> bean, Object instance) { this.instance = instance; this.instanceType = computeInstanceType(bean); }
@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; }
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(); } }
public DecorationHelper(TargetBeanInstance originalInstance, Bean<?> bean, Class<T> proxyClassForDecorator, BeanManagerImpl beanManager, ContextualStore contextualStore, List<Decorator<?>> decorators) { this.originalInstance = Reflections.<T>cast(originalInstance.getInstance()); this.targetBeanInstance = originalInstance; this.beanManager = beanManager; this.contextualStore = contextualStore; this.decorators = new LinkedList<Decorator<?>>(decorators); this.proxyClassForDecorator = proxyClassForDecorator; this.bean = bean; this.instantiator = beanManager.getServices().get(ProxyInstantiator.class); counter = 0; }