Search in sources :

Example 41 with EnterpriseBean

use of org.apache.openejb.jee.EnterpriseBean in project tomee by apache.

the class LegacyProcessor method deploy.

@Override
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final ClassLoader classLoader = ejbModule.getClassLoader();
        for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
            if (bean.getEjbClass() == null) {
                continue;
            }
            try {
                final Class<?> clazz = classLoader.loadClass(bean.getEjbClass());
                process(clazz, bean);
            } catch (final ClassNotFoundException e) {
            // skip, we'll get this in validation
            }
        }
    }
    return appModule;
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean)

Example 42 with EnterpriseBean

use of org.apache.openejb.jee.EnterpriseBean in project tomee by apache.

the class LinkBuiltInTypes method deploy.

@Override
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    for (final ClientModule module : appModule.getClientModules()) {
        final JndiConsumer consumer = module.getApplicationClient();
        if (consumer == null) {
            continue;
        }
        link(consumer);
    }
    for (final WebModule module : appModule.getWebModules()) {
        final JndiConsumer consumer = module.getWebApp();
        if (consumer == null) {
            continue;
        }
        link(consumer);
    }
    for (final EjbModule module : appModule.getEjbModules()) {
        final EjbJar ejbJar = module.getEjbJar();
        if (ejbJar == null) {
            continue;
        }
        for (final EnterpriseBean consumer : ejbJar.getEnterpriseBeans()) {
            link(consumer);
        }
    }
    return appModule;
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) JndiConsumer(org.apache.openejb.jee.JndiConsumer) EjbJar(org.apache.openejb.jee.EjbJar)

Example 43 with EnterpriseBean

use of org.apache.openejb.jee.EnterpriseBean in project tomee by apache.

the class FinderFactory method ensureMinimalClasses.

public static Class<?>[] ensureMinimalClasses(final DeploymentModule module) {
    final Collection<Class<?>> finderClasses = new HashSet<>();
    if (EjbModule.class.isInstance(module)) {
        final EjbModule ejb = EjbModule.class.cast(module);
        final EnterpriseBean[] enterpriseBeans = ejb.getEjbJar().getEnterpriseBeans();
        ClassLoader classLoader = ejb.getClassLoader();
        if (classLoader == null) {
            classLoader = Thread.currentThread().getContextClassLoader();
        }
        for (final EnterpriseBean bean : enterpriseBeans) {
            final String name;
            if (SessionBean.class.isInstance(bean)) {
                final SessionBean sessionBean = SessionBean.class.cast(bean);
                if (sessionBean.getProxy() == null) {
                    name = sessionBean.getEjbClass();
                } else {
                    name = sessionBean.getProxy();
                }
            } else {
                name = bean.getEjbClass();
            }
            try {
                final Class<?> clazz = classLoader.loadClass(name);
                finderClasses.addAll(ancestors(clazz));
            } catch (final ClassNotFoundException e) {
            // no-op
            }
        }
        if (ejb.getWebservices() != null) {
            for (final WebserviceDescription webservice : ejb.getWebservices().getWebserviceDescription()) {
                for (final PortComponent port : webservice.getPortComponent()) {
                    if (port.getHandlerChains() == null) {
                        continue;
                    }
                    for (final HandlerChain handlerChain : port.getHandlerChains().getHandlerChain()) {
                        for (final Handler handler : handlerChain.getHandler()) {
                            if (handler.getHandlerClass() != null) {
                                try {
                                    finderClasses.addAll(ancestors(classLoader.loadClass(handler.getHandlerClass())));
                                } catch (final ClassNotFoundException e) {
                                // no-op
                                }
                            }
                        }
                    }
                }
            }
        }
        for (final org.apache.openejb.jee.Interceptor interceptor : ejb.getEjbJar().getInterceptors()) {
            try {
                finderClasses.addAll(ancestors(classLoader.loadClass(interceptor.getInterceptorClass())));
            } catch (final ClassNotFoundException e) {
            // no-op
            }
        }
        final Beans beans = ejb.getBeans();
        if (beans != null && ejb.getEjbJar() != null) {
            for (final List<String> managedClasses : beans.getManagedClasses().values()) {
                for (final String name : managedClasses) {
                    try {
                        finderClasses.addAll(ancestors(classLoader.loadClass(name)));
                    } catch (final ClassNotFoundException e) {
                    // no-op
                    }
                }
            }
            for (final String name : beans.getInterceptors()) {
                try {
                    finderClasses.addAll(ancestors(classLoader.loadClass(name)));
                } catch (final ClassNotFoundException e) {
                // no-op
                }
            }
            for (final String name : beans.getAlternativeClasses()) {
                try {
                    finderClasses.addAll(ancestors(classLoader.loadClass(name)));
                } catch (final ClassNotFoundException e) {
                // no-op
                }
            }
            for (final String name : beans.getDecorators()) {
                try {
                    finderClasses.addAll(ancestors(classLoader.loadClass(name)));
                } catch (final ClassNotFoundException e) {
                // no-op
                }
            }
        }
    } else if (WebModule.class.isInstance(module)) {
        final WebModule web = WebModule.class.cast(module);
        final ClassLoader classLoader = web.getClassLoader();
        if (web.getWebApp() != null) {
            for (final Servlet s : web.getWebApp().getServlet()) {
                final String servletClass = s.getServletClass();
                if (servletClass == null) {
                    continue;
                }
                try {
                    finderClasses.addAll(ancestors(classLoader.loadClass(servletClass)));
                } catch (final ClassNotFoundException e) {
                // no-op
                }
            }
            for (final String s : web.getRestClasses()) {
                try {
                    finderClasses.addAll(ancestors(classLoader.loadClass(s)));
                } catch (final ClassNotFoundException e) {
                // no-op
                }
            }
            for (final String s : web.getEjbWebServices()) {
                try {
                    finderClasses.addAll(ancestors(classLoader.loadClass(s)));
                } catch (final ClassNotFoundException e) {
                // no-op
                }
            }
        }
    }
    return finderClasses.toArray(new Class<?>[finderClasses.size()]);
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) PortComponent(org.apache.openejb.jee.PortComponent) Handler(org.apache.openejb.jee.Handler) SessionBean(org.apache.openejb.jee.SessionBean) HandlerChain(org.apache.openejb.jee.HandlerChain) Beans(org.apache.openejb.jee.Beans) WebserviceDescription(org.apache.openejb.jee.WebserviceDescription) Servlet(org.apache.openejb.jee.Servlet) HashSet(java.util.HashSet)

