Search in sources :

Example 1 with LifecycleCallback$JAXB.writeLifecycleCallback

use of org.apache.openejb.jee.LifecycleCallback$JAXB.writeLifecycleCallback in project tomee by apache.

the class LegacyProcessor method process.

public static void process(final Class<?> clazz, final EnterpriseBean bean) {
    if (bean instanceof SessionBean) {
        final SessionBean sessionBean = (SessionBean) bean;
        if (sessionBean.getSessionType() == STATEFUL && SessionSynchronization.class.isAssignableFrom(clazz)) {
            try {
                sessionBean.getAfterBegin().add(new LifecycleCallback(clazz.getMethod("afterBegin")));
                sessionBean.getBeforeCompletion().add(new LifecycleCallback(clazz.getMethod("beforeCompletion")));
                sessionBean.getAfterCompletion().add(new LifecycleCallback(clazz.getMethod("afterCompletion", boolean.class)));
            } catch (final NoSuchMethodException e) {
            //Ignore, should never happen
            }
        }
        if (javax.ejb.SessionBean.class.isAssignableFrom(clazz)) {
            final ResourceEnvRef ref = new ResourceEnvRef("javax.ejb.SessionBean/sessionContext", SessionContext.class);
            final InjectionTarget target = new InjectionTarget();
            target.setInjectionTargetClass(clazz);
            target.setInjectionTargetName("sessionContext");
            ref.getInjectionTarget().add(target);
            sessionBean.getResourceEnvRef().add(ref);
        }
    }
    if (bean instanceof MessageDrivenBean) {
        final MessageDrivenBean messageDrivenBean = (MessageDrivenBean) bean;
        if (javax.ejb.MessageDrivenBean.class.isAssignableFrom(clazz)) {
            final ResourceEnvRef ref = new ResourceEnvRef("javax.ejb.MessageDrivenBean/messageDrivenContext", MessageDrivenContext.class);
            final InjectionTarget target = new InjectionTarget();
            target.setInjectionTargetClass(clazz);
            target.setInjectionTargetName("messageDrivenContext");
            ref.getInjectionTarget().add(target);
            messageDrivenBean.getResourceEnvRef().add(ref);
        }
    }
}
Also used : SessionSynchronization(javax.ejb.SessionSynchronization) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) InjectionTarget(org.apache.openejb.jee.InjectionTarget) LifecycleCallback(org.apache.openejb.jee.LifecycleCallback) SessionBean(org.apache.openejb.jee.SessionBean) ResourceEnvRef(org.apache.openejb.jee.ResourceEnvRef)

Example 2 with LifecycleCallback$JAXB.writeLifecycleCallback

use of org.apache.openejb.jee.LifecycleCallback$JAXB.writeLifecycleCallback in project tomee by apache.

the class CheckInvalidInterceptorTest method testDeclaringInterceptorClass.

/**
     * Should not get any failure message, as we explicitly configure the methods in the base class
     *
     * @return
     */
@Keys
public EjbJar testDeclaringInterceptorClass() {
    final EjbJar ejbJar = new EjbJar();
    final Interceptor subInterceptor = ejbJar.addInterceptor(new org.apache.openejb.jee.Interceptor(SubInterceptor.class));
    subInterceptor.getPostConstruct().add(new LifecycleCallback(BaseInterceptor.class.getName(), "interceptPostConstruct"));
    subInterceptor.getPreDestroy().add(new LifecycleCallback(BaseInterceptor.class.getName(), "interceptPreDestroy"));
    subInterceptor.getAroundInvoke().add(new org.apache.openejb.jee.AroundInvoke(BaseInterceptor.class.getName(), "interceptAroundInvoke"));
    subInterceptor.getAroundTimeout().add(new org.apache.openejb.jee.AroundTimeout(BaseInterceptor.class.getName(), "interceptAroundTimeout"));
    return ejbJar;
}
Also used : Interceptor(org.apache.openejb.jee.Interceptor) LifecycleCallback(org.apache.openejb.jee.LifecycleCallback) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar)

Example 3 with LifecycleCallback$JAXB.writeLifecycleCallback

use of org.apache.openejb.jee.LifecycleCallback$JAXB.writeLifecycleCallback 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

LifecycleCallback (org.apache.openejb.jee.LifecycleCallback)3 Interceptor (org.apache.openejb.jee.Interceptor)2 SessionBean (org.apache.openejb.jee.SessionBean)2 Method (java.lang.reflect.Method)1 SessionSynchronization (javax.ejb.SessionSynchronization)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 AroundInvoke (org.apache.openejb.jee.AroundInvoke)1 AroundTimeout (org.apache.openejb.jee.AroundTimeout)1 CallbackMethod (org.apache.openejb.jee.CallbackMethod)1 EjbJar (org.apache.openejb.jee.EjbJar)1 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)1 InitMethod (org.apache.openejb.jee.InitMethod)1 InjectionTarget (org.apache.openejb.jee.InjectionTarget)1 Invokable (org.apache.openejb.jee.Invokable)1 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)1 RemoveMethod (org.apache.openejb.jee.RemoveMethod)1 ResourceEnvRef (org.apache.openejb.jee.ResourceEnvRef)1 Session (org.apache.openejb.jee.Session)1 Timer (org.apache.openejb.jee.Timer)1 ClassFinder (org.apache.xbean.finder.ClassFinder)1