geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r768639 - in /geronimo/sandbox/blueprint/blueprint-core/src: main/java/org/apache/geronimo/blueprint/context/ test/java/org/apache/geronimo/blueprint/ test/java/org/apache/geronimo/blueprint/pojos/ test/resources/
Date Sun, 26 Apr 2009 03:47:41 GMT
Author: gawor
Date: Sun Apr 26 03:47:40 2009
New Revision: 768639

URL: http://svn.apache.org/viewvc?rev=768639&view=rev
Log:
fix parsing and injection of properties

Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Instanciator.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoA.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Instanciator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Instanciator.java?rev=768639&r1=768638&r2=768639&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Instanciator.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Instanciator.java
Sun Apr 26 03:47:40 2009
@@ -26,6 +26,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 import java.util.Comparator;
 
@@ -346,18 +347,14 @@
             }
             return mr;
         } else if (v instanceof PropsMetadata) {
-            // TODO
-            /*
             PropsMetadata mapValue = (PropsMetadata) v;
-            MapRecipe mr = new MapRecipe(HashMap.class);
+            MapRecipe mr = new MapRecipe(Properties.class);
             for (MapEntry entry : mapValue.getEntries()) {
-                Object key = getValue(entry.getKey(), keyType);
-                Object val = getValue(entry.getValue(), valueType);
+                Object key = getValue(entry.getKey(), String.class);
+                Object val = getValue(entry.getValue(), String.class);
                 mr.put(key, val);
             }
             return mr;
-            */
-            return null;
         } else if (v instanceof IdRefMetadata) {
             return ((IdRefMetadata) v).getComponentId();
         } else {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java?rev=768639&r1=768638&r2=768639&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java
Sun Apr 26 03:47:40 2009
@@ -530,7 +530,30 @@
 
     private PropsMetadata parseProps(Element element) {
         // Parse elements
-        return new PropsMetadataImpl(parseMap(element, null).getEntries());
+        List<MapEntry> entries = new ArrayList<MapEntry>();
+        NodeList nl = element.getChildNodes();
+        for (int i = 0; i < nl.getLength(); i++) {
+            Node node = nl.item(i);
+            if (node instanceof Element) {
+                Element e = (Element) node;
+                if (isBlueprintNamespace(e.getNamespaceURI()) && nodeNameEquals(e,
PROP_ELEMENT)) {
+                    NonNullMetadata keyValue = null;
+                    if (e.hasAttribute(KEY_ATTRIBUTE)) {
+                        keyValue = new ValueMetadataImpl(e.getAttribute(KEY_ATTRIBUTE));
+                    } else {
+                        throw new RuntimeException("key attribute is required");
+                    }
+                    Metadata valValue = null;
+                    if (e.hasAttribute(VALUE_ATTRIBUTE)) {
+                        valValue = new ValueMetadataImpl(e.getAttribute(VALUE_ATTRIBUTE));
+                    } else {
+                        throw new RuntimeException("value attribute is required");
+                    }
+                    entries.add(new MapEntryImpl(keyValue, valValue));
+                }
+            }
+        }
+        return new PropsMetadataImpl(entries);
     }
 
     private MapMetadata parseMap(Element element, ComponentMetadata enclosingComponent) {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java?rev=768639&r1=768638&r2=768639&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java
Sun Apr 26 03:47:40 2009
@@ -84,6 +84,10 @@
         assertEquals("val", pojoa.getMap().get("key"));
         assertEquals(pojob, pojoa.getMap().get(pojob));      
         
+        assertNotNull(pojoa.getProps());
+        assertEquals("value1", pojoa.getProps().get("key1"));
+        assertEquals("value2", pojoa.getProps().get("2"));
+        
         assertNotNull(pojoa.getNumber());
         assertEquals(new BigInteger("10"), pojoa.getNumber());
         

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoA.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoA.java?rev=768639&r1=768638&r2=768639&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoA.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoA.java
Sun Apr 26 03:47:40 2009
@@ -20,6 +20,7 @@
 
 import java.util.Map;
 import java.util.List;
+import java.util.Properties;
 import java.util.Set;
 
 public class PojoA implements InterfaceA {
@@ -29,6 +30,7 @@
     private Set set;
     private Map map;
     private Number number;
+    private Properties props;
     
     private Object[] array;
     private int[] intArray;
@@ -69,6 +71,14 @@
         this.map = map;
     }
 
+    public Properties getProps() {
+        return props;
+    }
+    
+    public void setProps(Properties props) {
+        this.props = props;
+    }
+    
     public void setPojob(PojoB pojob) {
         this.pojob = pojob;
     }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml?rev=768639&r1=768638&r2=768639&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml Sun Apr 26
03:47:40 2009
@@ -50,6 +50,12 @@
                 <ref component="pojoC" />
             </list>
         </property>
+        <property name="props">
+            <props>
+                <prop key="key1" value="value1" />
+                <prop key="2" value="value2" />
+            </props>
+        </property>
         <property name="array">
             <array>
                 <value>list value</value>
@@ -57,7 +63,7 @@
                 <value type="java.lang.Integer">55</value>
                 <value type="java.net.URI">http://geronimo.apache.org</value>
             </array>
-        </property>
+        </property>        
         <property name="intArray">
             <array>
                 <value>1</value>



Mime
View raw message