use of org.apache.openejb.jee.ManagedBean in project tomee by apache.
the class OpenEJBArchiveProcessor method addTestClassAsManagedBean.
private static EjbModule addTestClassAsManagedBean(Class<?> javaClass, URLClassLoader tempClassLoader, AppModule appModule) {
final EjbJar ejbJar = new EjbJar();
final OpenejbJar openejbJar = new OpenejbJar();
final String ejbName = appModule.getModuleId() + "_" + javaClass.getName();
final ManagedBean bean = ejbJar.addEnterpriseBean(new ManagedBean(ejbName, javaClass.getName(), true));
bean.localBean();
bean.setTransactionType(TransactionType.BEAN);
final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
ejbDeployment.setDeploymentId(ejbName);
final EjbModule e = new EjbModule(ejbJar, openejbJar);
e.getProperties().setProperty("openejb.cdi.activated", "false");
e.getProperties().setProperty("openejb.test.module", "true");
e.setBeans(new Beans());
e.setClassLoader(tempClassLoader);
appModule.getEjbModules().add(e);
return e;
}
use of org.apache.openejb.jee.ManagedBean in project tomee by apache.
the class InitEjbDeployments method deploy.
private EjbModule deploy(final EjbModule ejbModule, final Map<String, String> contextData, final Set<String> abstractSchemaNames) throws OpenEJBException {
contextData.put("moduleId", ejbModule.getModuleId());
contextData.put("moduleUri", ejbModule.getModuleUri().toString());
final OpenejbJar openejbJar;
if (ejbModule.getOpenejbJar() != null) {
openejbJar = ejbModule.getOpenejbJar();
} else {
openejbJar = new OpenejbJar();
ejbModule.setOpenejbJar(openejbJar);
}
StringTemplate deploymentIdTemplate = this.deploymentIdTemplate;
if (openejbJar.getProperties().containsKey(DEPLOYMENT_ID_FORMAT)) {
final String format = openejbJar.getProperties().getProperty(DEPLOYMENT_ID_FORMAT);
logger.info("Using " + DEPLOYMENT_ID_FORMAT + " '" + format + "'");
deploymentIdTemplate = new StringTemplate(format);
}
for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
StringTemplate template = deploymentIdTemplate;
final org.apache.openejb.api.EjbDeployment annotation = getEjbDeploymentAnnotation(ejbModule, bean);
EjbDeployment ejbDeployment = openejbJar.getDeploymentsByEjbName().get(bean.getEjbName());
if (ejbDeployment == null) {
ejbDeployment = new EjbDeployment();
ejbDeployment.setEjbName(bean.getEjbName());
if (annotation != null && isDefined(annotation.id())) {
template = new StringTemplate(annotation.id());
ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
} else {
ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
if (!(bean instanceof ManagedBean) || !((ManagedBean) bean).isHidden()) {
logger.info("Auto-deploying ejb " + bean.getEjbName() + ": EjbDeployment(deployment-id=" + ejbDeployment.getDeploymentId() + ")");
}
}
openejbJar.getEjbDeployment().add(ejbDeployment);
} else if (ejbDeployment.getDeploymentId() == null) {
if (annotation != null && isDefined(annotation.id())) {
template = new StringTemplate(annotation.id());
ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
} else {
ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
logger.info("Auto-assigning deployment-id for ejb " + bean.getEjbName() + ": EjbDeployment(deployment-id=" + ejbDeployment.getDeploymentId() + ")");
}
}
if (ejbDeployment.getContainerId() == null && annotation != null && isDefined(annotation.container())) {
ejbDeployment.setContainerId(annotation.container());
}
if (isCmpEntity(bean)) {
final EntityBean entity = (EntityBean) bean;
if (entity.getAbstractSchemaName() == null) {
String abstractSchemaName = bean.getEjbName().trim().replaceAll("[ \\t\\n\\r-]+", "_");
// The AbstractSchemaName must be unique, we should check that it is
if (abstractSchemaNames.contains(abstractSchemaName)) {
int i = 2;
while (abstractSchemaNames.contains(abstractSchemaName + i)) {
i++;
}
abstractSchemaName = abstractSchemaName + i;
}
abstractSchemaNames.add(abstractSchemaName);
entity.setAbstractSchemaName(abstractSchemaName);
}
}
}
return ejbModule;
}
use of org.apache.openejb.jee.ManagedBean in project tomee by apache.
the class ManagedBeanTest method setUp.
@Override
protected void setUp() 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 ManagedBean(MyBean.class));
assembler.createApplication(config.configureApplication(ejbJar));
}
use of org.apache.openejb.jee.ManagedBean in project tomee by apache.
the class Container method addCallersAsEjbModule.
private static void addCallersAsEjbModule(final ClassLoader loader, final AppModule app, final String... additionalCallers) {
final Set<String> callers = new HashSet<>(NewLoaderLogic.callers(Filters.classes(Container.class.getName(), "org.apache.openejb.maven.plugins.TomEEEmbeddedMojo")));
// we don't care of these
callers.remove("org.apache.tomee.embedded.Container");
callers.remove("org.apache.tomee.gradle.embedded.TomEEEmbeddedTask");
final Iterator<String> callerIt = callers.iterator();
while (callerIt.hasNext()) {
// TomEEEmbeddedMojo is also used with some anonymous classes (TomEEEmbeddedMojo$x)
if (callerIt.next().startsWith("org.apache.openejb.maven.plugins.TomEEEmbeddedMojo")) {
callerIt.remove();
// no break since we remove anonymous class+the mojo itself
}
}
if (additionalCallers != null && additionalCallers.length > 0) {
callers.addAll(asList(additionalCallers));
}
if (callers.isEmpty()) {
return;
}
final EjbJar ejbJar = new EjbJar();
final OpenejbJar openejbJar = new OpenejbJar();
for (final String caller : callers) {
try {
if (!AnnotationDeployer.isInstantiable(loader.loadClass(caller))) {
continue;
}
} catch (final ClassNotFoundException e) {
continue;
}
final String name = caller.replace("$", "_");
final ManagedBean bean = ejbJar.addEnterpriseBean(new ManagedBean(caller.replace("$", "_"), caller, true));
bean.localBean();
bean.setTransactionType(TransactionType.BEAN);
final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
ejbDeployment.setDeploymentId(name);
}
final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
ejbModule.setBeans(new Beans());
app.getEjbModules().add(ejbModule);
}
Aggregations