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