Search in sources :

Example 6 with ActivationConfigProperty$JAXB.writeActivationConfigProperty

use of org.apache.openejb.jee.ActivationConfigProperty$JAXB.writeActivationConfigProperty in project tomee by apache.

the class OpenEjb2Conversion method convertMdbConfigs.

public final void convertMdbConfigs(final EjbJar ejbJar, final OpenejbJarType openejbJarType) {
    final Map<String, MessageDrivenBean> mdbs = new TreeMap<String, MessageDrivenBean>();
    for (final EnterpriseBean enterpriseBean : ejbJar.getEnterpriseBeans()) {
        if (!(enterpriseBean instanceof MessageDrivenBean)) {
            continue;
        }
        mdbs.put(enterpriseBean.getEjbName(), (MessageDrivenBean) enterpriseBean);
    }
    for (final org.apache.openejb.jee.oejb2.EnterpriseBean enterpriseBean : openejbJarType.getEnterpriseBeans()) {
        if (!(enterpriseBean instanceof MessageDrivenBeanType)) {
            continue;
        }
        final MessageDrivenBeanType bean = (MessageDrivenBeanType) enterpriseBean;
        final MessageDrivenBean mdb = mdbs.get(bean.getEjbName());
        if (mdb == null) {
            // todo warn no such ejb in the ejb-jar.xml
            continue;
        }
        final ActivationConfigType activationConfigType = bean.getActivationConfig();
        if (activationConfigType != null) {
            ActivationConfig activationConfig = mdb.getActivationConfig();
            if (activationConfig == null) {
                activationConfig = new ActivationConfig();
                mdb.setActivationConfig(activationConfig);
            }
            for (final ActivationConfigPropertyType propertyType : activationConfigType.getActivationConfigProperty()) {
                final ActivationConfigProperty property = new ActivationConfigProperty(propertyType.getActivationConfigPropertyName(), propertyType.getActivationConfigPropertyValue());
                activationConfig.getActivationConfigProperty().add(property);
            }
        }
    }
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) MessageDrivenBeanType(org.apache.openejb.jee.oejb2.MessageDrivenBeanType) TreeMap(java.util.TreeMap) ActivationConfig(org.apache.openejb.jee.ActivationConfig) ActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty) ActivationConfigPropertyType(org.apache.openejb.jee.oejb2.ActivationConfigPropertyType) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ActivationConfigType(org.apache.openejb.jee.oejb2.ActivationConfigType)

Example 7 with ActivationConfigProperty$JAXB.writeActivationConfigProperty

use of org.apache.openejb.jee.ActivationConfigProperty$JAXB.writeActivationConfigProperty in project tomee by apache.

the class ActivationConfigPropertyOverride method deploy.

