Search in sources :

Example 1 with StatefulBeanInfo

use of org.apache.openejb.assembler.classic.StatefulBeanInfo in project tomee by apache.

the class EjbJarInfoBuilder method initSessionBean.

private EnterpriseBeanInfo initSessionBean(final SessionBean s, final EjbJarInfo ejbJar, final Map m) throws OpenEJBException {
    EnterpriseBeanInfo bean;
    if (s.getSessionType() == SessionType.STATEFUL) {
        bean = new StatefulBeanInfo();
        bean.passivable = s.getPassivationCapable() == null || s.getPassivationCapable();
        final StatefulBeanInfo stateful = (StatefulBeanInfo) bean;
        copyCallbacks(s.getPostActivate(), stateful.postActivate);
        copyCallbacks(s.getPrePassivate(), stateful.prePassivate);
        copyCallbacks(s.getAfterBegin(), stateful.afterBegin);
        copyCallbacks(s.getBeforeCompletion(), stateful.beforeCompletion);
        copyCallbacks(s.getAfterCompletion(), stateful.afterCompletion);
        for (final InitMethod initMethod : s.getInitMethod()) {
            final InitMethodInfo init = new InitMethodInfo();
            init.beanMethod = toInfo(initMethod.getBeanMethod());
            init.createMethod = toInfo(initMethod.getCreateMethod());
            stateful.initMethods.add(init);
        }
        for (final RemoveMethod removeMethod : s.getRemoveMethod()) {
            final RemoveMethodInfo remove = new RemoveMethodInfo();
            remove.beanMethod = toInfo(removeMethod.getBeanMethod());
            remove.retainIfException = removeMethod.getRetainIfException();
            stateful.removeMethods.add(remove);
        }
        copyConcurrentMethods(s, ejbJar, m);
    } else if (s.getSessionType() == SessionType.MANAGED) {
        bean = new ManagedBeanInfo();
        final ManagedBeanInfo managed = (ManagedBeanInfo) bean;
        // this way we support managed beans in ejb-jar.xml (not in the spec but can be useful)
        managed.hidden = !(s instanceof ManagedBean) || ((ManagedBean) s).isHidden();
        copyCallbacks(s.getPostActivate(), managed.postActivate);
        copyCallbacks(s.getPrePassivate(), managed.prePassivate);
        for (final RemoveMethod removeMethod : s.getRemoveMethod()) {
            final RemoveMethodInfo remove = new RemoveMethodInfo();
            remove.beanMethod = toInfo(removeMethod.getBeanMethod());
            remove.retainIfException = removeMethod.getRetainIfException();
            managed.removeMethods.add(remove);
        }
    } else if (s.getSessionType() == SessionType.SINGLETON) {
        bean = new SingletonBeanInfo();
        final ConcurrencyManagementType type = s.getConcurrencyManagementType();
        bean.concurrencyType = type != null ? type.toString() : ConcurrencyManagementType.CONTAINER.toString();
        bean.loadOnStartup = s.getInitOnStartup();
        copyCallbacks(s.getAroundTimeout(), bean.aroundTimeout);
        copySchedules(s.getTimer(), bean.methodScheduleInfos);
        // See JndiEncInfoBuilder.buildDependsOnRefs for processing of DependsOn
        // bean.dependsOn.addAll(s.getDependsOn());
        copyConcurrentMethods(s, ejbJar, m);
    } else {
        bean = new StatelessBeanInfo();
        copySchedules(s.getTimer(), bean.methodScheduleInfos);
    }
    if (s.getSessionType() != SessionType.STATEFUL) {
        copyCallbacks(s.getAroundTimeout(), bean.aroundTimeout);
    }
    bean.localbean = s.getLocalBean() != null;
    bean.timeoutMethod = toInfo(s.getTimeoutMethod());
    copyCallbacks(s.getAroundInvoke(), bean.aroundInvoke);
    copyCallbacks(s.getPostConstruct(), bean.postConstruct);
    copyCallbacks(s.getPreDestroy(), bean.preDestroy);
    copyAsynchronous(s.getAsyncMethod(), bean.asynchronous);
    bean.asynchronousClasses.addAll(s.getAsynchronousClasses());
    final EjbDeployment d = (EjbDeployment) m.get(s.getEjbName());
    if (d == null) {
        throw new OpenEJBException("No deployment information in openejb-jar.xml for bean " + s.getEjbName() + ". Please redeploy the jar");
    }
    bean.ejbDeploymentId = d.getDeploymentId();
    bean.containerId = d.getContainerId();
    final Icon icon = s.getIcon();
    bean.largeIcon = icon == null ? null : icon.getLargeIcon();
    bean.smallIcon = icon == null ? null : icon.getSmallIcon();
    bean.description = s.getDescription();
    bean.displayName = s.getDisplayName();
    bean.ejbClass = s.getEjbClass();
    bean.ejbName = s.getEjbName();
    bean.home = s.getHome();
    bean.remote = s.getRemote();
    bean.localHome = s.getLocalHome();
    bean.local = s.getLocal();
    bean.proxy = s.getProxy();
    bean.parents.addAll(s.getParents());
    bean.businessLocal.addAll(s.getBusinessLocal());
    bean.businessRemote.addAll(s.getBusinessRemote());
    final TransactionType txType = s.getTransactionType();
    bean.transactionType = txType != null ? txType.toString() : TransactionType.CONTAINER.toString();
    bean.serviceEndpoint = s.getServiceEndpoint();
    bean.properties.putAll(d.getProperties());
    bean.statefulTimeout = toInfo(s.getStatefulTimeout());
    bean.restService = s.isRestService() && !(s instanceof StatefulBean);
    return bean;
}
Also used : InitMethod(org.apache.openejb.jee.InitMethod) InitMethodInfo(org.apache.openejb.assembler.classic.InitMethodInfo) OpenEJBException(org.apache.openejb.OpenEJBException) TransactionType(org.apache.openejb.jee.TransactionType) ConcurrencyManagementType(org.apache.openejb.jee.ConcurrencyManagementType) StatefulBean(org.apache.openejb.jee.StatefulBean) RemoveMethodInfo(org.apache.openejb.assembler.classic.RemoveMethodInfo) StatelessBeanInfo(org.apache.openejb.assembler.classic.StatelessBeanInfo) ManagedBeanInfo(org.apache.openejb.assembler.classic.ManagedBeanInfo) SingletonBeanInfo(org.apache.openejb.assembler.classic.SingletonBeanInfo) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) StatefulBeanInfo(org.apache.openejb.assembler.classic.StatefulBeanInfo) RemoveMethod(org.apache.openejb.jee.RemoveMethod) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Icon(org.apache.openejb.jee.Icon) ManagedBean(org.apache.openejb.jee.ManagedBean)

