geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r769947 - 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/convert/
Date Wed, 29 Apr 2009 21:33:29 GMT
Author: gawor
Date: Wed Apr 29 21:33:27 2009
New Revision: 769947

URL: http://svn.apache.org/viewvc?rev=769947&view=rev
Log:
additonal conversion and injection fixes

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/context/TypedRecipe.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/convert/ConversionServiceImplTest.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=769947&r1=769946&r2=769947&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
Wed Apr 29 21:33:27 2009
@@ -140,7 +140,12 @@
         List<Object> args = new ArrayList<Object>();
         for (int i = 0; beanArguments != null && i < beanArguments.size(); i++)
{
             BeanArgument argument = beanArguments.get(i);
-            Class type = loadClass(argument.getValueType());
+            String valueType = argument.getValueType();
+            if (valueType == null) {
+                // check if valueType is set on the <value/> element
+                valueType = getValueType(argument.getValue());
+            }            
+            Class type = loadClass(valueType);
             Object obj = arguments.get(i);
             if (type != null) {
                 obj = new TypedRecipe(blueprintContext.getConversionService(), type, obj);
@@ -171,6 +176,14 @@
         return true;
     }
     
+    private String getValueType(Metadata metadata) {
+        if (metadata instanceof ValueMetadata) {
+            ValueMetadata stringValue = (ValueMetadata) metadata;
+            return stringValue.getTypeName();
+        }
+        return null;
+    }
+    
     private Class loadClass(String typeName) throws ConstructionException {
         if (typeName == null) {
             return null;

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/TypedRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/TypedRecipe.java?rev=769947&r1=769946&r2=769947&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/TypedRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/TypedRecipe.java
Wed Apr 29 21:33:27 2009
@@ -44,7 +44,7 @@
     
     public TypedRecipe(ConversionService conversionService, Class type, Object value) {
         this.conversionService = conversionService;
-        this.type = (type == null) ? Object.class : type;
+        this.type = type;
         this.value = value;
     }
 
@@ -70,7 +70,20 @@
 
     public boolean canCreate(Type expectedType) {
         Class expectedClass = RecipeHelper.toClass(expectedType);
-        return expectedClass == type;
+        if (type == null) {
+            if (value == null) {
+                return true;
+            } else if (value instanceof Recipe) {
+                return ((Recipe) value).canCreate(expectedType);
+            } else {
+                return value.getClass().isAssignableFrom(expectedClass);
+            }
+        } else {
+            return expectedClass == type;
+        }
     }
 
+    public String toString() {
+        return "TypedRecipe: " + type + " " + value;
+    }
 }

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=769947&r1=769946&r2=769947&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 21:33:27 2009
@@ -71,5 +71,9 @@
             return false;
         }
     }
+    
+    public String toString() {
+        return "ValueRecipe: " + type + " " + value.getStringValue();
+    }
 
 }

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=769947&r1=769946&r2=769947&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 21:33:27 2009
@@ -30,6 +30,7 @@
 import java.util.regex.Pattern;
 
 import org.apache.geronimo.blueprint.context.BlueprintContextImpl;
+import org.apache.xbean.recipe.RecipeHelper;
 import org.osgi.service.blueprint.convert.ConversionService;
 import org.osgi.service.blueprint.convert.Converter;
 
@@ -74,7 +75,7 @@
     }
     
     public Object convert(Object fromValue, Class toType) throws Exception {
-        if (toType.isInstance(fromValue)) {
+        if (RecipeHelper.isInstance(toType, fromValue)) {
             return fromValue;
         }
         Object value = doConvert(fromValue, toType);        

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=769947&r1=769946&r2=769947&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 21:33:27 2009
@@ -84,6 +84,11 @@
         assertEquals(Boolean.FALSE, service.convert("FALSE", boolean.class));
         assertEquals(Boolean.FALSE, service.convert("NO", boolean.class));
         assertEquals(Boolean.FALSE, service.convert("OFF", boolean.class));
+        
+        assertEquals(Boolean.FALSE, service.convert(false, boolean.class));
+        assertEquals(Boolean.TRUE, service.convert(true, boolean.class));        
+        assertEquals(Boolean.FALSE, service.convert(false, Boolean.class));
+        assertEquals(Boolean.TRUE, service.convert(true, Boolean.class));
     }
 
     public void testConvertOther() throws Exception {
@@ -137,11 +142,11 @@
         
         // lookup on a specific registered converter type
         Object result;
-        result = s.convert(null, Region.class);
+        result = s.convert(new Object(), Region.class);
         assertTrue(result instanceof Region);
         assertFalse(result instanceof EuRegion);
                 
-        result = s.convert(null, EuRegion.class);
+        result = s.convert(new Object(), EuRegion.class);
         assertTrue(result instanceof EuRegion);
         
         // find first converter that matches the type
@@ -149,7 +154,7 @@
         s.registerConverter(new AsianRegionConverter());
         s.registerConverter(new EuRegionConverter());
         
-        result = s.convert(null, Region.class);
+        result = s.convert(new Object(), Region.class);
         assertTrue(result instanceof AsianRegion || result instanceof EuRegion);
     }
     



Mime
View raw message