@Override
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    final Properties system = new Properties();
    system.putAll(SystemInstance.get().getProperties());
    system.putAll(appModule.getProperties());
    system.putAll(JavaSecurityManagers.getSystemProperties());
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final EjbJar ejbJar = ejbModule.getEjbJar();
        final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
        final Properties module = new Properties();
        module.putAll(openejbJar.getProperties());
        module.putAll(system);
        final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
        for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
            final String ejbName = bean.getEjbName();
            final EjbDeployment ejbDeployment = deployments.get(ejbName);
            if (!(bean instanceof MessageDrivenBean)) {
                continue;
            }
            final Properties properties = new Properties();
            properties.putAll(module);
            properties.putAll(ejbDeployment.getProperties());
            final MessageDrivenBean mdb = (MessageDrivenBean) bean;
            // override with placeholding
            if (mdb.getActivationConfig() != null) {
                for (final ActivationConfigProperty property : mdb.getActivationConfig().getActivationConfigProperty()) {
                    final String originalValue = property.getActivationConfigPropertyValue();
                    final String value = PropertyPlaceHolderHelper.simpleValue(originalValue);
                    if (value != null && !originalValue.equals(value)) {
                        property.setActivationConfigPropertyValue(value);
                    }
                }
            }
            // now try to use special keys
            final Properties overrides = new Properties();
            final MdbContainerDetails mdbContainer = getMdbContainer(appModule, ejbDeployment.getContainerId(), appModule.getModuleId());
            if (mdbContainer != null) {
                overrides.putAll(ConfigurationFactory.getOverrides(properties, "mdb.container." + mdbContainer.getContainerId() + ".activation", "EnterpriseBean"));
                overrides.putAll(ConfigurationFactory.getOverrides(mdbContainer.getProperties(), "activation", "EnterpriseBean"));
            }
            overrides.putAll(ConfigurationFactory.getOverrides(properties, "mdb.activation", "EnterpriseBean"));
            overrides.putAll(ConfigurationFactory.getOverrides(properties, mdb.getMessagingType() + ".activation", "EnterpriseBean"));
            overrides.putAll(ConfigurationFactory.getOverrides(properties, ejbName + ".activation", "EnterpriseBean"));
            overrides.putAll(ConfigurationFactory.getOverrides(properties, ejbDeployment.getDeploymentId() + ".activation", "EnterpriseBean"));
            // If we don't have any overrides, skip to the next
            if (overrides.size() == 0) {
                continue;
            }
            if (mdb.getActivationConfig() == null) {
                mdb.setActivationConfig(new ActivationConfig());
            }
            final List<ActivationConfigProperty> activationConfigList = mdb.getActivationConfig().getActivationConfigProperty();
            for (final Map.Entry<Object, Object> entry : overrides.entrySet()) {
                final Object property = String.valueOf(entry.getKey());
                final Object value = String.valueOf(entry.getValue());
                ActivationConfigProperty activationConfigProperty = this.findActivationProperty(activationConfigList, property.toString());
                if (activationConfigProperty != null) {
                    logger.info(String.format("Found %s bean with activation-config property %s=%s to override", ejbName, activationConfigProperty.getActivationConfigPropertyName(), activationConfigProperty.getActivationConfigPropertyValue()));
                    logger.info(String.format("Overriding %s bean activation-config property.%s=%s", ejbName, property, value));
                    activationConfigProperty.setActivationConfigPropertyValue(entry.getValue().toString());
                } else {
                    logger.info(String.format("Adding %s bean activation-config property %s=%s", ejbName, property, value));
                    activationConfigProperty = new ActivationConfigProperty();
                    activationConfigProperty.setActivationConfigPropertyName(property.toString());
                    activationConfigProperty.setActivationConfigPropertyValue(value.toString());
                    activationConfigList.add(activationConfigProperty);
                }
            }
        }
    }
    return appModule;
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) Properties(java.util.Properties) ActivationConfig(org.apache.openejb.jee.ActivationConfig) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) ActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Map(java.util.Map) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

ActivationConfig (org.apache.openejb.jee.ActivationConfig)5 ActivationConfigProperty (org.apache.openejb.jee.ActivationConfigProperty)5 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)4 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)3 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)3 Properties (java.util.Properties)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 ActivationConfigProperty$JAXB.readActivationConfigProperty (org.apache.openejb.jee.ActivationConfigProperty$JAXB.readActivationConfigProperty)2 ActivationConfigProperty$JAXB.writeActivationConfigProperty (org.apache.openejb.jee.ActivationConfigProperty$JAXB.writeActivationConfigProperty)2 Text$JAXB.readText (org.apache.openejb.jee.Text$JAXB.readText)2 Text$JAXB.writeText (org.apache.openejb.jee.Text$JAXB.writeText)2 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)2 ResourceLink (org.apache.openejb.jee.oejb3.ResourceLink)2 RuntimeContext (org.metatype.sxc.jaxb.RuntimeContext)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 CollapsedStringAdapter (javax.xml.bind.annotation.adapters.CollapsedStringAdapter)1 QName (javax.xml.namespace.QName)1 MessageDrivenBeanInfo (org.apache.openejb.assembler.classic.MessageDrivenBeanInfo)1