Search in sources :

Example 1 with SessionBean$JAXB.writeSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.writeSessionBean in project tomee by apache.

the class AnnotationDeployerTest method testLocalBean.

/**
     * For https://issues.apache.org/jira/browse/OPENEJB-1188
     *
     * @throws Exception
     */
@Test
public void testLocalBean() throws Exception {
    final EjbModule ejbModule = testModule();
    final EjbJar ejbJar = ejbModule.getEjbJar();
    AppModule appModule = new AppModule(Thread.currentThread().getContextClassLoader(), "myapp");
    appModule.getEjbModules().add(ejbModule);
    final AnnotationDeployer annotationDeployer = new AnnotationDeployer();
    appModule = annotationDeployer.deploy(appModule);
    EnterpriseBean bean = ejbJar.getEnterpriseBean("TestLocalBean");
    assert bean != null;
    assert (((SessionBean) bean).getLocalBean() != null);
    bean = ejbJar.getEnterpriseBean("InterceptedSLSBean");
    assert bean != null;
    assert (((SessionBean) bean).getLocalBean() == null);
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) SessionBean(org.apache.openejb.jee.SessionBean) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test)

Example 2 with SessionBean$JAXB.writeSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.writeSessionBean in project tomee by apache.

the class JndiEncInfoBuilder method buildDependsOnRefs.

public void buildDependsOnRefs(final EnterpriseBean enterpriseBean, final EnterpriseBeanInfo beanInfo, final String moduleId) throws OpenEJBException {
    if (!(enterpriseBean instanceof SessionBean)) {
        return;
    }
    final SessionBean sessionBean = (SessionBean) enterpriseBean;
    final URI moduleUri;
    if (moduleId == null) {
        moduleUri = null;
    } else {
        moduleUri = URLs.uri(moduleId);
    }
    final EjbResolver ejbResolver = getEjbResolver(moduleId);
    if (sessionBean.getDependsOn() != null) {
        for (final String ejbName : sessionBean.getDependsOn()) {
            final String deploymentId = ejbResolver.resolve(new SimpleRef(ejbName), moduleUri);
            if (deploymentId != null) {
                beanInfo.dependsOn.add(deploymentId);
            }
        }
    }
}
Also used : EjbResolver(org.apache.openejb.assembler.classic.EjbResolver) SessionBean(org.apache.openejb.jee.SessionBean) URI(java.net.URI)

Example 3 with SessionBean$JAXB.writeSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.writeSessionBean 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 4 with SessionBean$JAXB.writeSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.writeSessionBean in project tomee by apache.

the class MergeWebappJndiContext method merge.

private void merge(final EjbModule ejbModule, final WebModule webModule) {
    final JndiConsumer webApp = webModule.getWebApp();
    final EjbJar ejbJar = ejbModule.getEjbJar();
    for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
        merge(bean.getEnvEntryMap(), webApp.getEnvEntryMap());
        merge(bean.getEjbRefMap(), webApp.getEjbRefMap());
        merge(bean.getEjbLocalRefMap(), webApp.getEjbLocalRefMap());
        merge(bean.getServiceRefMap(), webApp.getServiceRefMap());
        merge(bean.getResourceRefMap(), webApp.getResourceRefMap());
        merge(bean.getResourceEnvRefMap(), webApp.getResourceEnvRefMap());
        merge(bean.getMessageDestinationRefMap(), webApp.getMessageDestinationRefMap());
        merge(bean.getPersistenceContextRefMap(), webApp.getPersistenceContextRefMap());
        merge(bean.getPersistenceUnitRefMap(), webApp.getPersistenceUnitRefMap());
        mergeUserTransaction(bean.getResourceRefMap(), webApp.getResourceRefMap(), webApp);
        mergeUserTransaction(bean.getResourceEnvRefMap(), webApp.getResourceEnvRefMap(), webApp);
        mergeUserTransaction(webApp.getResourceRefMap(), bean.getResourceRefMap(), bean);
        mergeUserTransaction(webApp.getResourceEnvRefMap(), bean.getResourceEnvRefMap(), bean);
    }
    // easy way to get a JndiConsumer
    final SessionBean aggregator = new SessionBean();
    for (final EnterpriseBean a : ejbJar.getEnterpriseBeans()) {
        aggregator.getEnvEntryMap().putAll(a.getEnvEntryMap());
        aggregator.getEjbRefMap().putAll(a.getEjbRefMap());
        aggregator.getEjbLocalRefMap().putAll(a.getEjbLocalRefMap());
        aggregator.getServiceRefMap().putAll(a.getServiceRefMap());
        aggregator.getResourceRefMap().putAll(a.getResourceRefMap());
        aggregator.getResourceEnvRefMap().putAll(a.getResourceEnvRefMap());
        aggregator.getMessageDestinationRefMap().putAll(a.getMessageDestinationRefMap());
        aggregator.getPersistenceContextRefMap().putAll(a.getPersistenceContextRefMap());
        aggregator.getPersistenceUnitRefMap().putAll(a.getPersistenceUnitRefMap());
    }
    for (final EnterpriseBean a : ejbJar.getEnterpriseBeans()) {
        copy(aggregator.getEnvEntryMap(), a.getEnvEntryMap());
        copy(aggregator.getEjbRefMap(), a.getEjbRefMap());
        copy(aggregator.getEjbLocalRefMap(), a.getEjbLocalRefMap());
        copy(aggregator.getServiceRefMap(), a.getServiceRefMap());
        copy(aggregator.getResourceRefMap(), a.getResourceRefMap());
        copy(aggregator.getResourceEnvRefMap(), a.getResourceEnvRefMap());
        copy(aggregator.getMessageDestinationRefMap(), a.getMessageDestinationRefMap());
        copy(aggregator.getPersistenceContextRefMap(), a.getPersistenceContextRefMap());
        copy(aggregator.getPersistenceUnitRefMap(), a.getPersistenceUnitRefMap());
        mergeUserTransaction(aggregator.getResourceRefMap(), a.getResourceRefMap(), a);
        mergeUserTransaction(aggregator.getResourceEnvRefMap(), a.getResourceEnvRefMap(), a);
    }
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) JndiConsumer(org.apache.openejb.jee.JndiConsumer) SessionBean(org.apache.openejb.jee.SessionBean) EjbJar(org.apache.openejb.jee.EjbJar)