Example 44 with EnterpriseBean

use of org.apache.openejb.jee.EnterpriseBean in project tomee by apache.

the class StatefulInterceptorTest method buildTestApp.

public EjbModule buildTestApp() {
    final EjbJar ejbJar = new EjbJar();
    final AssemblyDescriptor ad = ejbJar.getAssemblyDescriptor();
    final EnterpriseBean bean = ejbJar.addEnterpriseBean(new StatefulBean(TargetBean.class));
    Interceptor interceptor;
    interceptor = ejbJar.addInterceptor(new Interceptor(ClassInterceptor.class));
    ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
    interceptor = ejbJar.addInterceptor(new Interceptor(DefaultInterceptor.class));
    ad.addInterceptorBinding(new InterceptorBinding("*", interceptor));
    interceptor = ejbJar.addInterceptor(new Interceptor(EchoMethodInterceptor.class));
    final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
    binding.setMethod(new NamedMethod("echo"));
    return new EjbModule(this.getClass().getClassLoader(), this.getClass().getSimpleName(), "test", ejbJar, null);
}
Also used : InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) StatefulBean(org.apache.openejb.jee.StatefulBean) EjbModule(org.apache.openejb.config.EjbModule) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) NamedMethod(org.apache.openejb.jee.NamedMethod) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar)

Example 45 with EnterpriseBean

use of org.apache.openejb.jee.EnterpriseBean in project tomee by apache.

the class CheckCallbacks method validate.

