aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1461057 - in /aries/trunk/blueprint: blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/ blueprint-noosgi/src/main/java/org/apache/aries/blueprint/ext/ blueprint-noosgi/src/main/java/org/apache/aries/blueprint/services/ bl...
Date Tue, 26 Mar 2013 10:54:48 GMT
Author: gnodet
Date: Tue Mar 26 10:54:47 2013
New Revision: 1461057

URL: http://svn.apache.org/r1461057
Log:
[ARIES-1038] Add support for loading properties from a global war location

Modified:
    aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
    aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/ext/PropertyPlaceholder.java
    aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/services/ExtendedBlueprintContainer.java
    aries/trunk/blueprint/blueprint-sample-war/src/main/resources/META-INF/test.xml
    aries/trunk/blueprint/blueprint-sample-war/src/main/webapp/WEB-INF/web.xml
    aries/trunk/blueprint/blueprint-web/src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java

Modified: aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java?rev=1461057&r1=1461056&r2=1461057&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
(original)
+++ aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
Tue Mar 26 10:54:47 2013
@@ -53,21 +53,34 @@ public class BlueprintContainerImpl impl
     private final IdSpace tempRecipeIdSpace = new IdSpace();
     private BlueprintRepository repository;
     private List<Processor> processors = new ArrayList<Processor>();
+    private Map<String, String> properties;
 
     public BlueprintContainerImpl(ClassLoader loader, List<URL> resources) throws Exception
{
-        this(loader, resources,  true);
+        this(loader, resources, null, true);
     }
 
     public BlueprintContainerImpl(ClassLoader loader, List<URL> resources, boolean
init) throws Exception {
+        this(loader, resources, null, init);
+    }
+
+    public BlueprintContainerImpl(ClassLoader loader, List<URL> resources, Map<String,
String> properties, boolean init) throws Exception {
         this.loader = loader;
         this.converter = new AggregateConverter(this);
         this.componentDefinitionRegistry = new ComponentDefinitionRegistryImpl();
         this.resources = resources;
+        this.properties = properties;
         if (init) {
             init();
         }
     }
 
+    public String getProperty(String key) {
+        if (properties != null && properties.containsKey(key)) {
+            return properties.get(key);
+        }
+        return System.getProperty(key);
+    }
+
     public void init() throws Exception {
         // Parse xml resources
         Parser parser = new Parser();

Modified: aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/ext/PropertyPlaceholder.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/ext/PropertyPlaceholder.java?rev=1461057&r1=1461056&r2=1461057&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/ext/PropertyPlaceholder.java
(original)
+++ aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/ext/PropertyPlaceholder.java
Tue Mar 26 10:54:47 2013
@@ -126,7 +126,7 @@ public class PropertyPlaceholder extends
         LOGGER.debug("Retrieving property {}", val);
         Object v = null;
         if (v == null && systemProperties == SystemProperties.override) {
-            v = System.getProperty(val);
+            v = getBlueprintContainer().getProperty(val);
             if (v != null) {
                 LOGGER.debug("Found system property {} with value {}", val, v);
             }
@@ -138,7 +138,7 @@ public class PropertyPlaceholder extends
             }
         }
         if (v == null && systemProperties == SystemProperties.fallback) {
-            v = System.getProperty(val);
+            v = getBlueprintContainer().getProperty(val);
             if (v != null) {
                 LOGGER.debug("Found system property {} with value {}", val, v);
             }

Modified: aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/services/ExtendedBlueprintContainer.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/services/ExtendedBlueprintContainer.java?rev=1461057&r1=1461056&r2=1461057&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/services/ExtendedBlueprintContainer.java
(original)
+++ aries/trunk/blueprint/blueprint-noosgi/src/main/java/org/apache/aries/blueprint/services/ExtendedBlueprintContainer.java
Tue Mar 26 10:54:47 2013
@@ -41,4 +41,6 @@ public interface ExtendedBlueprintContai
 
     <T extends Processor> List<T> getProcessors(Class<T> type);
 
+    String getProperty(String key);
+
 }

