You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2011/09/08 00:18:14 UTC
svn commit: r1166444 - in
/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config:
ActivationConfigPropertyOverride.java AppModule.java
ConfigurationFactory.java
Author: dblevins
Date: Wed Sep 7 22:18:14 2011
New Revision: 1166444
URL: http://svn.apache.org/viewvc?rev=1166444&view=rev
Log:
OPENEJB-1654: System property overrides for MDB ActivationConfig
Added:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java?rev=1166444&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java Wed Sep 7 22:18:14 2011
@@ -0,0 +1,108 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.config;
+
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.jee.ActivationConfig;
+import org.apache.openejb.jee.ActivationConfigProperty;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.EnterpriseBean;
+import org.apache.openejb.jee.MessageDrivenBean;
+import org.apache.openejb.jee.oejb3.EjbDeployment;
+import org.apache.openejb.jee.oejb3.OpenejbJar;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.util.LogCategory;
+import org.apache.openejb.util.Logger;
+
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ActivationConfigPropertyOverride implements DynamicDeployer {
+
+ private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG, ActivationConfigPropertyOverride.class);
+
+ @Override
+ public AppModule deploy(AppModule appModule) throws OpenEJBException {
+
+ final Properties system = new Properties(System.getProperties());
+ system.putAll(SystemInstance.get().getProperties());
+ system.putAll(appModule.getProperties());
+
+ for (EjbModule ejbModule : appModule.getEjbModules()) {
+ EjbJar ejbJar = ejbModule.getEjbJar();
+ OpenejbJar openejbJar = ejbModule.getOpenejbJar();
+
+ final Properties module = new Properties(system);
+ module.putAll(openejbJar.getProperties());
+
+ Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
+
+ for (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(module);
+ properties.putAll(ejbDeployment.getProperties());
+
+ final MessageDrivenBean mdb = (MessageDrivenBean) bean;
+
+ final Properties overrides = 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;
+
+ final Properties activation = asProperties(mdb.getActivationConfig());
+
+ for (Map.Entry<Object, Object> entry : overrides.entrySet()) {
+
+ final Object property = entry.getKey() + "";
+ final Object value = entry.getValue() + "";
+
+ if (activation.contains(property)) {
+ logger.info(String.format("Overriding %s bean activation-config property %s=%s", ejbName, property, value));
+ } else {
+ logger.info(String.format("Adding %s bean activation-config property %s=%s", ejbName, property, value));
+ }
+
+ activation.put(property, value);
+ }
+ }
+ }
+
+ return appModule;
+ }
+
+ private Properties asProperties(ActivationConfig activationConfig) {
+ final Properties properties = new Properties();
+
+ for (ActivationConfigProperty property : activationConfig.getActivationConfigProperty()) {
+ properties.put(property.getActivationConfigPropertyName(), property.getActivationConfigPropertyValue());
+ }
+
+ return properties;
+ }
+
+}
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java?rev=1166444&r1=1166443&r2=1166444&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java Wed Sep 7 22:18:14 2011
@@ -30,6 +30,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
@@ -38,6 +39,7 @@ import java.util.TreeSet;
*/
public class AppModule implements DeploymentModule {
+ private final Properties properties = new Properties();
private final Application application;
private final ValidationContext validation;
private final List<URL> additionalLibraries = new ArrayList<URL>();
@@ -85,6 +87,10 @@ public class AppModule implements Deploy
}
}
+ public Properties getProperties() {
+ return properties;
+ }
+
public AppModule(ClassLoader classLoader, String jarLocation, Application application, boolean standaloneModule) {
this.classLoader = classLoader;
this.application = application;
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=1166444&r1=1166443&r2=1166444&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java Wed Sep 7 22:18:14 2011
@@ -197,6 +197,7 @@ public class ConfigurationFactory implem
chain.add(new ApplyOpenejbJar());
chain.add(new MappedNameBuilder());
+ chain.add(new ActivationConfigPropertyOverride());
// TODO: How do we want this plugged in?
chain.add(new OutputGeneratedDescriptors());
@@ -215,9 +216,7 @@ public class ConfigurationFactory implem
sys = configuration;
}
- public ConfigurationFactory(boolean offline,
- Chain deployerChain,
- OpenEjbConfiguration configuration) {
+ public ConfigurationFactory(boolean offline, Chain deployerChain, OpenEjbConfiguration configuration) {
this.offline = offline;
this.deploymentLoader = new DeploymentLoader();
this.deployer = deployerChain;
@@ -979,16 +978,22 @@ public class ConfigurationFactory implem
}
protected static Properties getSystemProperties(String serviceId, String serviceType) {
- String fullPrefix = serviceType.toUpperCase() + "." + serviceId + ".";
- String fullPrefix2 = serviceType.toUpperCase() + "." + serviceId + "|";
- String shortPrefix = serviceId + ".";
- String shortPrefix2 = serviceId + "|";
-
// Override with system properties
- Properties serviceProperties = new Properties();
- Properties sysProps = new Properties(System.getProperties());
+ final Properties sysProps = new Properties(System.getProperties());
sysProps.putAll(SystemInstance.get().getProperties());
- for (Map.Entry<Object, Object> entry : sysProps.entrySet()) {
+
+
+ return getOverrides(sysProps, serviceId, serviceType);
+ }
+
+ protected static Properties getOverrides(Properties properties, String serviceId, String serviceType) {
+ final String fullPrefix = serviceType.toUpperCase() + "." + serviceId + ".";
+ final String fullPrefix2 = serviceType.toUpperCase() + "." + serviceId + "|";
+ final String shortPrefix = serviceId + ".";
+ final String shortPrefix2 = serviceId + "|";
+
+ final Properties overrides = new Properties();
+ for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String name = (String) entry.getKey();
@@ -1000,13 +1005,13 @@ public class ConfigurationFactory implem
// TODO: Maybe use xbean-reflect to get the string value
String value = entry.getValue().toString();
- serviceProperties.setProperty(name, value);
+ overrides.setProperty(name, value);
break;
}
}
}
- return serviceProperties;
+ return overrides;
}
static Map<String, Class<? extends ContainerInfo>> containerTypes = new HashMap<String, Class<? extends ContainerInfo>>();