Search in sources :

Example 16 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class CdiPlugin method validateProduceMethods.

private static void validateProduceMethods(final CdiEjbBean<?> bean, final Set<ProducerMethodBean<?>> methods) {
    final BeanContext beanContext = bean.getBeanContext();
    if (beanContext.isLocalbean()) {
        return;
    }
    for (final ProducerMethodBean<?> m : methods) {
        final Method method = m.getCreatorMethod();
        final Method viewMethod = doResolveViewMethod(bean, method);
        if (viewMethod == null || beanContext.getBusinessRemoteInterfaces().contains(viewMethod.getDeclaringClass())) {
            throw new WebBeansConfigurationException("@Produces " + method + " not in a local ejb view of ejb " + beanContext.getEjbName());
        }
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) WebBeansConfigurationException(org.apache.webbeans.exception.WebBeansConfigurationException) ObserverMethod(javax.enterprise.inject.spi.ObserverMethod) Method(java.lang.reflect.Method) AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod)

Example 17 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class CdiPlugin method findBeanContext.

private static BeanContext findBeanContext(final WebBeansContext ctx, final Class<?> clazz) {
    final Map<Class<?>, BeanContext> beans = pluginBeans(ctx);
    final BeanContext b = beans.get(clazz);
    if (b != null) {
        return b;
    }
    for (final BeanContext bc : beans.values()) {
        if (bc.isLocalbean()) {
            // see isSessionBean() impl
            continue;
        }
        final CdiEjbBean<?> cdiEjbBean = bc.get(CdiEjbBean.class);
        if (cdiEjbBean == null) {
            continue;
        }
        for (final Class<?> itf : cdiEjbBean.getBusinessLocalInterfaces()) {
            if (itf.equals(clazz)) {
                return bc;
            }
        }
    }
    final WebBeansContext parentCtx = superContext(ctx);
    if (parentCtx != null) {
        return findBeanContext(parentCtx, clazz);
    }
    return null;
}
Also used : BeanContext(org.apache.openejb.BeanContext) WebBeansContext(org.apache.webbeans.config.WebBeansContext)

Example 18 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class CdiPlugin method doResolveViewMethod.

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
        }
    }
    for (final Class intface : beanContext.getBusinessRemoteInterfaces()) {
        try {
            return intface.getMethod(declaredMethod.getName(), declaredMethod.getParameterTypes());
        } catch (final NoSuchMethodException ignore) {
        // no-op
        }
    }
    return null;
}
Also used : BeanContext(org.apache.openejb.BeanContext)

Example 19 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class CdiResourceInjectionService method setAppContext.

public void setAppContext(final AppContext appModule, final Collection<BeanContext> ejbs) {
    compContexts.clear();
    ear = false;
    for (final BeanContext beanContext : appModule.getBeanContexts()) {
        if (!ear) {
            ear = beanContext.getEjbName().contains("ear-scoped-cdi-beans_");
        }
        if (beanContext.getBeanClass().equals(BeanContext.Comp.class) && (ejbs == null || ear || ejbs.contains(beanContext))) {
            compContexts.add(beanContext);
        }
    }
    this.appCtx = appModule;
}
Also used : BeanContext(org.apache.openejb.BeanContext)

Example 20 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class CdiResourceInjectionService method getResourceReference.

@Override
public <X, T extends Annotation> X getResourceReference(final ResourceReference<X, T> resourceReference) {
    final Class<X> type = resourceReference.getResourceType();
    final String name = resourceReference.getJndiName();
    try {
        return type.cast(new InitialContext().lookup(name));
    } catch (final NamingException e) {
    // no-op: try next
    }
    final String noJavaPrefix = name.replace("java:", "");
    for (final BeanContext beanContext : compContexts) {
        try {
            return type.cast(beanContext.getJndiContext().lookup(noJavaPrefix));
        } catch (final NamingException e1) {
        // fine for now
        }
    }
    if (appCtx != null) {
        // depending envrt bindings can be missing from InitialContext (embedded for instance)
        for (final WebContext w : appCtx.getWebContexts()) {
            final Object instance = w.getBindings().get(noJavaPrefix);
            if (instance != null) {
                if (Reference.class.isInstance(instance)) {
                    try {
                        return type.cast(Reference.class.cast(instance).getObject());
                    } catch (final NamingException e) {
                    // no-op: try next
                    }
                }
                if (type.isInstance(instance)) {
                    return type.cast(instance);
                }
            // else a javax.naming.Reference we don't handle yet surely
            }
        }
    }
    return null;
}
Also used : BeanContext(org.apache.openejb.BeanContext) WebContext(org.apache.openejb.core.WebContext) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Aggregations

BeanContext (org.apache.openejb.BeanContext)198 OpenEJBException (org.apache.openejb.OpenEJBException)40 ThreadContext (org.apache.openejb.core.ThreadContext)40 Method (java.lang.reflect.Method)38 ContainerSystem (org.apache.openejb.spi.ContainerSystem)28 ArrayList (java.util.ArrayList)27 AppContext (org.apache.openejb.AppContext)26 TransactionPolicy (org.apache.openejb.core.transaction.TransactionPolicy)26 NamingException (javax.naming.NamingException)24 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)23 Context (javax.naming.Context)22 ApplicationException (org.apache.openejb.ApplicationException)20 HashMap (java.util.HashMap)19 EJBLocalObject (javax.ejb.EJBLocalObject)18 EJBObject (javax.ejb.EJBObject)18 SystemException (org.apache.openejb.SystemException)18 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)17 ModuleContext (org.apache.openejb.ModuleContext)16 EjbTransactionUtil.createTransactionPolicy (org.apache.openejb.core.transaction.EjbTransactionUtil.createTransactionPolicy)16 FinderException (javax.ejb.FinderException)14