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 2007/01/16 15:18:05 UTC

svn commit: r496701 - /incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java

Author: dblevins
Date: Tue Jan 16 06:18:04 2007
New Revision: 496701

URL: http://svn.apache.org/viewvc?view=rev&rev=496701
Log:
cleaned up property overriding and added command line/system property overrides

Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java?view=diff&rev=496701&r1=496700&r2=496701
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java Tue Jan 16 06:18:04 2007
@@ -65,6 +65,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Iterator;
 
 public class ConfigurationFactory implements OpenEjbConfigurationFactory {
 
@@ -347,63 +348,24 @@
             return configureDefaultService(type);
         }
 
-        String serviceType = service.getClass().getSimpleName();
-
-        String serviceId = service.getId();
-
-        String providerId = (service.getProvider() != null) ? service.getProvider() : serviceId;
+        String providerId = (service.getProvider() != null) ? service.getProvider() : service.getId();
 
         ServiceProvider provider = ServiceUtils.getServiceProvider(providerId);
 
-        String itemContent = service.getContent();
-
-        Properties props = new Properties();
-
-        try {
-            /*
-            * 2. Load properties from the content in the service provider
-            *    element of the service-jar.xml
-            */
-
-            if (provider.getContent() != null) {
-                String content = provider.getContent();
+        Properties props = getDefaultProperties(provider);
 
-                StringBufferInputStream in = new StringBufferInputStream(content);
+        Properties declaredProperties = getDeclaredProperties(service);
 
-                try {
-                    props.load(in);
-                } catch (IOException ex) {
-                    throw new OpenEJBException(ServiceUtils.messages.format("conf.0012", ex.getLocalizedMessage()));
-                }
+        props.putAll(declaredProperties);
 
-            }
-        } catch (OpenEJBException ex) {
-            throw new OpenEJBException(ServiceUtils.messages.format("conf.0013", provider.getId(), null, ex.getLocalizedMessage()));
-        }
-
-        /* 3. Load properties from the content in the Container
-        *    element of the configuration file.
-        */
-        try {
-            if (itemContent != null) {
-                String content = itemContent;
-                StringBufferInputStream in = new StringBufferInputStream(content);
-
-                try {
-                    props.load(in);
-                } catch (IOException ex) {
-                    throw new OpenEJBException(ServiceUtils.messages.format("conf.0012", ex.getLocalizedMessage()));
-                }
-
-            }
-        } catch (OpenEJBException ex) {
-            throw new OpenEJBException(ServiceUtils.messages.format("conf.0014", serviceType, serviceId, configLocation, ex.getLocalizedMessage()));
-        }
+        String serviceId = service.getId();
+        Properties serviceProperties = getSystemProperties(serviceId);
 
+        props.putAll(serviceProperties);
         Properties properties = props;
 
-        if (!provider.getProviderType().equals(serviceType)) {
-            throw new OpenEJBException(messages.format("conf.4902", service, serviceType));
+        if (!provider.getProviderType().equals(service.getClass().getSimpleName())) {
+            throw new OpenEJBException(messages.format("conf.4902", service, service.getClass().getSimpleName()));
         }
 
         T info = null;
@@ -419,7 +381,7 @@
         info.description = provider.getDescription();
         info.displayName = provider.getDisplayName();
         info.className = provider.getClassName();
-        info.id = serviceId;
+        info.id = service.getId();
         info.properties = properties;
         info.constructorArgs.addAll(parseConstructorArgs(provider));
 
@@ -431,6 +393,74 @@
 //        serviceIds.add(serviceId);
 
         return info;
+    }
+
+    private <T extends ServiceInfo>Properties getSystemProperties(String serviceId) {
+        // Override with system properties
+        Properties serviceProperties = new Properties();
+        String prefix = serviceId + ".";
+        Properties sysProps = new Properties(System.getProperties());
+        sysProps.putAll(SystemInstance.get().getProperties());
+        for (Iterator iterator1 = sysProps.entrySet().iterator(); iterator1.hasNext();) {
+            Map.Entry entry1 = (Map.Entry) iterator1.next();
+            String key = (String) entry1.getKey();
+            String value = (String) entry1.getValue();
+            if (key.startsWith(prefix)) {
+                key = key.replaceFirst(prefix, "");
+                serviceProperties.setProperty(key, value);
+            }
+        }
+        return serviceProperties;
+    }
+
+    private <T extends ServiceInfo>Properties getDeclaredProperties(Service service) throws OpenEJBException {
+        /* 3. Load properties from the content in the Container
+        *    element of the configuration file.
+        */
+        Properties declaredProperties = new Properties();
+        try {
+            if (service.getContent() != null) {
+                String content = service.getContent();
+                StringBufferInputStream in = new StringBufferInputStream(content);
+
+                try {
+                    declaredProperties.load(in);
+                } catch (IOException ex) {
+                    throw new OpenEJBException(ServiceUtils.messages.format("conf.0012", ex.getLocalizedMessage()));
+                }
+
+            }
+        } catch (OpenEJBException ex) {
+            throw new OpenEJBException(ServiceUtils.messages.format("conf.0014", service.getClass().getSimpleName(), service.getId(), configLocation, ex.getLocalizedMessage()));
+        }
+        return declaredProperties;
+    }
+
+    private <T extends ServiceInfo>Properties getDefaultProperties(ServiceProvider provider) throws OpenEJBException {
+        Properties props = new Properties();
+
+        try {
+            /*
+            * 2. Load properties from the content in the service provider
+            *    element of the service-jar.xml
+            */
+
+            if (provider.getContent() != null) {
+                String content = provider.getContent();
+
+                StringBufferInputStream in = new StringBufferInputStream(content);
+
+                try {
+                    props.load(in);
+                } catch (IOException ex) {
+                    throw new OpenEJBException(ServiceUtils.messages.format("conf.0012", ex.getLocalizedMessage()));
+                }
+
+            }
+        } catch (OpenEJBException ex) {
+            throw new OpenEJBException(ServiceUtils.messages.format("conf.0013", provider.getId(), null, ex.getLocalizedMessage()));
+        }
+        return props;
     }
 
     static Map<String, Class<? extends ContainerInfo>> containerTypes = new HashMap();