public void validate(final EjbModule module) {
    for (final EnterpriseBean bean : module.getEjbJar().getEnterpriseBeans()) {
        Class ejbClass = null;
        try {
            ejbClass = loadClass(bean.getEjbClass());
        } catch (final OpenEJBException e) {
            continue;
        }
        if (bean instanceof Invokable) {
            final Invokable invokable = (Invokable) bean;
            for (final AroundInvoke aroundInvoke : invokable.getAroundInvoke()) {
                checkAroundInvoke(ejbClass, aroundInvoke, bean.getEjbName());
            }
            for (final AroundTimeout aroundTimeout : invokable.getAroundTimeout()) {
                checkAroundTimeout(ejbClass, aroundTimeout, bean.getEjbName());
            }
        }
        for (final LifecycleCallback callback : bean.getPostConstruct()) {
            checkCallback(ejbClass, "PostConstruct", callback, bean);
        }
        for (final LifecycleCallback callback : bean.getPreDestroy()) {
            checkCallback(ejbClass, "PreDestroy", callback, bean);
        }
        final ClassFinder finder = new ClassFinder(ejbClass);
        if (bean instanceof Session) {
            final SessionBean session = (SessionBean) bean;
            if (session.getSessionType() == SessionType.STATEFUL) {
                for (final LifecycleCallback callback : session.getPrePassivate()) {
                    checkCallback(ejbClass, "PrePassivate", callback, bean);
                }
                for (final LifecycleCallback callback : session.getPostActivate()) {
                    checkCallback(ejbClass, "PostActivate", callback, bean);
                }
                checkSessionSynchronization(ejbClass, session);
                for (final LifecycleCallback callback : session.getAfterBegin()) {
                    checkCallback(ejbClass, "AfterBegin", callback, bean);
                }
                for (final LifecycleCallback callback : session.getBeforeCompletion()) {
                    checkCallback(ejbClass, "BeforeCompletion", callback, bean);
                }
                for (final LifecycleCallback callback : session.getAfterCompletion()) {
                    checkCallback(ejbClass, "AfterCompletion", callback, bean, boolean.class);
                }
                for (final AroundTimeout aroundTimeout : session.getAroundTimeout()) {
                    ignoredMethodAnnotation("AroundTimeout", bean, bean.getEjbClass(), aroundTimeout.getMethodName(), SessionType.STATEFUL.getName());
                }
                for (final Timer timer : session.getTimer()) {
                    ignoredMethodAnnotation("Schedule/Schedules", bean, bean.getEjbClass(), timer.getTimeoutMethod().getMethodName(), SessionType.STATEFUL.getName());
                }
            } else {
                for (final LifecycleCallback callback : session.getAfterBegin()) {
                    ignoredMethodAnnotation("AfterBegin", bean, bean.getEjbClass(), callback.getMethodName(), session.getSessionType().getName());
                }
                for (final LifecycleCallback callback : session.getBeforeCompletion()) {
                    ignoredMethodAnnotation("BeforeCompletion", bean, bean.getEjbClass(), callback.getMethodName(), session.getSessionType().getName());
                }
                for (final LifecycleCallback callback : session.getAfterCompletion()) {
                    ignoredMethodAnnotation("AfterCompletion", bean, bean.getEjbClass(), callback.getMethodName(), session.getSessionType().getName());
                }
                for (final LifecycleCallback callback : session.getPrePassivate()) {
                    ignoredMethodAnnotation("PrePassivate", bean, bean.getEjbClass(), callback.getMethodName(), session.getSessionType().getName());
                }
                for (final LifecycleCallback callback : session.getPostActivate()) {
                    ignoredMethodAnnotation("PostActivate", bean, bean.getEjbClass(), callback.getMethodName(), session.getSessionType().getName());
                }
                for (final RemoveMethod method : session.getRemoveMethod()) {
                    ignoredMethodAnnotation("Remove", bean, bean.getEjbClass(), method.getBeanMethod().getMethodName(), session.getSessionType().getName());
                }
                for (final InitMethod method : session.getInitMethod()) {
                    ignoredMethodAnnotation("Init", bean, bean.getEjbClass(), method.getBeanMethod().getMethodName(), session.getSessionType().getName());
                }
            }
        } else {
            for (final Method method : finder.findAnnotatedMethods(PrePassivate.class)) {
                ignoredMethodAnnotation("PrePassivate", bean, bean.getEjbClass(), method.getName(), bean.getClass().getSimpleName());
            }
            for (final Method method : finder.findAnnotatedMethods(PostActivate.class)) {
                ignoredMethodAnnotation("PostActivate", bean, bean.getEjbClass(), method.getName(), bean.getClass().getSimpleName());
            }
            for (final Method method : finder.findAnnotatedMethods(Remove.class)) {
                ignoredMethodAnnotation("Remove", bean, bean.getEjbClass(), method.getName(), bean.getClass().getSimpleName());
            }
            for (final Method method : finder.findAnnotatedMethods(Init.class)) {
                ignoredMethodAnnotation("Init", bean, bean.getEjbClass(), method.getName(), bean.getClass().getSimpleName());
            }
            for (final Method method : finder.findAnnotatedMethods(AfterBegin.class)) {
                ignoredMethodAnnotation("AfterBegin", bean, bean.getEjbClass(), method.getName(), bean.getClass().getSimpleName());
            }
            for (final Method method : finder.findAnnotatedMethods(BeforeCompletion.class)) {
                ignoredMethodAnnotation("BeforeCompletion", bean, bean.getEjbClass(), method.getName(), bean.getClass().getSimpleName());
            }
            for (final Method method : finder.findAnnotatedMethods(AfterCompletion.class)) {
                ignoredMethodAnnotation("AfterCompletion", bean, bean.getEjbClass(), method.getName(), bean.getClass().getSimpleName());
            }
        }
    //            if (bean instanceof TimerConsumer) {
    //                TimerConsumer timerConsumer = (TimerConsumer) bean;
    //                checkTimeOut(ejbClass, timerConsumer.getTimeoutMethod(), bean);
    //
    //                List<Method> timeoutMethods = finder.findAnnotatedMethods(Timeout.class);
    //                if (timeoutMethods.size() > 1) {
    //                    fail(timerConsumer.getTimerConsumerName(), "timeout.tooManyMethods", timeoutMethods.size(), Join.join(",", timeoutMethods));
    //                }
    //
    //                for(Timer timer : ((TimerConsumer) bean).getTimer()) {
    //                    checkTimeOut(ejbClass, timer.getTimeoutMethod(), bean);
    //                }
    //            }
    }
    for (final Interceptor interceptor : module.getEjbJar().getInterceptors()) {
        Class interceptorClass = null;
        try {
            interceptorClass = loadClass(interceptor.getInterceptorClass());
        } catch (final OpenEJBException e) {
            continue;
        }
        for (final AroundInvoke aroundInvoke : interceptor.getAroundInvoke()) {
            checkAroundInvoke(interceptorClass, aroundInvoke, "Interceptor");
        }
        for (final AroundTimeout aroundTimeout : interceptor.getAroundTimeout()) {
            checkAroundTimeout(interceptorClass, aroundTimeout, "Interceptor");
        }
        for (final LifecycleCallback callback : interceptor.getPostConstruct()) {
            checkCallback(interceptorClass, "PostConstruct", callback, interceptor);
        }
        for (final LifecycleCallback callback : interceptor.getPreDestroy()) {
            checkCallback(interceptorClass, "PreDestroy", callback, interceptor);
        }
        for (final LifecycleCallback callback : interceptor.getPrePassivate()) {
            checkCallback(interceptorClass, "PrePassivate", callback, interceptor);
        }
        for (final LifecycleCallback callback : interceptor.getPostActivate()) {
            checkCallback(interceptorClass, "PostActivate", callback, interceptor);
        }
        for (final LifecycleCallback callback : interceptor.getAfterBegin()) {
            checkCallback(interceptorClass, "AfterBegin", callback, interceptor);
        }
        for (final LifecycleCallback callback : interceptor.getBeforeCompletion()) {
            checkCallback(interceptorClass, "BeforeCompletion", callback, interceptor);
        }
        for (final LifecycleCallback callback : interceptor.getAfterCompletion()) {
            checkCallback(interceptorClass, "AfterCompletion", callback, interceptor);
        }
    }
}
Also used : InitMethod(org.apache.openejb.jee.InitMethod) OpenEJBException(org.apache.openejb.OpenEJBException) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) AroundTimeout(org.apache.openejb.jee.AroundTimeout) RemoveMethod(org.apache.openejb.jee.RemoveMethod) Method(java.lang.reflect.Method) InitMethod(org.apache.openejb.jee.InitMethod) CallbackMethod(org.apache.openejb.jee.CallbackMethod) SessionBean(org.apache.openejb.jee.SessionBean) Timer(org.apache.openejb.jee.Timer) Invokable(org.apache.openejb.jee.Invokable) ClassFinder(org.apache.xbean.finder.ClassFinder) RemoveMethod(org.apache.openejb.jee.RemoveMethod) LifecycleCallback(org.apache.openejb.jee.LifecycleCallback) AroundInvoke(org.apache.openejb.jee.AroundInvoke) Interceptor(org.apache.openejb.jee.Interceptor) Session(org.apache.openejb.jee.Session)

Aggregations

EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)46 EjbJar (org.apache.openejb.jee.EjbJar)19 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)16 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)14 SessionBean (org.apache.openejb.jee.SessionBean)12 ArrayList (java.util.ArrayList)9 EjbModule (org.apache.openejb.config.EjbModule)9 HashMap (java.util.HashMap)8 OpenEJBException (org.apache.openejb.OpenEJBException)7 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)7 Map (java.util.Map)6 AssemblyDescriptor (org.apache.openejb.jee.AssemblyDescriptor)6 Interceptor (org.apache.openejb.jee.Interceptor)6 List (java.util.List)5 Properties (java.util.Properties)5 EntityBean (org.apache.openejb.jee.EntityBean)5 InterceptorBinding (org.apache.openejb.jee.InterceptorBinding)5 ResourceLink (org.apache.openejb.jee.oejb3.ResourceLink)5 Resources (org.apache.openejb.config.sys.Resources)4 JndiConsumer (org.apache.openejb.jee.JndiConsumer)4