@Override protected CdiEjbBean<A> createBean(final Class<A> beanClass, final boolean beanEnabled) { return new CdiEjbBean<A>(beanContext, webBeansContext, annotatedType); }
@Override public T create(final CreationalContext<T> creationalContext) { final T instance = bean.createEjb(creationalContext); if (owbProxy != null && SessionBeanType.STATEFUL.equals(bean.getEjbType())) { // we need to be able to remove OWB proxy to remove (statefuls for instance) bean.storeStatefulInstance(owbProxy, instance); } return instance; }
@Override public void destroy(final T instance, final CreationalContext<T> cc) { if (!SessionBeanType.STATEFUL.equals(bean.getEjbType())) { return; } bean.destroy(instance, cc); }
public void destroyComponentInstance(final T instance) { if (getScope() == null || Dependent.class == getScope()) { destroyStatefulSessionBeanInstance(instance, null); } else { destroyScopedStateful(instance, null); } }
public NewCdiEjbBean(final CdiEjbBean<T> that) { super(that.getBeanContext(), that.getWebBeansContext(), that.getBeanContext().getManagedClass(), that.getAnnotatedType(), new NewEjbInjectionTargetFactory<T>(that.getAnnotatedType(), that.getWebBeansContext(), that.getInjectionTarget())); this.id = that.getId() + "NewBean"; initInternals(); }
public CdiEjbBean(final BeanContext bc, final WebBeansContext webBeansContext, final Class beanClass, final AnnotatedType<T> at, final InjectionTargetFactoryImpl<T> factory, final BeanAttributes<T> attributes) { super(webBeansContext, toSessionType(bc.getComponentType()), at, new EJBBeanAttributesImpl<T>(bc, attributes), beanClass, factory); this.beanContext = bc; bc.set(Bean.class, this); passivatingId = bc.getDeploymentID() + getReturnType().getName(); final boolean isDependent = getScope().equals(Dependent.class); isDependentAndStateful = isDependent && stateful; if (webBeansContext.getBeanManagerImpl().isPassivatingScope(getScope()) && stateful) { if (!getBeanContext().isPassivable()) { throw new DefinitionException( getBeanContext().getBeanClass() + " is a not apssivation-capable @Stateful with a scope " + getScope().getSimpleName() + " which need passivation"); if (getAnnotatedType().isAnnotationPresent(Interceptor.class) || getAnnotatedType().isAnnotationPresent(Decorator.class)) { throw new DefinitionException("An EJB can't be an interceptor or a decorator: " + beanClass);
if (bean.isEnabled()) { observerMethods = new ObserverMethodsBuilder<T, InjectionTargetBean<T>>(webBeansContext, bean.getAnnotatedType()).defineObserverMethods(bean); } else { observerMethods = new HashSet<ObserverMethod<?>>(); final Set<ProducerMethodBean<?>> producerMethods = new ProducerMethodBeansBuilder(bean.getWebBeansContext(), bean.getAnnotatedType()).defineProducerMethods(bean); final Set<ProducerFieldBean<?>> producerFields = new ProducerFieldBeansBuilder(bean.getWebBeansContext(), bean.getAnnotatedType()).defineProducerFields(bean); beanManager.fireEvent(new GProcessSessionBean(Bean.class.cast(bean), annotatedType, bc.getEjbName(), bean.getEjbType())); webBeansUtil.inspectErrorStack("There are errors that are added by ProcessSessionBean event observers for managed beans. Look at logs for further details");
AbstractProducer.class.cast(cdiEjbBean).defineInterceptorStack(cdiEjbBean, cdiEjbBean.getAnnotatedType(), cdiEjbBean.getWebBeansContext()); bc.set(InterceptorResolutionService.BeanInterceptorInfo.class, InjectionTargetImpl.class.cast(cdiEjbBean.getInjectionTarget()).getInterceptorInfo()); cdiEjbBean.initInternals();
if (cdiEjbBean != null && !dynamicallyImplemented && CdiEjbBean.EjbInjectionTargetImpl.class.isInstance(cdiEjbBean.getInjectionTarget())) { rootInstance = CdiEjbBean.EjbInjectionTargetImpl.class.cast(cdiEjbBean.getInjectionTarget()).createNewPojo(creationalContext); } else { // not a cdi bean rootInstance = getManagedClass().newInstance(); cdiEjbBean.getInjectionTarget().postConstruct(beanInstance); final Class<?> proxyClass = Class.class.cast(Reflections.get(cdiEjbBean.getInjectionTarget(), "proxyClass")); if (proxyClass != null) { // means interception final InterceptorResolutionService.BeanInterceptorInfo interceptorInfo = cdiEjbBean.getBeanContext().get(InterceptorResolutionService.BeanInterceptorInfo.class); if (interceptorInfo.getDecorators() != null && !interceptorInfo.getDecorators().isEmpty()) { final InterceptorDecoratorProxyFactory pf = webBeansContext.getInterceptorDecoratorProxyFactory(); final Object decoratorInstance = decorator.create(CreationalContext.class.cast(creationalContext)); instances.put(decorator, decoratorInstance); beanInstance = pf.createProxyInstance(proxyClass, instance, new DecoratorHandler(interceptorInfo, instances, i - 1, instance, cdiEjbBean.getId()));
public static Method doResolveViewMethod(final Bean<?> component, final Method declaredMethod) { if (!(component instanceof CdiEjbBean)) { return declaredMethod; } final CdiEjbBean cdiEjbBean = (CdiEjbBean) component; final BeanContext beanContext = cdiEjbBean.getBeanContext(); for (final Class intface : beanContext.getBusinessLocalInterfaces()) { try { return intface.getMethod(declaredMethod.getName(), declaredMethod.getParameterTypes()); } catch (final NoSuchMethodException ignore) { // no-op } } return null; }
private static void validateScope(final CdiEjbBean<?> bean) { final Class<? extends Annotation> scope = bean.getScope(); final BeanType beanType = bean.getBeanContext().getComponentType(); if (BeanType.STATELESS.equals(beanType) && !Dependent.class.equals(scope)) { throw new WebBeansConfigurationException("@Stateless can only be @Dependent"); } if (BeanType.SINGLETON.equals(beanType) && !Dependent.class.equals(scope) && !ApplicationScoped.class.equals(scope)) { throw new WebBeansConfigurationException("@Singleton can only be @Dependent or @ApplicationScoped"); } }
return cdiEjbBean.createEjb(cc); final BeanContext beanContext = cdiEjbBean.getBeanContext(); final Provider provider = webBeansContext.getNormalScopeProxyFactory().getInstanceProvider(beanContext.getClassLoader(), cdiEjbBean);
final InjectionTargetImpl<?> injectionTarget = InjectionTargetImpl.class.cast(get(CdiEjbBean.class).getInjectionTarget()); final InterceptorResolutionService.BeanInterceptorInfo info = injectionTarget.getInterceptorInfo(); if (info == null) { final AnnotatedType annotatedType = cdiEjbBean.getAnnotatedType(); final AnnotationManager annotationManager = getWebBeansContext().getAnnotationManager(); final Collection<Annotation> annotations = new HashSet<>();
@Override public void dispose(final T instance) { ejb.destroyComponentInstance(instance); }
@Override public List<Method> getRemoveMethods() { // Should we delegate to super and merge both? if (beanContext.isLocalbean()) { return findRemove(beanContext.getBeanClass(), beanContext.getBeanClass()); } return findRemove(beanContext.getBeanClass(), beanContext.getBusinessLocalInterface()); }
@Override public T produce(final CreationalContext<T> creationalContext) { if (delegate == null) { return bean.createEjb(creationalContext); } return delegate.produce(creationalContext); }
@Override public Class<?> getBeanClass() { return bean.getBeanClass(); }
private void destroyScopedStateful(final T instance, final CreationalContext<T> cc) { try { instance.hashCode(); // force the instance to be created - otherwise we'll miss @PreDestroy for instance } catch (final NoSuchEJBException e) { InvocationHandler handler = null; if (LocalBeanProxyFactory.isProxy(instance.getClass())) { handler = LocalBeanProxyFactory.getInvocationHandler(instance); } else if (ProxyManager.isProxyClass(instance.getClass())) { handler = ProxyManager.getInvocationHandler(instance); } if (BaseEjbProxyHandler.class.isInstance(handler) && !BaseEjbProxyHandler.class.cast(handler).isValid()) { return; // already destroyed } // else log error logger.log(Level.FINE, "The stateful instance " + instance + " can't be removed since it was invalidated", e); return; } final Object ejbInstance = dependentSFSBToBeRemoved.remove(System.identityHashCode(instance)); if (ejbInstance != null) { destroyStatefulSessionBeanInstance((T) ejbInstance, cc); } else { destroyStatefulSessionBeanInstance(instance, cc); } }
public NewCdiEjbBean(final CdiEjbBean<T> that) { super(that.getBeanContext(), that.getWebBeansContext(), that.getBeanContext().getManagedClass(), that.getAnnotatedType(), new NewEjbInjectionTargetFactory<T>(that.getAnnotatedType(), that.getWebBeansContext(), that.getInjectionTarget()), new BeanAttributesImpl<T>(that)); this.id = that.getId() + "NewBean"; initInternals(); }
if (bean.isEnabled()) { observerMethods = new ObserverMethodsBuilder<T>(webBeansContext, bean.getAnnotatedType()).defineObserverMethods(bean); } else { observerMethods = new HashSet<>(); final Set<ProducerFieldBean<?>> producerFields = new ProducerFieldBeansBuilder(bean.getWebBeansContext(), bean.getAnnotatedType()).defineProducerFields(bean); final Set<ProducerMethodBean<?>> producerMethods = new ProducerMethodBeansBuilder(bean.getWebBeansContext(), bean.getAnnotatedType()).defineProducerMethods(bean, producerFields); final GProcessSessionBean event = new GProcessSessionBean(Bean.class.cast(bean), annotatedType, bc.getEjbName(), bean.getEjbType()); beanManager.fireEvent(event, true); event.setStarted();