Example 2 with StatefulBeanInfo

use of org.apache.openejb.assembler.classic.StatefulBeanInfo in project tomee by apache.

the class InheritenceTest method test.

public void test() throws Exception {
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    assembler.createContainer(config.configureService(StatefulSessionContainerInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatefulBean(Color.class));
    ejbJar.addEnterpriseBean(new StatefulBean(Red.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    final StatefulBeanInfo expected = (StatefulBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
    final StatefulBeanInfo actual = (StatefulBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
    assertEquals("transactionType", expected.transactionType, actual.transactionType);
    assertEquals("runAs", expected.runAs, actual.runAs);
    assertEquals("businessLocal", expected.businessLocal, actual.businessLocal);
    assertEquals("businessRemote", expected.businessRemote, actual.businessRemote);
    assertEquals("local", expected.local, actual.local);
    assertEquals("localHome", expected.localHome, actual.localHome);
    assertEquals("remote", expected.remote, actual.remote);
    assertEquals("home", expected.home, actual.home);
    assertEquals("timeout", expected.timeoutMethod, actual.timeoutMethod);
    assertCallbackInfos("postActivate", expected.postActivate, actual.postActivate);
    assertCallbackInfos("prePassivate", expected.prePassivate, actual.prePassivate);
    assertCallbackInfos("postConstruct", expected.postConstruct, actual.postConstruct);
    assertCallbackInfos("preDestroy", expected.preDestroy, actual.preDestroy);
    assertCallbackInfos("preDestroy", expected.aroundInvoke, actual.aroundInvoke);
    assertRemoveMethodInfos("removeMethods", expected.removeMethods, actual.removeMethods);
    assertInitMethodInfos("initMethods", expected.initMethods, actual.initMethods);
    assertSecurityRoleReferenceInfos("securityRoleReferences", expected.securityRoleReferences, actual.securityRoleReferences);
    // comp/ComponentName is different
    assertEquals(1, expected.jndiEnc.envEntries.size());
    assertEquals(1, actual.jndiEnc.envEntries.size());
    assertEquals("comp/ComponentName", expected.jndiEnc.envEntries.get(0).referenceName);
    assertEquals("Color", expected.jndiEnc.envEntries.get(0).value);
    assertEquals("comp/ComponentName", actual.jndiEnc.envEntries.get(0).referenceName);
    assertEquals("Red", actual.jndiEnc.envEntries.get(0).value);
    expected.jndiEnc.envEntries.clear();
    actual.jndiEnc.envEntries.clear();
    assertEquals("jndiEnc", expected.jndiEnc, actual.jndiEnc);
}
Also used : StatefulSessionContainerInfo(org.apache.openejb.assembler.classic.StatefulSessionContainerInfo) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatefulBeanInfo(org.apache.openejb.assembler.classic.StatefulBeanInfo) StatefulBean(org.apache.openejb.jee.StatefulBean) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

StatefulBeanInfo (org.apache.openejb.assembler.classic.StatefulBeanInfo)2 StatefulBean (org.apache.openejb.jee.StatefulBean)2 OpenEJBException (org.apache.openejb.OpenEJBException)1 Assembler (org.apache.openejb.assembler.classic.Assembler)1 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)1 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)1 InitMethodInfo (org.apache.openejb.assembler.classic.InitMethodInfo)1 ManagedBeanInfo (org.apache.openejb.assembler.classic.ManagedBeanInfo)1 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)1 RemoveMethodInfo (org.apache.openejb.assembler.classic.RemoveMethodInfo)1 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)1 SingletonBeanInfo (org.apache.openejb.assembler.classic.SingletonBeanInfo)1 StatefulSessionContainerInfo (org.apache.openejb.assembler.classic.StatefulSessionContainerInfo)1 StatelessBeanInfo (org.apache.openejb.assembler.classic.StatelessBeanInfo)1 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)1 ConcurrencyManagementType (org.apache.openejb.jee.ConcurrencyManagementType)1 EjbJar (org.apache.openejb.jee.EjbJar)1 Icon (org.apache.openejb.jee.Icon)1 InitMethod (org.apache.openejb.jee.InitMethod)1 ManagedBean (org.apache.openejb.jee.ManagedBean)1