Search in sources :

Example 11 with EnterpriseBean

use of org.apache.openejb.jee.EnterpriseBean in project tomee by apache.

the class BeanProperties method deploy.

@Override
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    final Properties base = new Properties();
    base.putAll(SystemInstance.get().getProperties());
    base.putAll(appModule.getProperties());
    for (final EjbModule module : appModule.getEjbModules()) {
        final Properties overrides = new SuperProperties().caseInsensitive(true);
        overrides.putAll(base);
        overrides.putAll(module.getProperties());
        if (module.getOpenejbJar() == null) {
            module.setOpenejbJar(new OpenejbJar());
        }
        final OpenejbJar openejbJar = module.getOpenejbJar();
        final Map<String, EjbDeployment> deploymentMap = openejbJar.getDeploymentsByEjbName();
        for (final EnterpriseBean bean : module.getEjbJar().getEnterpriseBeans()) {
            final SuperProperties properties = new SuperProperties().caseInsensitive(true);
            properties.putAll(globalProperties);
            final String additionalKey = bean.getEjbName();
            if (additionalProperties.containsKey(additionalKey)) {
                for (final Map.Entry<Object, Object> entry : additionalProperties.get(additionalKey).entrySet()) {
                    properties.put(entry.getKey().toString(), entry.getValue().toString());
                }
            }
            final EjbDeployment deployment = deploymentMap.get(bean.getEjbName());
            if (deployment != null) {
                properties.putAll(deployment.getProperties());
                deployment.getProperties().clear();
            }
            final String id = bean.getEjbName() + ".";
            for (final Map.Entry<Object, Object> entry : overrides.entrySet()) {
                final String key = entry.getKey().toString();
                if (key.startsWith(id)) {
                    final String property = key.substring(id.length());
                    if (properties.containsKey(property)) {
                        log.debug("Overriding ejb " + bean.getEjbName() + " property " + property + "=" + entry.getValue());
                    } else {
                        log.debug("Adding ejb " + bean.getEjbName() + " property " + property + "=" + entry.getValue());
                    }
                    properties.put(property, entry.getValue());
                }
            }
            if (properties.size() > 0) {
                if (deployment == null) {
                    final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
                    ejbDeployment.getProperties().putAll(properties);
                } else {
                    deployment.getProperties().putAll(properties);
                }
            }
        }
    }
    // cleanup
    additionalProperties.clear();
    globalProperties.clear();
    return appModule;
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Properties(java.util.Properties) SuperProperties(org.apache.openejb.util.SuperProperties) Map(java.util.Map) HashMap(java.util.HashMap) SuperProperties(org.apache.openejb.util.SuperProperties)

Example 12 with EnterpriseBean

use of org.apache.openejb.jee.EnterpriseBean in project tomee by apache.

the class BuiltInEnvironmentEntries method deploy.

public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    for (final ClientModule module : appModule.getClientModules()) {
        final JndiConsumer consumer = module.getApplicationClient();
        if (consumer == null) {
            continue;
        }
        add(consumer, module, appModule, false);
    }
    for (final WebModule module : appModule.getWebModules()) {
        final JndiConsumer consumer = module.getWebApp();
        if (consumer == null) {
            continue;
        }
        add(consumer, module, appModule, addDefaults);
    }
    for (final EjbModule module : appModule.getEjbModules()) {
        final EjbJar ejbJar = module.getEjbJar();
        if (ejbJar == null) {
            continue;
        }
        for (final EnterpriseBean consumer : ejbJar.getEnterpriseBeans()) {
            add(consumer, module, appModule, addDefaults && BeanContext.Comp.class.getName().equals(consumer.getEjbClass()));
        }
    }
    return appModule;
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) JndiConsumer(org.apache.openejb.jee.JndiConsumer) EjbJar(org.apache.openejb.jee.EjbJar)

Example 13 with EnterpriseBean

use of org.apache.openejb.jee.EnterpriseBean in project tomee by apache.

