@Override public T newInstance(CreationalContext<T> ctx, BeanManagerImpl manager) { try { T instance = AccessController.doPrivileged(NewInstanceAction.of(proxyClass)); if (!bean.getScope().equals(Dependent.class)) { ctx.push(instance); } ProxyFactory.setBeanInstance( bean.getBeanManager().getContextId(), instance, createEnterpriseTargetBeanInstance(), bean); return instance; } catch (PrivilegedActionException e) { if (e.getCause() instanceof InstantiationException) { throw new WeldException(BeanLogger.LOG.proxyInstantiationFailed(this), e.getCause()); } else if (e.getCause() instanceof IllegalAccessException) { throw new WeldException( BeanLogger.LOG.proxyInstantiationBeanAccessFailed(this), e.getCause()); } else { throw new WeldException(e.getCause()); } } catch (Exception e) { throw BeanLogger.LOG.ejbNotFound(proxyClass, e); } }
protected T applyDecorators( T instance, CreationalContext<T> creationalContext, InjectionPoint originalInjectionPoint) { TargetBeanInstance beanInstance = new TargetBeanInstance(this, instance); ProxyFactory<T> proxyFactory = new ProxyFactory<T>(getType(), getTypes(), this); DecorationHelper<T> decorationHelper = new DecorationHelper<T>( beanInstance, this, proxyFactory.getProxyClass(), beanManager, getServices().get(ContextualStore.class), decorators); DecorationHelper.getHelperStack().push(decorationHelper); final T outerDelegate = decorationHelper.getNextDelegate(originalInjectionPoint, creationalContext); DecorationHelper.getHelperStack().pop(); if (outerDelegate == null) { throw new WeldException(PROXY_INSTANTIATION_FAILED, this); } CombinedInterceptorAndDecoratorStackMethodHandler wrapperMethodHandler = (CombinedInterceptorAndDecoratorStackMethodHandler) ((ProxyObject) instance).getHandler(); wrapperMethodHandler.setOuterDecorator(outerDelegate); return instance; }