geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r780020 - in /geronimo/sandbox/blueprint: blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ blueprint-core/src/main/resources/org/apache/geronimo/blueprint/...
Date Fri, 29 May 2009 15:57:20 GMT
Author: gnodet
Date: Fri May 29 15:57:20 2009
New Revision: 780020

URL: http://svn.apache.org/viewvc?rev=780020&view=rev
Log:
Rename and enhance the property placeholder

Added:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/PropertyPlaceholder.java
      - copied, changed from r779883, geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/SystemPropertyPlaceholder.java
Removed:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/SystemPropertyPlaceholder.java
Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/AbstractPropertyPlaceholder.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd
    geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/AbstractPropertyPlaceholder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/AbstractPropertyPlaceholder.java?rev=780020&r1=780019&r2=780020&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/AbstractPropertyPlaceholder.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/AbstractPropertyPlaceholder.java
Fri May 29 15:57:20 2009
@@ -198,6 +198,7 @@
     }
 
     protected String processString(String str) {
+        // TODO: we need to handle escapes on the prefix / suffix
         Matcher matcher = getPattern().matcher(str);
         while (matcher.find()) {
             String rep = getProperty(matcher.group(1));

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java?rev=780020&r1=780019&r2=780020&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java
Fri May 29 15:57:20 2009
@@ -20,11 +20,15 @@
 
 import java.net.URL;
 import java.util.List;
+import java.util.ArrayList;
 
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.Attr;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Comment;
+import org.w3c.dom.EntityReference;
 
 import org.osgi.service.blueprint.reflect.Metadata;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
@@ -38,7 +42,6 @@
 import org.osgi.service.blueprint.reflect.RefCollectionMetadata;
 import org.osgi.service.blueprint.container.ComponentDefinitionException;
 import org.apache.geronimo.blueprint.ParserContext;
-import org.apache.geronimo.blueprint.ComponentDefinitionRegistry;
 import org.apache.geronimo.blueprint.ExtendedRefCollectionMetadata;
 import org.apache.geronimo.blueprint.mutable.MutableBeanMetadata;
 import org.apache.geronimo.blueprint.mutable.MutableComponentMetadata;
@@ -62,15 +65,22 @@
     public static final String BLUEPRINT_NAMESPACE = "http://www.osgi.org/xmlns/blueprint/v1.0.0";
     public static final String BLUEPRINT_EXT_NAMESPACE = "http://geronimo.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0";
 
-    public static final String SYSTEM_PROPERTY_PLACEHOLDER_ELEMENT = "system-property-placeholder";
+    public static final String PROPERTY_PLACEHOLDER_ELEMENT = "property-placeholder";
     public static final String DEFAULT_PROPERTIES_ELEMENT = "default-properties";
     public static final String PROPERTY_ELEMENT = "property";
     public static final String VALUE_ELEMENT = "value";
+    public static final String LOCATION_ELEMENT = "location";
 
     public static final String ID_ATTRIBUTE = "id";
     public static final String PLACEHOLDER_PREFIX_ATTRIBUTE = "placeholder-prefix";
     public static final String PLACEHOLDER_SUFFIX_ATTRIBUTE = "placeholder-suffix";
     public static final String DEFAULTS_REF_ATTRIBUTE = "defaults-ref";
+    public static final String IGNORE_MISSING_LOCATIONS_ATTRIBUTE = "ignore-missing-locations";
+
+    public static final String SYSTEM_PROPERTIES_ATTRIBUTE = "system-properties";
+    public static final String SYSTEM_PROPERTIES_NEVER = "never";
+    public static final String SYSTEM_PROPERTIES_FALLBACK = "fallback";
+    public static final String SYSTEM_PROPERTIES_OVERRIDE = "override";
 
     public static final String PROXY_METHOD_ATTRIBUTE = "proxy-method";
     public static final String PROXY_METHOD_DEFAULT = "default";
@@ -87,8 +97,8 @@
 
     public Metadata parse(Element element, ParserContext context) {
         LOGGER.debug("Parsing element {" + element.getNamespaceURI() + "}" + element.getLocalName());
-        if (nodeNameEquals(element, SYSTEM_PROPERTY_PLACEHOLDER_ELEMENT)) {
-            return parseSystemPropertyPlaceholder(context, element);
+        if (nodeNameEquals(element, PROPERTY_PLACEHOLDER_ELEMENT)) {
+            return parsePropertyPlaceholder(context, element);
         } else {
             throw new ComponentDefinitionException("Unsupported element: " + element.getNodeName());
         }
@@ -130,12 +140,12 @@
         return component;
     }
 
-    private Metadata parseSystemPropertyPlaceholder(ParserContext context, Element element)
{
+    private Metadata parsePropertyPlaceholder(ParserContext context, Element element) {
         MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
         metadata.setProcessor(true);
         metadata.setId(getId(context, element));
         metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
-        metadata.setRuntimeClass(SystemPropertyPlaceholder.class);
+        metadata.setRuntimeClass(PropertyPlaceholder.class);
         String prefix = element.hasAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
                                     ? element.getAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
                                     : "${";
@@ -148,7 +158,16 @@
         if (defaultsRef != null) {
             metadata.addProperty("defaultProperties", createRef(context, defaultsRef));
         }
+        String ignoreMissingLocations = element.hasAttribute(IGNORE_MISSING_LOCATIONS_ATTRIBUTE)
? element.getAttribute(IGNORE_MISSING_LOCATIONS_ATTRIBUTE) : null;
+        if (ignoreMissingLocations != null) {
+            metadata.addProperty("ignoreMissingLocations", createValue(context, ignoreMissingLocations));
+        }
+        String systemProperties = element.hasAttribute(SYSTEM_PROPERTIES_ATTRIBUTE) ? element.getAttribute(SYSTEM_PROPERTIES_ATTRIBUTE)
: null;
+        if (systemProperties != null) {
+            metadata.addProperty("systemProperties", createValue(context, systemProperties));
+        }
         // Parse elements
+        List<String> locations = new ArrayList<String>();
         NodeList nl = element.getChildNodes();
         for (int i = 0; i < nl.getLength(); i++) {
             Node node = nl.item(i);
@@ -161,10 +180,15 @@
                         }
                         Metadata props = parseDefaultProperties(context, metadata, e);
                         metadata.addProperty("defaultProperties", props);
+                    } else if (nodeNameEquals(e, LOCATION_ELEMENT)) {
+                        locations.add(getTextValue(e));
                     }
                 }
             }
         }
+        if (!locations.isEmpty()) {
+            metadata.addProperty("locations", createList(context, locations));
+        }
 
         PlaceholdersUtils.validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
 
@@ -244,6 +268,18 @@
         return m;
     }
 
