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