the class CleanEnvEntries method fillInMissingType.

public AppModule fillInMissingType(final AppModule appModule) throws OpenEJBException {
    for (final ClientModule module : appModule.getClientModules()) {
        final JndiConsumer consumer = module.getApplicationClient();
        if (consumer == null) {
            continue;
        }
        fillInMissingType(consumer, module);
    }
    for (final WebModule module : appModule.getWebModules()) {
        final JndiConsumer consumer = module.getWebApp();
        if (consumer == null) {
            continue;
        }
        fillInMissingType(consumer, module);
    }
    for (final EjbModule module : appModule.getEjbModules()) {
        final EjbJar ejbJar = module.getEjbJar();
        if (ejbJar == null) {
            continue;
        }
        for (final EnterpriseBean consumer : ejbJar.getEnterpriseBeans()) {
            fillInMissingType(consumer, module);
        }
    }
    return appModule;
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) JndiConsumer(org.apache.openejb.jee.JndiConsumer) EjbJar(org.apache.openejb.jee.EjbJar)

Example 14 with EnterpriseBean

use of org.apache.openejb.jee.EnterpriseBean in project tomee by apache.

the class AutoConfig method deploy.

private void deploy(final EjbModule ejbModule, final AppResources appResources) throws OpenEJBException {
    final OpenejbJar openejbJar;
    if (ejbModule.getOpenejbJar() != null) {
        openejbJar = ejbModule.getOpenejbJar();
    } else {
        openejbJar = new OpenejbJar();
        ejbModule.setOpenejbJar(openejbJar);
    }
    final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
    for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
        final EjbDeployment ejbDeployment = deployments.get(bean.getEjbName());
        if (ejbDeployment == null) {
            throw new OpenEJBException("No ejb deployment found for ejb " + bean.getEjbName());
        }
        final Class<? extends ContainerInfo> containerInfoType = ConfigurationFactory.getContainerInfoType(getType(bean));
        if (ejbDeployment.getContainerId() == null && !skipMdb(bean)) {
            String containerId = getUsableContainer(containerInfoType, bean, appResources);
            if (containerId == null) {
                containerId = createContainer(containerInfoType, ejbDeployment, bean);
            }
            ejbDeployment.setContainerId(containerId);
        }
        // create the container if it doesn't exist
        final List<String> containerIds = configFactory.getContainerIds();
        containerIds.addAll(appResources.getContainerIds());
        if (!containerIds.contains(ejbDeployment.getContainerId()) && !skipMdb(bean)) {
            createContainer(containerInfoType, ejbDeployment, bean);
        }
        // Resource reference
        for (final ResourceRef ref : bean.getResourceRef()) {
            processResourceRef(ref, ejbDeployment, appResources, ejbModule);
        }
        // Resource env reference
        for (final JndiReference ref : bean.getResourceEnvRef()) {
            processResourceEnvRef(ref, ejbDeployment, appResources, ejbModule.getClassLoader());
        }
        // Message destination reference
        for (final MessageDestinationRef ref : bean.getMessageDestinationRef()) {
            processResourceEnvRef(ref, ejbDeployment, appResources, ejbModule.getClassLoader());
        }
        // mdb message destination id
        if (autoCreateResources && bean instanceof MessageDrivenBean) {
            final MessageDrivenBean mdb = (MessageDrivenBean) bean;
            final ResourceLink resourceLink = ejbDeployment.getResourceLink("openejb/destination");
            if (resourceLink != null) {
                try {
                    final String destinationId = getResourceEnvId(bean.getEjbName(), resourceLink.getResId(), mdb.getMessageDestinationType(), appResources);
                    resourceLink.setResId(destinationId);
                } catch (final OpenEJBException e) {
                    // The MDB doesn't need the auto configured "openejb/destination" env entry
                    ejbDeployment.removeResourceLink("openejb/destination");
                }
            }
        }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) MessageDestinationRef(org.apache.openejb.jee.MessageDestinationRef) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) JndiReference(org.apache.openejb.jee.JndiReference) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ResourceLink(org.apache.openejb.jee.oejb3.ResourceLink) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) ResourceRef(org.apache.openejb.jee.ResourceRef)