+    private static String getTextValue(Element element) {
+        StringBuffer value = new StringBuffer();
+        NodeList nl = element.getChildNodes();
+        for (int i = 0; i < nl.getLength(); i++) {
+            Node item = nl.item(i);
+            if ((item instanceof CharacterData && !(item instanceof Comment)) ||
item instanceof EntityReference) {
+                value.append(item.getNodeValue());
+            }
+        }
+        return value.toString();
+    }
+
     private static boolean nodeNameEquals(Node node, String name) {
         return (name.equals(node.getNodeName()) || name.equals(node.getLocalName()));
     }

Copied: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/PropertyPlaceholder.java
(from r779883, geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/SystemPropertyPlaceholder.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/PropertyPlaceholder.java?p2=geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/PropertyPlaceholder.java&p1=geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/SystemPropertyPlaceholder.java&r1=779883&r2=780020&rev=780020&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/SystemPropertyPlaceholder.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/PropertyPlaceholder.java
Fri May 29 15:57:20 2009
@@ -19,6 +19,11 @@
 package org.apache.geronimo.blueprint.ext;
 
 import java.util.Map;
+import java.util.List;
+import java.util.Properties;
+import java.net.URL;
+import java.io.InputStream;
+import java.io.IOException;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -30,11 +35,21 @@
  * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
  * @version $Rev: 766508 $, $Date: 2009-04-19 22:09:27 +0200 (Sun, 19 Apr 2009) $
  */
-public class SystemPropertyPlaceholder extends AbstractPropertyPlaceholder {
+public class PropertyPlaceholder extends AbstractPropertyPlaceholder {
 
-    private static final Logger LOGGER = LoggerFactory.getLogger(SystemPropertyPlaceholder.class);
+    public enum SystemProperties {
+        never,
+        fallback,
+        override
+    }
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(PropertyPlaceholder.class);
 
     private Map defaultProperties;
+    private Properties properties;
+    private List<URL> locations;
+    private boolean ignoreMissingLocations;
+    private SystemProperties systemProperties = SystemProperties.fallback;
 
     public Map getDefaultProperties() {
         return defaultProperties;
@@ -44,22 +59,85 @@
         this.defaultProperties = defaultProperties;
     }
 
-    protected String getProperty(String val) {
-        LOGGER.debug("Retrieving system property {}", val);
-        Object v = System.getProperty(val);
-        if (v != null) {
-            LOGGER.debug("Found system property {}", v);
-        } else {
-            LOGGER.debug("System property not found {}", v);
-            if (defaultProperties != null) {
-                v = defaultProperties.get(val);
-                if (v != null) {
-                    LOGGER.debug("Retrieved value from defaults {}", v);
-                } else {
-                    throw new ComponentDefinitionException("Property not found: " + val);
+    public List<URL> getLocations() {
+        return locations;
+    }
+
+    public void setLocations(List<URL> locations) {
+        this.locations = locations;
+    }
+
+    public boolean isIgnoreMissingLocations() {
+        return ignoreMissingLocations;
+    }
+
+    public void setIgnoreMissingLocations(boolean ignoreMissingLocations) {
+        this.ignoreMissingLocations = ignoreMissingLocations;
+    }
+
+    public SystemProperties getSystemProperties() {
+        return systemProperties;
+    }
+
+    public void setSystemProperties(SystemProperties systemProperties) {
+        this.systemProperties = systemProperties;
+    }
+
+    public void init() throws Exception {
+        properties = new Properties();
+        if (locations != null) {
+            for (URL url : locations) {
+                InputStream is = null;
+                try {
+                    is = url.openStream();
+                } catch (IOException e) {
+                    if (ignoreMissingLocations) {
+                        LOGGER.info("Unable to load properties from url " + url, e);
+                    } else {
+                        throw e;
+                    }
+                }
+                if (is != null) {
+                    try {
+                        properties.load(is);
+                    } finally {
+                        is.close();
+                    }
                 }
             }
         }
+    }
+
+    protected String getProperty(String val) {
+        LOGGER.debug("Retrieving property {}", val);
+        Object v = null;
+        if (v == null && systemProperties == SystemProperties.override) {
+            v = System.getProperty(val);
+            if (v != null) {
+                LOGGER.debug("Found system property {} with value {}", val, v);
+            }
+        }
+        if (v == null && properties != null) {
+            v = properties.getProperty(val);
+            if (v != null) {
+                LOGGER.debug("Found property {} from locations with value {}", val, v);
+            }
+        }
+        if (v == null && systemProperties == SystemProperties.fallback) {
+            v = System.getProperty(val);
+            if (v != null) {
+                LOGGER.debug("Found system property {} with value {}", val, v);
+            }
+        }
+        if (v == null && defaultProperties != null) {
+            v = defaultProperties.get(val);
+            if (v != null) {
+                LOGGER.debug("Retrieved property {} value from defaults {}", val, v);
+            }
+        }
+        if (v == null) {
+            LOGGER.debug("Property {} not found", val);
+        }
         return v != null ? v.toString() : null;
     }
 

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java?rev=780020&r1=780019&r2=780020&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java
Fri May 29 15:57:20 2009
@@ -22,6 +22,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.LinkedHashMap;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 
@@ -45,7 +46,8 @@
     private final List<Target> typeConverters;
 
     public ComponentDefinitionRegistryImpl() {
-        components = new ConcurrentHashMap<String, ComponentMetadata>();
+        // Use a linked hash map to keep the declaration order 
+        components = Collections.synchronizedMap(new LinkedHashMap<String, ComponentMetadata>());
         typeConverters = new CopyOnWriteArrayList<Target>();
     }
 

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd?rev=780020&r1=780019&r2=780020&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd
Fri May 29 15:57:20 2009
@@ -29,7 +29,7 @@
 
     <!-- property placeholder -->
 
-    <xsd:element name="system-property-placeholder" type="TpropertyPlaceholder"/>
+    <xsd:element name="property-placeholder" type="TpropertyPlaceholder"/>
 
     <xsd:complexType name="TpropertyPlaceholder">
         <xsd:complexContent>
@@ -37,10 +37,21 @@
                 <xsd:sequence>
                     <!-- nested properties declaration -->
                     <xsd:element name="default-properties" type="TdefaultProperties" minOccurs="0"
maxOccurs="1"/>
+                    <xsd:element name="location" minOccurs="0" maxOccurs="unbounded" type="xsd:string"/>
                 </xsd:sequence>
                 <xsd:attribute name="placeholder-prefix" type="xsd:string" use="optional"
default="${"/>
                 <xsd:attribute name="placeholder-suffix" type="xsd:string" use="optional"
default="}"/>
                 <xsd:attribute name="defaults-ref" type="bp:Tidref" use="optional"/>
+                <xsd:attribute name="ignore-missing-locations" type="xsd:boolean" use="optional"
default="false"/>
+                <xsd:attribute name="system-properties" use="optional" default="fallback">
+                    <xsd:simpleType>
+                        <xsd:restriction base="xsd:NMTOKEN">
+                            <xsd:enumeration value="never"/>
+                            <xsd:enumeration value="fallback"/>
+                            <xsd:enumeration value="override"/>
+                        </xsd:restriction>
+                    </xsd:simpleType>
+                </xsd:attribute>
             </xsd:extension>
         </xsd:complexContent>
     </xsd:complexType>

Modified: geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml?rev=780020&r1=780019&r2=780020&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
(original)
+++ geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
Fri May 29 15:57:20 2009
@@ -12,7 +12,12 @@
 
     </type-converters>
 
-    <ext:system-property-placeholder placeholder-prefix="$[" placeholder-suffix="]"/>
+    <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]" ignore-missing-locations="true"
system-properties="override">
+        <ext:default-properties>
+            <ext:property name="name" value="value"/>
+        </ext:default-properties>
+        <ext:location>file://url</ext:location>
+    </ext:property-placeholder>
 
     <cm:managed-service-factory id="managed-service-factory" factory-pid="blueprint-sample-managed-service-factory"
             interface="org.apache.geronimo.blueprint.sample.Foo">



Mime
View raw message