geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r769635 - in /geronimo/sandbox/blueprint/blueprint-core/src: main/java/org/apache/geronimo/blueprint/context/ main/java/org/apache/geronimo/blueprint/convert/ test/java/org/apache/geronimo/blueprint/ test/java/org/apache/geronimo/blueprint/...
Date Wed, 29 Apr 2009 03:28:51 GMT
Author: gawor
Date: Wed Apr 29 03:28:45 2009
New Revision: 769635

URL: http://svn.apache.org/viewvc?rev=769635&view=rev
Log:
collections value-type attribute is the default type for collection elements but individual
elements can specify a totaly different type

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/ValueRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/convert/ConversionServiceImpl.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/convert/ConversionServiceImplTest.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=769635&r1=769634&r2=769635&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
Wed Apr 29 03:28:45 2009
@@ -273,7 +273,8 @@
         } else if (v instanceof ValueMetadata) {
             ValueMetadata stringValue = (ValueMetadata) v;
             Class type = loadClass(stringValue.getTypeName());
-            return new ValueRecipe(getConversionService(), stringValue, type, groupingType);
+            type = (type == null) ? groupingType : type;
+            return new ValueRecipe(getConversionService(), stringValue, type);
         } else if (v instanceof RefMetadata) {
             String componentName = ((RefMetadata) v).getComponentId();
             return new ReferenceRecipe(componentName);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ValueRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ValueRecipe.java?rev=769635&r1=769634&r2=769635&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ValueRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ValueRecipe.java
Wed Apr 29 03:28:45 2009
@@ -37,43 +37,32 @@
     private ConversionService conversionService;
     private ValueMetadata value;
     private Class type;
-    private Class groupingType;
 
-    public ValueRecipe(ConversionService conversionService, ValueMetadata value, Class type,
Class groupingType) {
+    public ValueRecipe(ConversionService conversionService, ValueMetadata value, Class type)
{
         this.conversionService = conversionService;
         this.value = value;
         this.type = type;
-        this.groupingType = groupingType;
     }
 
-    private static Class determineType(Class type, Class groupingType, Class defaultType)
throws RuntimeException {
-        if (type != null) {
-            if (groupingType == null || groupingType.isAssignableFrom(type)) {
-                return type;
-            } else {
-                throw new RuntimeException(type.getName() + " cannot be assigned to " + groupingType.getName());
-            }
-        } else if (groupingType != null) {
-            return groupingType;
-        } else {
-            return defaultType;
-        }
+    private static Class determineType(Class type, Type defaultType) {
+        // TODO: check if type is assignable from defaultType?
+        return (type != null) ? type : RecipeHelper.toClass(defaultType);
     }
 
     @Override
     protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException
{
-        Class myType = determineType(type, groupingType, RecipeHelper.toClass(expectedType));
+        Class myType = determineType(type, expectedType);
 
         try {
             return conversionService.convert(value.getStringValue(), myType);
-        } catch (Exception e) {
+        } catch (Exception e) {            
             throw new ConstructionException(e);
         }
     }
 
     public boolean canCreate(Type expectedType) {
         // XXX: this is expensive but that's what spec wants
-        Class myType = determineType(type, groupingType, RecipeHelper.toClass(expectedType));
+        Class myType = determineType(type, expectedType);
         
         try {
             conversionService.convert(value.getStringValue(), myType);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/convert/ConversionServiceImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/convert/ConversionServiceImpl.java?rev=769635&r1=769634&r2=769635&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/convert/ConversionServiceImpl.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/convert/ConversionServiceImpl.java
Wed Apr 29 03:28:45 2009
@@ -70,6 +70,8 @@
     public Object convert(Object fromValue, Class toType) throws Exception {
         if (toType.isInstance(fromValue)) {
             return fromValue;
+        } else if (Class.class == toType) {
+            return fromValue.getClass();
         }
         Object value = doConvert(fromValue, toType);        
         if (value == null) {

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=769635&r1=769634&r2=769635&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
Wed Apr 29 03:28:45 2009
@@ -81,6 +81,7 @@
         assertNotNull(pojoa.getSet());
         assertTrue(pojoa.getSet().contains("set value"));
         assertTrue(pojoa.getSet().contains(pojob));
+        assertTrue(pojoa.getSet().contains(URI.create("http://geronimo.apache.org")));
         
         assertNotNull(pojoa.getMap());
         assertEquals("val", pojoa.getMap().get("key"));
@@ -102,10 +103,11 @@
         assertEquals(100, pojoa.getIntArray()[2]);
         
         assertNotNull(pojoa.getNumberArray());
-        assertEquals(3, pojoa.getNumberArray().length);
+        assertEquals(4, pojoa.getNumberArray().length);
         assertEquals(new Integer(1), pojoa.getNumberArray()[0]);
         assertEquals(new BigInteger("50"), pojoa.getNumberArray()[1]);
         assertEquals(new Long(100), pojoa.getNumberArray()[2]);
+        assertEquals(new Integer(200), pojoa.getNumberArray()[3]);
         
         // test init-method
         assertEquals(true, pojob.getInitCalled());

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/convert/ConversionServiceImplTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/convert/ConversionServiceImplTest.java?rev=769635&r1=769634&r2=769635&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/convert/ConversionServiceImplTest.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/convert/ConversionServiceImplTest.java
Wed Apr 29 03:28:45 2009
@@ -123,6 +123,11 @@
         assertEquals(new Locale("de", "", "POSIX"), result);
     }
     
+    public void testConvertWeird() throws Exception {
+        assertEquals(this, service.convert(this, ConversionServiceImplTest.class));
+        assertEquals(ConversionServiceImplTest.class, service.convert(this, Class.class));
+    }
+    
     public void testCustom() throws Exception {
         ConversionServiceImpl s = new ConversionServiceImpl();
         s.registerConverter(new RegionConverter());

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=769635&r1=769634&r2=769635&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 Wed Apr 29
03:28:45 2009
@@ -38,9 +38,10 @@
             </map>
         </property>
         <property name="set">
-            <set>
-                <value>set value</value>
+            <set value-type="java.net.URI">
+                <value type="java.lang.String">set value</value>
                 <ref component="pojoB" />
+                <value>http://geronimo.apache.org</value>
             </set>
         </property>
         <property name="list">
@@ -75,10 +76,11 @@
             </array>
         </property>
         <property name="numberArray">
-            <array>
-                <value type="java.lang.Integer">1</value>
+            <array value-type="java.lang.Integer">
+                <value>1</value>
                 <value type="java.math.BigInteger">50</value>
                 <value type="java.lang.Long">100</value>
+                <value>200</value>
             </array>
         </property>
         <property name="number">



Mime
View raw message