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);
}
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);
}
}
}
}
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);
}
}
}
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);
}
}
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);
}
}
Aggregations