Search in sources :

Example 6 with ManagedBean

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;
}
Also used : CompositeBeans(org.apache.openejb.cdi.CompositeBeans) Beans(org.apache.openejb.jee.Beans) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EjbModule(org.apache.openejb.config.EjbModule) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) ManagedBean(org.apache.openejb.jee.ManagedBean) EjbJar(org.apache.openejb.jee.EjbJar)

Example 7 with ManagedBean

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;
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) StringTemplate(org.apache.openejb.util.StringTemplate) EntityBean(org.apache.openejb.jee.EntityBean) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) ManagedBean(org.apache.openejb.jee.ManagedBean)

Example 8 with ManagedBean

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));
}
Also used : TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) ManagedBean(org.apache.openejb.jee.ManagedBean) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 9 with ManagedBean

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);
}
Also used : Beans(org.apache.openejb.jee.Beans) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EjbModule(org.apache.openejb.config.EjbModule) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) ManagedBean(org.apache.openejb.jee.ManagedBean) HashSet(java.util.HashSet) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

ManagedBean (org.apache.openejb.jee.ManagedBean)9 EjbJar (org.apache.openejb.jee.EjbJar)7 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)6 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)6 EjbModule (org.apache.openejb.config.EjbModule)5 File (java.io.File)3 Beans (org.apache.openejb.jee.Beans)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Properties (java.util.Properties)2 AppModule (org.apache.openejb.config.AppModule)2 ConnectorModule (org.apache.openejb.config.ConnectorModule)2 WebModule (org.apache.openejb.config.WebModule)2 StatefulBean (org.apache.openejb.jee.StatefulBean)2 AnnotationFinder (org.apache.xbean.finder.AnnotationFinder)2 ClassesArchive (org.apache.xbean.finder.archive.ClassesArchive)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1