use of org.apache.openejb.jee.StatefulBean 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;
}
use of org.apache.openejb.jee.StatefulBean in project tomee by apache.
the class EntityManagerPropogationTest method addStatefulBean.
private void addStatefulBean(final EjbJar ejbJar, final Class<?> ejbClass, final String name, final String reference) {
final StatefulBean bean = ejbJar.addEnterpriseBean(new StatefulBean(name, ejbClass));
bean.getEjbLocalRef().add(new EjbLocalRef("child", reference));
}
use of org.apache.openejb.jee.StatefulBean in project tomee by apache.
the class StatefulBeanManagedTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatefulBean(MyBean.class));
assembler.createApplication(config.configureApplication(ejbJar));
}
use of org.apache.openejb.jee.StatefulBean in project tomee by apache.
the class StatefulContainerTest method setUp.
protected void setUp() throws Exception {
super.setUp();
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
// containers
final StatefulSessionContainerInfo statefulContainerInfo = config.configureService(StatefulSessionContainerInfo.class);
statefulContainerInfo.properties.setProperty("PoolSize", "0");
statefulContainerInfo.properties.setProperty("BulkPassivate", "1");
statefulContainerInfo.properties.setProperty("Frequency", "0");
assembler.createContainer(statefulContainerInfo);
// Setup the descriptor information
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatefulBean(WidgetBean.class));
assembler.createApplication(config.configureApplication(ejbJar));
WidgetBean.lifecycle.clear();
expectedLifecycle = Arrays.asList(Lifecycle.values());
inTxExpectedLifecycle = new ArrayList<>();
for (final Lifecycle lifecycle : Lifecycle.values()) {
if (!lifecycle.name().startsWith("PRE_PASSIVATE") && !lifecycle.name().startsWith("POST_ACTIVATE")) {
inTxExpectedLifecycle.add(lifecycle);
}
}
}
use of org.apache.openejb.jee.StatefulBean in project tomee by apache.
the class StatefulConcurrencyTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final StatefulSessionContainerInfo statefulContainerInfo = config.configureService(StatefulSessionContainerInfo.class);
assembler.createContainer(statefulContainerInfo);
final EjbJar ejbJar = new EjbJar();
final StatefulBean bean1 = new StatefulBean(MyLocalBeanImpl.class);
final Timeout timeout1 = new Timeout();
timeout1.setTimeout(1000);
timeout1.setUnit(TimeUnit.MILLISECONDS);
final ConcurrentMethod method1 = new ConcurrentMethod();
method1.setMethod(new NamedMethod("*"));
method1.setAccessTimeout(timeout1);
bean1.getConcurrentMethod().add(method1);
final StatefulBean bean2 = new StatefulBean("BeanNegative", MyLocalBeanImpl.class);
final Timeout timeout2 = new Timeout();
timeout2.setTimeout(-1);
timeout2.setUnit(TimeUnit.MILLISECONDS);
final ConcurrentMethod method2 = new ConcurrentMethod();
method2.setMethod(new NamedMethod("*"));
method2.setAccessTimeout(timeout2);
bean2.getConcurrentMethod().add(method2);
ejbJar.addEnterpriseBean(bean1);
ejbJar.addEnterpriseBean(bean2);
assembler.createApplication(config.configureApplication(ejbJar));
}
Aggregations