geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r773384 - in /geronimo/sandbox/blueprint/blueprint-core/src: main/java/org/apache/geronimo/blueprint/context/ main/java/org/apache/geronimo/blueprint/utils/ test/java/org/apache/geronimo/blueprint/ test/java/org/apache/geronimo/blueprint/po...
Date Sun, 10 May 2009 18:36:27 GMT
Author: gawor
Date: Sun May 10 18:36:26 2009
New Revision: 773384

URL: http://svn.apache.org/viewvc?rev=773384&view=rev
Log:
support generics

Added:
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoGenerics.java
  (with props)
    geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-generics.xml   (with
props)
Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatch.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java?rev=773384&r1=773383&r2=773384&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java
Sun May 10 18:36:26 2009
@@ -175,7 +175,7 @@
     
     private List<Object> getFinalArguments(ArgumentsMatch match, boolean refAllowed)
throws ConstructionException {
         List<Object> arguments = match.getArguments();
-        Class[] parameterTypes = match.getParameterTypes();
+        Type[] parameterTypes = match.getGenericParameterTypes();
 
         List<Object> args = new ArrayList<Object>();
         for (int i = 0; i < arguments.size(); i++) {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatch.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatch.java?rev=773384&r1=773383&r2=773384&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatch.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatch.java
Sun May 10 18:36:26 2009
@@ -20,6 +20,7 @@
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 import java.util.List;
 
 /**
@@ -62,6 +63,16 @@
         }
     }
     
+    public Type[] getGenericParameterTypes() {
+        if (constructor != null) {
+            return constructor.getGenericParameterTypes();
+        } else if (method != null) {
+            return method.getGenericParameterTypes();
+        } else {
+            return null;
+        }
+    }
+    
     public List<Object> getArguments() {
         return arguments;
     }

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=773384&r1=773383&r2=773384&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 May 10 18:36:26 2009
@@ -20,8 +20,12 @@
 
 import java.math.BigInteger;
 import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.geronimo.blueprint.CallbackTracker.Callback;
 import org.apache.geronimo.blueprint.context.BlueprintObjectInstantiator;
@@ -32,6 +36,7 @@
 import org.apache.geronimo.blueprint.pojos.Multiple;
 import org.apache.geronimo.blueprint.pojos.PojoA;
 import org.apache.geronimo.blueprint.pojos.PojoB;
+import org.apache.geronimo.blueprint.pojos.PojoGenerics;
 import org.apache.xbean.recipe.Repository;
 import org.osgi.framework.ServiceRegistration;
 
@@ -276,6 +281,57 @@
         assertEquals(integerValue, ((Multiple)obj).getInteger());        
     }
 
+    public void testGenerics() throws Exception {
+        ComponentDefinitionRegistryImpl registry = parse("/test-generics.xml");
+        RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
+        Repository repository = i.createRepository(registry);
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(repository);
+        
+        List<Integer> expectedList = new ArrayList<Integer>();
+        expectedList.add(new Integer(10));
+        expectedList.add(new Integer(20));
+        expectedList.add(new Integer(50));
+        
+        Set<Long> expectedSet = new HashSet<Long>();
+        expectedSet.add(new Long(1000));
+        expectedSet.add(new Long(2000));
+        expectedSet.add(new Long(5000));
+        
+        Map<Short, Boolean> expectedMap = new HashMap<Short, Boolean>();
+        expectedMap.put(new Short((short)1), Boolean.TRUE);
+        expectedMap.put(new Short((short)2), Boolean.FALSE);
+        expectedMap.put(new Short((short)5), Boolean.TRUE);
+        
+        Object obj;
+        PojoGenerics pojo;
+        
+        obj = graph.create("method");
+        assertTrue(obj instanceof PojoGenerics);
+        pojo = (PojoGenerics) obj;
+        
+        assertEquals(expectedList, pojo.getList());
+        assertEquals(expectedSet, pojo.getSet());
+        assertEquals(expectedMap, pojo.getMap());
+        
+        obj = graph.create("constructorList");
+        assertTrue(obj instanceof PojoGenerics);
+        pojo = (PojoGenerics) obj;
+        
+        assertEquals(expectedList, pojo.getList());
+        
+        obj = graph.create("constructorSet");
+        assertTrue(obj instanceof PojoGenerics);
+        pojo = (PojoGenerics) obj;
+        
+        assertEquals(expectedSet, pojo.getSet());
+        
+        obj = graph.create("constructorMap");
+        assertTrue(obj instanceof PojoGenerics);
+        pojo = (PojoGenerics) obj;
+        
+        assertEquals(expectedMap, pojo.getMap());
+    }
+    
     public void testCircular() throws Exception {
         ComponentDefinitionRegistryImpl registry = parse("/test-circular.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));

Added: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoGenerics.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoGenerics.java?rev=773384&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoGenerics.java
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoGenerics.java
Sun May 10 18:36:26 2009
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.blueprint.pojos;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class PojoGenerics {
+
+    private List<Integer> list;
+    private Set<Long> set;
+    private Map<Short, Boolean> map;
+
+    public PojoGenerics() {
+    }
+    
+    public PojoGenerics(List<Integer> list) {
+        this.list = list;        
+    }
+    
+    public PojoGenerics(Set<Long> set) {
+        this.set = set;        
+    }
+    
+    public PojoGenerics(Map<Short, Boolean> map) {
+        this.map = map;
+    }
+
+    public List<Integer> getList() {
+        return list;
+    }
+
+    public void setList(List<Integer> list) {
+        this.list = list;
+    }
+
+    public Set<Long> getSet() {
+        return set;
+    }
+
+    public void setSet(Set<Long> set) {
+        this.set = set;
+    }
+
+    public Map<Short, Boolean> getMap() {
+        return map;
+    }
+
+    public void setMap(Map<Short, Boolean> map) {
+        this.map = map;
+    }
+     
+    public void start() {
+        System.out.println("Starting component " + this);
+    }
+
+    public void stop() {
+        System.out.println("Stopping component " + this);
+    }
+}

Propchange: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoGenerics.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoGenerics.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoGenerics.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-generics.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-generics.xml?rev=773384&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-generics.xml (added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-generics.xml Sun May
10 18:36:26 2009
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+            default-availability="mandatory"
+            default-init-method = "init"
+            default-destroy-method = "destroy" >
+
+    <bean id="method" class="org.apache.geronimo.blueprint.pojos.PojoGenerics">
+        <property name="list">
+            <list>
+                <value>10</value>
+                <value>20</value>
+                <value>50</value>
+            </list>
+        </property>
+        <property name="set">
+            <set>
+                <value>1000</value>
+                <value>2000</value>
+                <value>5000</value>
+            </set>
+        </property>
+        <property name="map">
+            <map>
+                <entry key="1" value="yes"/>
+                <entry key="2" value="no" />
+                <entry>
+                     <key><value>5</value></key>
+                     <value>true</value>
+                </entry>
+            </map>
+        </property>        
+    </bean>
+    
+    <bean id="constructorList" class="org.apache.geronimo.blueprint.pojos.PojoGenerics">
+        <argument>
+            <list>
+                <value>10</value>
+                <value>20</value>
+                <value>50</value>
+            </list>
+        </argument>      
+    </bean>
+    
+    <bean id="constructorSet" class="org.apache.geronimo.blueprint.pojos.PojoGenerics">
+       <argument>
+            <set>
+                <value>1000</value>
+                <value>2000</value>
+                <value>5000</value>
+            </set>
+        </argument>
+    </bean>
+    
+    <bean id="constructorMap" class="org.apache.geronimo.blueprint.pojos.PojoGenerics">
+        <argument>
+            <map>
+                <entry key="1" value="yes"/>
+                <entry key="2" value="no" />
+                <entry>
+                     <key><value>5</value></key>
+                     <value>true</value>
+                </entry>
+            </map>
+        </argument>
+    </bean>
+    
+    
+</blueprint>

Propchange: geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-generics.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-generics.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-generics.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message