@Override public boolean isStatefulBean(final Class<?> clazz) { return BeanType.STATEFUL.equals(beans.get(clazz).getComponentType()); }
private boolean hasEjbAndIsNotAManagedBean(final Map<String, EJBRestServiceInfo> restEjbs, final String clazz) { return restEjbs.containsKey(clazz) && !BeanType.MANAGED.equals(restEjbs.get(clazz).context.getComponentType()); }
@Override public boolean isStatefulBean(final Class<?> clazz) { return BeanType.STATEFUL.equals(beans.get(clazz).getComponentType()); }
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"); } }
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"); } }
private static void eagerInitOfLocalBeanProxies(final Collection<BeanContext> beans, final ClassLoader classLoader) { for (final BeanContext deployment : beans) { if (deployment.isLocalbean() && !deployment.isDynamicallyImplemented()) { // init proxy eagerly otherwise deserialization of serialized object can't work final List<Class> interfaces = new ArrayList<>(2); interfaces.add(Serializable.class); interfaces.add(IntraVmProxy.class); final BeanType type = deployment.getComponentType(); if (BeanType.STATEFUL.equals(type) || BeanType.MANAGED.equals(type)) { interfaces.add(BeanContext.Removable.class); } try { LocalBeanProxyFactory.createProxy(deployment.getBeanClass(), classLoader, interfaces.toArray(new Class<?>[interfaces.size()])); } catch (final Exception e) { // no-op: as before } } } }
public static Object createHomeProxy(final BeanContext beanContext, final InterfaceType interfaceType, final List<Class> objectInterfaces, final Class mainInterface) { if (!interfaceType.isHome()) { throw new IllegalArgumentException("InterfaceType is not a Home type: " + interfaceType); } try { final EjbHomeProxyHandler handler = createHomeHandler(beanContext, interfaceType, objectInterfaces, mainInterface); final List<Class> proxyInterfaces = new ArrayList<Class>(2); final Class homeInterface = beanContext.getInterface(interfaceType); proxyInterfaces.add(homeInterface); proxyInterfaces.add(IntraVmProxy.class); if (BeanType.STATEFUL.equals(beanContext.getComponentType()) || BeanType.MANAGED.equals(beanContext.getComponentType())) { proxyInterfaces.add(BeanContext.Removable.class); } return ProxyManager.newProxyInstance(proxyInterfaces.toArray(new Class[proxyInterfaces.size()]), handler); } catch (final Exception e) { throw new OpenEJBRuntimeException("Can't create EJBHome stub" + e.getMessage(), e); } }
public static Object createHomeProxy(final BeanContext beanContext, final InterfaceType interfaceType, final List<Class> objectInterfaces, final Class mainInterface) { if (!interfaceType.isHome()) { throw new IllegalArgumentException("InterfaceType is not a Home type: " + interfaceType); } try { final EjbHomeProxyHandler handler = createHomeHandler(beanContext, interfaceType, objectInterfaces, mainInterface); final List<Class> proxyInterfaces = new ArrayList<Class>(2); final Class homeInterface = beanContext.getInterface(interfaceType); proxyInterfaces.add(homeInterface); proxyInterfaces.add(IntraVmProxy.class); if (BeanType.STATEFUL.equals(beanContext.getComponentType()) || BeanType.MANAGED.equals(beanContext.getComponentType())) { proxyInterfaces.add(BeanContext.Removable.class); } return ProxyManager.newProxyInstance(proxyInterfaces.toArray(new Class[proxyInterfaces.size()]), handler); } catch (final Exception e) { throw new OpenEJBRuntimeException("Can't create EJBHome stub" + e.getMessage(), e); } }
@Override public Object invoke(final Exchange exchange, final Object o) { // mainly a select the right invoker impl final ClassResourceInfo cri = (ClassResourceInfo) exchange.get("root.resource.class"); if (cri != null) { final String clazz = cri.getServiceClass().getName(); final EJBRestServiceInfo restServiceInfo = ejbs.get(clazz); if (restServiceInfo != null && !BeanType.MANAGED.equals(restServiceInfo.context.getComponentType())) { return ejbInvoker.invoke(exchange, o); } } return jaxrsInvoker.invoke(exchange, o); } }
private void initDefaultLock() { if (!BeanType.SINGLETON.equals(this.componentType)) { return; } final ArrayList<Class> classes = new ArrayList<Class>(); for (final Class local : businessRemotes) { classes.add(local); } for (final Class local : businessLocals) { classes.add(local); } classes.add(this.beanClass); for (final Class c : classes) { Lock lock = null; try { lock = (Lock) c.getAnnotation(Lock.class); this.getSingleton().lockType = lock.value(); if (logger.isDebugEnabled()) { logger.debug("Declared Lock for " + c.getName() + " is " + this.getSingleton().lockType); } } catch (final NullPointerException e) { //Ignore } catch (final Throwable e) { logger.warning("Failed to determine from: " + lock); } } if (logger.isDebugEnabled()) { logger.debug("Default Lock for " + this.beanClass.getName() + " is " + this.getSingleton().lockType); } }
private void initDefaultLock() { if (!BeanType.SINGLETON.equals(this.componentType)) { return; } final ArrayList<Class> classes = new ArrayList<Class>(); for (final Class local : businessRemotes) { classes.add(local); } for (final Class local : businessLocals) { classes.add(local); } classes.add(this.beanClass); for (final Class c : classes) { Lock lock = null; try { lock = (Lock) c.getAnnotation(Lock.class); this.getSingleton().lockType = lock.value(); if (logger.isDebugEnabled()) { logger.debug("Declared Lock for " + c.getName() + " is " + this.getSingleton().lockType); } } catch (final NullPointerException e) { //Ignore } catch (final Throwable e) { logger.warning("Failed to determine from: " + lock); } } if (logger.isDebugEnabled()) { logger.debug("Default Lock for " + this.beanClass.getName() + " is " + this.getSingleton().lockType); } }
public Object createProxy(final Object primaryKey, final Class mainInterface) { try { final InterfaceType objectInterfaceType = this.interfaceType.getCounterpart(); final BeanType type = getBeanContext().getComponentType(); final EjbObjectProxyHandler handler = newEjbObjectHandler(getBeanContext(), primaryKey, objectInterfaceType, getInterfaces(), mainInterface); // TODO Is it correct for ManagedBean injection via managed bean class? if ((InterfaceType.LOCALBEAN.equals(objectInterfaceType) || getBeanContext().getComponentType().equals(BeanType.MANAGED)) && !getBeanContext().isDynamicallyImplemented()) { return LocalBeanProxyFactory.constructProxy(handler.getBeanContext().get(BeanContext.ProxyClass.class).getProxy(), handler); } else { final List<Class> proxyInterfaces = new ArrayList<Class>(handler.getInterfaces().size() + 2); proxyInterfaces.addAll(handler.getInterfaces()); proxyInterfaces.add(Serializable.class); proxyInterfaces.add(IntraVmProxy.class); if (BeanType.STATEFUL.equals(type) || BeanType.MANAGED.equals(type)) { proxyInterfaces.add(BeanContext.Removable.class); } return ProxyManager.newProxyInstance(proxyInterfaces.toArray(new Class[proxyInterfaces.size()]), handler); } } catch (final IllegalAccessException iae) { throw new OpenEJBRuntimeException("Could not create IVM proxy for " + getInterfaces().get(0), iae); } }
public Object createProxy(final Object primaryKey, final Class mainInterface) { try { final InterfaceType objectInterfaceType = this.interfaceType.getCounterpart(); final BeanType type = getBeanContext().getComponentType(); final EjbObjectProxyHandler handler = newEjbObjectHandler(getBeanContext(), primaryKey, objectInterfaceType, getInterfaces(), mainInterface); // TODO Is it correct for ManagedBean injection via managed bean class? if ((InterfaceType.LOCALBEAN.equals(objectInterfaceType) || getBeanContext().getComponentType().equals(BeanType.MANAGED)) && !getBeanContext().isDynamicallyImplemented()) { return LocalBeanProxyFactory.constructProxy(handler.getBeanContext().get(BeanContext.ProxyClass.class).getProxy(), handler); } else { final List<Class> proxyInterfaces = new ArrayList<Class>(handler.getInterfaces().size() + 2); proxyInterfaces.addAll(handler.getInterfaces()); proxyInterfaces.add(Serializable.class); proxyInterfaces.add(IntraVmProxy.class); if (BeanType.STATEFUL.equals(type) || BeanType.MANAGED.equals(type)) { proxyInterfaces.add(BeanContext.Removable.class); } return ProxyManager.newProxyInstance(proxyInterfaces.toArray(new Class[proxyInterfaces.size()]), handler); } } catch (final IllegalAccessException iae) { throw new OpenEJBRuntimeException("Could not create IVM proxy for " + getInterfaces().get(0), iae); } }
public CdiEjbBean(final BeanContext beanContext, final WebBeansContext webBeansContext, final Class beanClass, final AnnotatedType<T> at, final InjectionTargetFactoryImpl<T> factory) { super(webBeansContext, toSessionType(beanContext.getComponentType()), at, new EJBBeanAttributesImpl<T>(beanContext, BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes(at).build()), beanClass, factory); this.beanContext = beanContext; beanContext.set(Bean.class, this); passivatingId = beanContext.getDeploymentID() + getReturnType().getName(); isDependentAndStateful = getScope().equals(Dependent.class) && BeanType.STATEFUL.equals(beanContext.getComponentType()); }
for (final Map.Entry<String, EJBRestServiceInfo> ejb : restEjbs.entrySet()) { final BeanContext ctx = ejb.getValue().context; if (BeanType.MANAGED.equals(ctx.getComponentType())) { deployPojo("", ejb.getValue().path, ctx.getBeanClass(), null, ctx.getClassLoader(), ctx.getInjections(), ctx.getJndiContext(),
passivatingId = bc.getDeploymentID() + getReturnType().getName(); final boolean stateful = BeanType.STATEFUL.equals(bc.getComponentType()); final boolean isDependent = getScope().equals(Dependent.class); isDependentAndStateful = isDependent && stateful;