use of org.apache.openejb.BeanType in project tomee by apache.
the class Assembler method initEjbs.
public List<BeanContext> initEjbs(final ClassLoader classLoader, final AppInfo appInfo, final AppContext appContext, final Set<Injection> injections, final List<BeanContext> allDeployments, final String webappId) throws OpenEJBException {
final String globalTimersOn = SystemInstance.get().getProperty(OPENEJB_TIMERS_ON, "true");
final EjbJarBuilder ejbJarBuilder = new EjbJarBuilder(props, appContext);
for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
if (isSkip(appInfo, webappId, ejbJar)) {
continue;
}
final HashMap<String, BeanContext> deployments = ejbJarBuilder.build(ejbJar, injections, classLoader);
final JaccPermissionsBuilder jaccPermissionsBuilder = new JaccPermissionsBuilder();
final PolicyContext policyContext = jaccPermissionsBuilder.build(ejbJar, deployments);
jaccPermissionsBuilder.install(policyContext);
final TransactionPolicyFactory transactionPolicyFactory = createTransactionPolicyFactory(ejbJar, classLoader);
for (final BeanContext beanContext : deployments.values()) {
beanContext.setTransactionPolicyFactory(transactionPolicyFactory);
}
final MethodTransactionBuilder methodTransactionBuilder = new MethodTransactionBuilder();
methodTransactionBuilder.build(deployments, ejbJar.methodTransactions);
final MethodConcurrencyBuilder methodConcurrencyBuilder = new MethodConcurrencyBuilder();
methodConcurrencyBuilder.build(deployments, ejbJar.methodConcurrency);
for (final BeanContext beanContext : deployments.values()) {
containerSystem.addDeployment(beanContext);
}
// bind ejbs into global jndi
jndiBuilder.build(ejbJar, deployments);
// setup timers/asynchronous methods - must be after transaction attributes are set
for (final BeanContext beanContext : deployments.values()) {
if (beanContext.getComponentType() != BeanType.STATEFUL) {
final Method ejbTimeout = beanContext.getEjbTimeout();
boolean timerServiceRequired = false;
if (ejbTimeout != null) {
// If user set the tx attribute to RequiresNew change it to Required so a new transaction is not started
if (beanContext.getTransactionType(ejbTimeout) == TransactionType.RequiresNew) {
beanContext.setMethodTransactionAttribute(ejbTimeout, TransactionType.Required);
}
timerServiceRequired = true;
}
for (final Iterator<Map.Entry<Method, MethodContext>> it = beanContext.iteratorMethodContext(); it.hasNext(); ) {
final Map.Entry<Method, MethodContext> entry = it.next();
final MethodContext methodContext = entry.getValue();
if (methodContext.getSchedules().size() > 0) {
timerServiceRequired = true;
final Method method = entry.getKey();
// TODO Need ?
if (beanContext.getTransactionType(method) == TransactionType.RequiresNew) {
beanContext.setMethodTransactionAttribute(method, TransactionType.Required);
}
}
}
if (timerServiceRequired && "true".equalsIgnoreCase(appInfo.properties.getProperty(OPENEJB_TIMERS_ON, globalTimersOn))) {
// Create the timer
final EjbTimerServiceImpl timerService = new EjbTimerServiceImpl(beanContext, newTimerStore(beanContext));
// Load auto-start timers
final TimerStore timerStore = timerService.getTimerStore();
for (final Iterator<Map.Entry<Method, MethodContext>> it = beanContext.iteratorMethodContext(); it.hasNext(); ) {
final Map.Entry<Method, MethodContext> entry = it.next();
final MethodContext methodContext = entry.getValue();
for (final ScheduleData scheduleData : methodContext.getSchedules()) {
timerStore.createCalendarTimer(timerService, (String) beanContext.getDeploymentID(), null, entry.getKey(), scheduleData.getExpression(), scheduleData.getConfig(), true);
}
}
beanContext.setEjbTimerService(timerService);
} else {
beanContext.setEjbTimerService(new NullEjbTimerServiceImpl());
}
}
// TODO ???
for (final Iterator<Entry<Method, MethodContext>> it = beanContext.iteratorMethodContext(); it.hasNext(); ) {
final Entry<Method, MethodContext> entry = it.next();
if (entry.getValue().isAsynchronous() && beanContext.getTransactionType(entry.getKey()) == TransactionType.RequiresNew) {
beanContext.setMethodTransactionAttribute(entry.getKey(), TransactionType.Required);
}
}
// if local bean or mdb generate proxy class now to avoid bottleneck on classloader later
if (beanContext.isLocalbean() && !beanContext.getComponentType().isMessageDriven() && !beanContext.isDynamicallyImplemented()) {
final List<Class> interfaces = new ArrayList<>(3);
interfaces.add(Serializable.class);
interfaces.add(IntraVmProxy.class);
final BeanType type = beanContext.getComponentType();
if (BeanType.STATEFUL.equals(type) || BeanType.MANAGED.equals(type)) {
interfaces.add(BeanContext.Removable.class);
}
beanContext.set(BeanContext.ProxyClass.class, new BeanContext.ProxyClass(beanContext, interfaces.toArray(new Class<?>[interfaces.size()])));
}
}
// process application exceptions
for (final ApplicationExceptionInfo exceptionInfo : ejbJar.applicationException) {
try {
final Class exceptionClass = classLoader.loadClass(exceptionInfo.exceptionClass);
for (final BeanContext beanContext : deployments.values()) {
beanContext.addApplicationException(exceptionClass, exceptionInfo.rollback, exceptionInfo.inherited);
}
} catch (final ClassNotFoundException e) {
logger.error("createApplication.invalidClass", e, exceptionInfo.exceptionClass, e.getMessage());
}
}
allDeployments.addAll(deployments.values());
}
final List<BeanContext> ejbs = sort(allDeployments);
for (final BeanContext b : ejbs) {
// otherwise for ears we have duplicated beans
if (appContext.getBeanContexts().contains(b)) {
continue;
}
appContext.getBeanContexts().add(b);
}
return ejbs;
}
use of org.apache.openejb.BeanType in project tomee by apache.
the class CdiPlugin method validateScope.
private static void validateScope(final CdiEjbBean<?> bean) {
final Class<? extends Annotation> scope = bean.getScope();
final BeanType beanType = bean.getBeanContext().getComponentType();
if (BeanType.STATELESS.equals(beanType) && !Dependent.class.equals(scope)) {
throw new WebBeansConfigurationException("@Stateless can only be @Dependent");
}
if (BeanType.SINGLETON.equals(beanType) && !Dependent.class.equals(scope) && !ApplicationScoped.class.equals(scope)) {
throw new WebBeansConfigurationException("@Singleton can only be @Dependent or @ApplicationScoped");
}
}
use of org.apache.openejb.BeanType in project tomee by apache.
the class EjbHomeProxyHandler method createProxy.
public Object createProxy(final Object primaryKey, final Class mainInterface) {
try {
final InterfaceType objectInterfaceType = this.interfaceType.getCounterpart();
final BeanType type = getBeanContext().getComponentType();
final EjbObjectProxyHandler handler = newEjbObjectHandler(getBeanContext(), primaryKey, objectInterfaceType, getInterfaces(), mainInterface);
// TODO Is it correct for ManagedBean injection via managed bean class?
if ((InterfaceType.LOCALBEAN.equals(objectInterfaceType) || getBeanContext().getComponentType().equals(BeanType.MANAGED)) && !getBeanContext().isDynamicallyImplemented()) {
return LocalBeanProxyFactory.constructProxy(handler.getBeanContext().get(BeanContext.ProxyClass.class).getProxy(), handler);
} else {
final List<Class> proxyInterfaces = new ArrayList<>(handler.getInterfaces().size() + 2);
proxyInterfaces.addAll(handler.getInterfaces());
proxyInterfaces.add(Serializable.class);
proxyInterfaces.add(IntraVmProxy.class);
if (BeanType.STATEFUL.equals(type) || BeanType.MANAGED.equals(type)) {
proxyInterfaces.add(BeanContext.Removable.class);
}
return ProxyManager.newProxyInstance(proxyInterfaces.toArray(new Class[proxyInterfaces.size()]), handler);
}
} catch (final IllegalAccessException iae) {
throw new OpenEJBRuntimeException("Could not create IVM proxy for " + getInterfaces().get(0), iae);
}
}
use of org.apache.openejb.BeanType in project tomee by apache.
the class TomcatWebAppBuilder method eagerInitOfLocalBeanProxies.
private static void eagerInitOfLocalBeanProxies(final Collection<BeanContext> beans, final ClassLoader classLoader) {
for (final BeanContext deployment : beans) {
if (deployment.isLocalbean() && !deployment.isDynamicallyImplemented()) {
// init proxy eagerly otherwise deserialization of serialized object can't work
final List<Class> interfaces = new ArrayList<>(2);
interfaces.add(Serializable.class);
interfaces.add(IntraVmProxy.class);
final BeanType type = deployment.getComponentType();
if (BeanType.STATEFUL.equals(type) || BeanType.MANAGED.equals(type)) {
interfaces.add(BeanContext.Removable.class);
}
try {
LocalBeanProxyFactory.createProxy(deployment.getBeanClass(), classLoader, interfaces.toArray(new Class<?>[interfaces.size()]));
} catch (final Exception e) {
// no-op: as before
}
}
}
}
use of org.apache.openejb.BeanType in project tomee by apache.
the class BeanTypeComparisonTest method testEqualsMethodForDifferentClassTypes.
@Test
public void testEqualsMethodForDifferentClassTypes() {
final BeanType beanType = BeanType.STATELESS;
final SessionType sessionType = SessionType.STATELESS;
assertFalse(beanType.equals(sessionType));
}
Aggregations