Example 5 with SessionBean$JAXB.writeSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.writeSessionBean in project tomee by apache.

the class CheckClasses method validate.

public void validate(final EjbModule ejbModule) {
    final ClassLoader loader = ejbModule.getClassLoader();
    for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
        try {
            final Class<?> beanClass = check_hasEjbClass(loader, bean);
            // All the subsequent checks require the bean class
            if (beanClass == null) {
                continue;
            }
            if (!(bean instanceof RemoteBean)) {
                continue;
            }
            if (bean instanceof SessionBean && ((SessionBean) bean).getProxy() != null) {
                continue;
            }
            final RemoteBean b = (RemoteBean) bean;
            check_isEjbClass(b);
            check_hasDependentClasses(b, b.getEjbClass(), "ejb-class");
            check_hasInterface(b);
            if (b.getRemote() != null) {
                checkInterface(loader, b, beanClass, "remote", b.getRemote());
            }
            if (b.getHome() != null) {
                checkInterface(loader, b, beanClass, "home", b.getHome());
            }
            if (b.getLocal() != null) {
                checkInterface(loader, b, beanClass, "local", b.getLocal());
            }
            if (b.getLocalHome() != null) {
                checkInterface(loader, b, beanClass, "local-home", b.getLocalHome());
            }
            if (b instanceof SessionBean) {
                final SessionBean sessionBean = (SessionBean) b;
                for (final String interfce : sessionBean.getBusinessLocal()) {
                    checkInterface(loader, b, beanClass, "business-local", interfce);
                }
                for (final String interfce : sessionBean.getBusinessRemote()) {
                    checkInterface(loader, b, beanClass, "business-remote", interfce);
                }
            }
        } catch (final RuntimeException e) {
            throw new OpenEJBRuntimeException(bean.getEjbName(), e);
        }
    }
    for (final Interceptor interceptor : ejbModule.getEjbJar().getInterceptors()) {
        check_hasInterceptorClass(loader, interceptor);
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) RemoteBean(org.apache.openejb.jee.RemoteBean) SessionBean(org.apache.openejb.jee.SessionBean) Interceptor(org.apache.openejb.jee.Interceptor)

Aggregations

SessionBean (org.apache.openejb.jee.SessionBean)22 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)12 EjbJar (org.apache.openejb.jee.EjbJar)10 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)8 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)7 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)4 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 PortInfo (org.apache.openejb.assembler.classic.PortInfo)3 EjbModule (org.apache.openejb.config.EjbModule)3 MalformedURLException (java.net.MalformedURLException)2 List (java.util.List)2 Beans (org.apache.openejb.jee.Beans)2 EntityBean (org.apache.openejb.jee.EntityBean)2 Interceptor (org.apache.openejb.jee.Interceptor)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1