protected void registerOuterDecorator(ProxyObject instance, T outerDelegate) { CombinedInterceptorAndDecoratorStackMethodHandler wrapperMethodHandler = (CombinedInterceptorAndDecoratorStackMethodHandler) instance.getHandler(); wrapperMethodHandler.setOuterDecorator(outerDelegate); }
protected T applyInterceptors(T instance, InterceptionContext interceptionContext) { try { InterceptorMethodHandler methodHandler = new InterceptorMethodHandler(interceptionContext); CombinedInterceptorAndDecoratorStackMethodHandler wrapperMethodHandler = (CombinedInterceptorAndDecoratorStackMethodHandler) ((ProxyObject) instance).getHandler(); wrapperMethodHandler.setInterceptorMethodHandler(methodHandler); } catch (Exception e) { throw new DeploymentException(e); } return instance; }
@Override public T produce(CreationalContext<T> ctx) { T result = super.produce(ctx); if (result instanceof ProxyObject) { // if decorators are applied, use SessionBeanViewMethodHandler ProxyObject proxy = (ProxyObject) result; proxy.setHandler(new SessionBeanViewMethodHandler(bean.getTypes(), (CombinedInterceptorAndDecoratorStackMethodHandler) proxy.getHandler())); } return result; }
@Override public void destroy(T instance) { Preconditions.checkNotNull(instance); // Attempt to destroy instance which is either a client proxy or a dependent session bean proxy if (instance instanceof ProxyObject) { ProxyObject proxy = (ProxyObject) instance; if (proxy.getHandler() instanceof ProxyMethodHandler) { ProxyMethodHandler handler = (ProxyMethodHandler) proxy.getHandler(); Bean<?> bean = handler.getBean(); if (instance instanceof EnterpriseBeanInstance && Dependent.class.equals(bean.getScope())) { // Destroy internal reference to a dependent session bean destroyDependentInstance(instance); return; } else { // Destroy contextual instance of a normal-scoped bean Context context = getBeanManager().getContext(bean.getScope()); if (context instanceof AlterableContext) { AlterableContext alterableContext = (AlterableContext) context; alterableContext.destroy(bean); return; } else { throw BeanLogger.LOG.destroyUnsupported(context); } } } } // Attempt to destroy dependent instance which is neither a client proxy nor a dependent session bean proxy destroyDependentInstance(instance); }