Modified: aries/trunk/blueprint/blueprint-sample-war/src/main/resources/META-INF/test.xml
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-sample-war/src/main/resources/META-INF/test.xml?rev=1461057&r1=1461056&r2=1461057&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-sample-war/src/main/resources/META-INF/test.xml (original)
+++ aries/trunk/blueprint/blueprint-sample-war/src/main/resources/META-INF/test.xml Tue Mar
26 10:54:47 2013
@@ -24,13 +24,12 @@
         <bean id="converter2" class="org.apache.aries.blueprint.sample.CurrencyTypeConverter"
/>
     </type-converters>
 
-    <ext:property-placeholder>
+    <ext:property-placeholder system-properties="override">
         <ext:default-properties>
             <ext:property name="name" value="value" />
             <ext:property name="a" value="Hello " />
             <ext:property name="b" value="FooBar" />
         </ext:default-properties>
-        <ext:location>classpath:test.properties</ext:location>
     </ext:property-placeholder>
 
     <bean id="foo" class="org.apache.aries.blueprint.sample.Foo"

Modified: aries/trunk/blueprint/blueprint-sample-war/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-sample-war/src/main/webapp/WEB-INF/web.xml?rev=1461057&r1=1461056&r2=1461057&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-sample-war/src/main/webapp/WEB-INF/web.xml (original)
+++ aries/trunk/blueprint/blueprint-sample-war/src/main/webapp/WEB-INF/web.xml Tue Mar 26
10:54:47 2013
@@ -5,12 +5,17 @@
 
   <display-name>blueprint web sample</display-name>
 
-  <context-param>
-      <param-name>blueprintLocation</param-name>
-      <param-value>META-INF/test.xml</param-value>
-  </context-param>
+    <context-param>
+        <param-name>blueprintLocation</param-name>
+        <param-value>META-INF/test.xml</param-value>
+    </context-param>
+
+    <context-param>
+        <param-name>blueprintProperties</param-name>
+        <param-value>test.properties</param-value>
+    </context-param>
 
-  <listener>
+    <listener>
     <listener-class>org.apache.aries.blueprint.web.BlueprintContextListener</listener-class>
   </listener>
 

Modified: aries/trunk/blueprint/blueprint-web/src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-web/src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java?rev=1461057&r1=1461056&r2=1461057&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-web/src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java
(original)
+++ aries/trunk/blueprint/blueprint-web/src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java
Tue Mar 26 10:54:47 2013
@@ -21,10 +21,14 @@ import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 import javax.servlet.ServletException;
+import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 import org.apache.aries.blueprint.container.BlueprintContainerImpl;
 
@@ -37,6 +41,8 @@ public class BlueprintContextListener im
 
     public static final String LOCATION = "blueprintLocation";
 
+    public static final String PROPERTIES = "blueprintProperties";
+
     public static final String DEFAULT_LOCATION = "META-INF/blueprint.xml";
 
     public void contextInitialized(ServletContextEvent event) {
@@ -53,7 +59,31 @@ public class BlueprintContextListener im
                 resourcePaths.add(resources.nextElement());
             }
             servletContext.log("Loading Blueprint contexts " + resourcePaths);
-            BlueprintContainerImpl container = new BlueprintContainerImpl(classLoader, resourcePaths);
+
+            Map<String, String> properties = new HashMap<String, String>();
+            String propLocations = servletContext.getInitParameter(PROPERTIES);
+            if (propLocations != null) {
+                for (String propLoc : propLocations.split(",")) {
+                    Enumeration<URL> propUrl = classLoader.getResources(propLoc);
+                    while (propUrl.hasMoreElements()) {
+                        URL url = propUrl.nextElement();
+                        InputStream is = url.openStream();
+                        try {
+                            Properties props = new Properties();
+                            props.load(is);
+                            Enumeration names = props.propertyNames();
+                            while (names.hasMoreElements()) {
+                                String key = names.nextElement().toString();
+                                properties.put(key, props.getProperty(key));
+                            }
+                        } finally {
+                            is.close();
+                        }
+                    }
+                }
+            }
+
+            BlueprintContainerImpl container = new BlueprintContainerImpl(classLoader, resourcePaths,
properties, true);
             servletContext.setAttribute(CONTAINER_ATTRIBUTE, container);
         } catch (Exception e) {
             servletContext.log("Failed to startup blueprint container. " + e, e);



Mime
View raw message