Example 15 with EnterpriseBean

use of org.apache.openejb.jee.EnterpriseBean in project tomee by apache.

the class ApplyOpenejbJar method deploy.

public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final Map<String, EjbDeployment> ejbDeployments = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
        for (final EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
            // Get the OpenEJB deployment from openejb-jar.xml
            final EjbDeployment ejbDeployment = ejbDeployments.get(enterpriseBean.getEjbName());
            enterpriseBean.setId(ejbDeployment.getDeploymentId());
            for (final ResourceRef ref : enterpriseBean.getResourceRef()) {
                final ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
                if (resourceLink != null && resourceLink.getResId() != null) /* don't overwrite with null */
                {
                    ref.setMappedName(resourceLink.getResId());
                }
            }
            for (final ResourceEnvRef ref : enterpriseBean.getResourceEnvRef()) {
                final ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
                if (resourceLink != null && resourceLink.getResId() != null) /* don't overwrite with null */
                {
                    ref.setMappedName(resourceLink.getResId());
                }
            }
            for (final MessageDestinationRef ref : enterpriseBean.getMessageDestinationRef()) {
                final ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
                if (resourceLink != null && resourceLink.getResId() != null) /* don't overwrite with null */
                {
                    ref.setMappedName(resourceLink.getResId());
                }
            }
            for (final EjbRef ref : enterpriseBean.getEjbRef()) {
                final EjbLink ejbLink = ejbDeployment.getEjbLink(ref.getName());
                if (ejbLink != null && ejbLink.getDeployentId() != null) /* don't overwrite with null */
                {
                    ref.setMappedName(ejbLink.getDeployentId());
                }
            }
            for (final EjbLocalRef ref : enterpriseBean.getEjbLocalRef()) {
                final EjbLink ejbLink = ejbDeployment.getEjbLink(ref.getName());
                if (ejbLink != null && ejbLink.getDeployentId() != null) /* don't overwrite with null */
                {
                    ref.setMappedName(ejbLink.getDeployentId());
                }
            }
        }
    }
    return appModule;
}
Also used : EjbLocalRef(org.apache.openejb.jee.EjbLocalRef) MessageDestinationRef(org.apache.openejb.jee.MessageDestinationRef) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) ResourceLink(org.apache.openejb.jee.oejb3.ResourceLink) EjbRef(org.apache.openejb.jee.EjbRef) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) ResourceRef(org.apache.openejb.jee.ResourceRef) ResourceEnvRef(org.apache.openejb.jee.ResourceEnvRef) EjbLink(org.apache.openejb.jee.oejb3.EjbLink)

Aggregations

EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)46 EjbJar (org.apache.openejb.jee.EjbJar)19 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)16 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)14 SessionBean (org.apache.openejb.jee.SessionBean)12 ArrayList (java.util.ArrayList)9 EjbModule (org.apache.openejb.config.EjbModule)9 HashMap (java.util.HashMap)8 OpenEJBException (org.apache.openejb.OpenEJBException)7 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)7 Map (java.util.Map)6 AssemblyDescriptor (org.apache.openejb.jee.AssemblyDescriptor)6 Interceptor (org.apache.openejb.jee.Interceptor)6 List (java.util.List)5 Properties (java.util.Properties)5 EntityBean (org.apache.openejb.jee.EntityBean)5 InterceptorBinding (org.apache.openejb.jee.InterceptorBinding)5 ResourceLink (org.apache.openejb.jee.oejb3.ResourceLink)5 Resources (org.apache.openejb.config.sys.Resources)4 JndiConsumer (org.apache.openejb.jee.JndiConsumer)4