geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r781047 - in /geronimo/sandbox/blueprint: blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/ blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/ blueprint-sample/src/main/resources/OSGI-INF/blueprint/
Date Tue, 02 Jun 2009 14:47:33 GMT
Author: gnodet
Date: Tue Jun  2 14:47:33 2009
New Revision: 781047

URL: http://svn.apache.org/viewvc?rev=781047&view=rev
Log:
make CmPropertyPlaceholder extends PropertyPlaceholder and add some custom attributes / elements
to define those in the schema

Modified:
    geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java
    geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmPropertyPlaceholder.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-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java?rev=781047&r1=781046&r2=781047&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java
Tue Jun  2 14:47:33 2009
@@ -30,6 +30,7 @@
 import org.apache.geronimo.blueprint.container.ParserContextImpl;
 import org.apache.geronimo.blueprint.container.ServiceListener;
 import org.apache.geronimo.blueprint.ext.PlaceholdersUtils;
+import org.apache.geronimo.blueprint.ext.ExtNamespaceHandler;
 import org.apache.geronimo.blueprint.mutable.MutableBeanMetadata;
 import org.apache.geronimo.blueprint.mutable.MutableCollectionMetadata;
 import org.apache.geronimo.blueprint.mutable.MutableComponentMetadata;
@@ -57,6 +58,9 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Comment;
+import org.w3c.dom.EntityReference;
 
 /**
  * Namespace handler for the Config Admin service.
@@ -171,7 +175,19 @@
         if (defaultsRef != null) {
             metadata.addProperty("defaultProperties", createRef(context, defaultsRef));
         }
+        String ignoreMissingLocations = element.hasAttributeNS(ExtNamespaceHandler.BLUEPRINT_EXT_NAMESPACE,
ExtNamespaceHandler.IGNORE_MISSING_LOCATIONS_ATTRIBUTE)
+                ? element.getAttributeNS(ExtNamespaceHandler.BLUEPRINT_EXT_NAMESPACE, ExtNamespaceHandler.IGNORE_MISSING_LOCATIONS_ATTRIBUTE)
: null;
+        if (ignoreMissingLocations != null) {
+            metadata.addProperty("ignoreMissingLocations", createValue(context, ignoreMissingLocations));
+        }
+        String systemProperties = element.hasAttributeNS(ExtNamespaceHandler.BLUEPRINT_EXT_NAMESPACE,
ExtNamespaceHandler.SYSTEM_PROPERTIES_ATTRIBUTE)
+                ? element.getAttributeNS(ExtNamespaceHandler.BLUEPRINT_EXT_NAMESPACE, ExtNamespaceHandler.SYSTEM_PROPERTIES_ATTRIBUTE)
: null;
+        if (systemProperties == null) {
+            systemProperties = ExtNamespaceHandler.SYSTEM_PROPERTIES_NEVER;
+        }
+        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);
@@ -185,10 +201,17 @@
                         Metadata props = parseDefaultProperties(context, metadata, e);
                         metadata.addProperty("defaultProperties", props);
                     }
+                } else if (ExtNamespaceHandler.BLUEPRINT_EXT_NAMESPACE.equals(e.getNamespaceURI()))
{
+                    if (nodeNameEquals(e, ExtNamespaceHandler.LOCATION_ELEMENT)) {
+                        locations.add(getTextValue(e));
+                    }
                 }
             }
         }
-        
+        if (!locations.isEmpty()) {
+            metadata.addProperty("locations", createList(context, locations));
+        }
+
         PlaceholdersUtils.validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
         
         return metadata;
@@ -428,6 +451,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()));
     }

Modified: geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmPropertyPlaceholder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmPropertyPlaceholder.java?rev=781047&r1=781046&r2=781047&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmPropertyPlaceholder.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmPropertyPlaceholder.java
Tue Jun  2 14:47:33 2009
@@ -23,6 +23,7 @@
 import java.util.Map;
 
 import org.apache.geronimo.blueprint.ext.AbstractPropertyPlaceholder;
+import org.apache.geronimo.blueprint.ext.PropertyPlaceholder;
 import org.osgi.service.blueprint.container.BlueprintContainer;
 import org.osgi.service.blueprint.container.ComponentDefinitionException;
 import org.osgi.service.cm.Configuration;
@@ -33,20 +34,16 @@
 /**
  * TODO: javadoc
  *
- * TODO: make CmPropertyPlaceholder extends PropertyPlaceholder and add some custom attributes
/ elements to
- *   define those in the schema
- *
  * @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 CmPropertyPlaceholder extends AbstractPropertyPlaceholder {
+public class CmPropertyPlaceholder extends PropertyPlaceholder {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(CmPropertyPlaceholder.class);
 
     private BlueprintContainer blueprintContainer;
     private ConfigurationAdmin configAdmin; 
     private String persistentId;
-    private Map defaultProperties;
 
     public BlueprintContainer getBlueprintContainer() {
         return blueprintContainer;
@@ -72,14 +69,6 @@
         this.persistentId = persistentId;
     }
 
-    public Map getDefaultProperties() {
-        return defaultProperties;
-    }
-
-    public void setDefaultProperties(Map defaultProperties) {
-        this.defaultProperties = defaultProperties;
-    }
-
     protected String getProperty(String val) {
         LOGGER.debug("Retrieving property value {} from configuration with pid {}", val,
persistentId);
         Configuration config = null;
@@ -102,13 +91,8 @@
                 LOGGER.debug("No dictionary available from configuration");
             }
         }
-        if (v == null && defaultProperties != null) {
-            v = defaultProperties.get(val);           
-            if (v != null) {
-                LOGGER.debug("Retrieved value from defaults {}", v);
-            } else {
-                throw new ComponentDefinitionException("Property not found: " + val);
-            }
+        if (v == null) {
+            v = super.getProperty(val);
         }
         return v != null ? v.toString() : null;
     }

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=781047&r1=781046&r2=781047&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
Tue Jun  2 14:47:33 2009
@@ -83,6 +83,8 @@
         </xsd:simpleType>
     </xsd:attribute>
 
+    <!-- role -->
+
     <xsd:attribute name="role">
         <xsd:simpleType>
             <xsd:restriction>
@@ -99,4 +101,18 @@
         </xsd:simpleType>
     </xsd:attribute>
 
+    <!-- CM property placeholder extenstion -->
+
+    <xsd:element name="location" type="xsd:string"/>
+    <xsd:attribute name="ignore-missing-locations" type="xsd:boolean" default="false"/>
+    <xsd:attribute name="system-properties" 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:schema>

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=781047&r1=781046&r2=781047&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
Tue Jun  2 14:47:33 2009
@@ -20,7 +20,8 @@
     </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">
+            interface="org.apache.geronimo.blueprint.sample.Foo"
+            ext:system-properties="fallback">
         <service-properties>
             <entry key="key1" value="value1"/>
         </service-properties>



Mime
View raw message