geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r785908 - in /geronimo/sandbox/blueprint: blueprint-api/src/main/java/org/osgi/service/blueprint/container/ blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ blueprint-core/src/main/java/org/apache/geronimo/blueprint/uti...
Date Thu, 18 Jun 2009 05:09:51 GMT
Author: gawor
Date: Thu Jun 18 05:09:51 2009
New Revision: 785908

URL: http://svn.apache.org/viewvc?rev=785908&view=rev
Log:
update the Converter interface to match the latest api

Modified:
    geronimo/sandbox/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/Converter.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/AggregateConverterTest.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterA.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterB.java
    geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/CurrencyTypeConverter.java
    geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/DateTypeConverter.java

Modified: geronimo/sandbox/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/Converter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/Converter.java?rev=785908&r1=785907&r2=785908&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/Converter.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/Converter.java
Thu Jun 18 05:09:51 2009
@@ -24,21 +24,26 @@
 	/**
 	 * Check if the converter is able to convert the given value to the specified
 	 * type.
-	 *
+	 * 
+	 * @param fromValue the object to be converted
+     * @param toType the type that the instance is to be converted to.
+     *        This will be either a Class object or a Type object.	 
 	 * @return <code>true</code> if the conversion is possible, <code>false</code>
otherwise.
 	 */
-	boolean canConvert(Object fromValue, Class toType);
+	boolean canConvert(Object fromValue, Object toType);
 
 	/**
 	 * Convert an object to an instance of the given class, using the built-in and 
 	 * user-registered type converters as necessary.
+	 * 
 	 * @param fromValue the object to be converted
-	 * @param toType the type that the instance is to be converted to
+	 * @param toType the type that the instance is to be converted to.
+	 *        This will be either a Class object or a Type object.
 	 * @return an instance of the class 'toType'
 	 * @throws Exception if the conversion cannot succeed. This exception is
 	 * checked because callers should expect that not all source objects
 	 * can be successfully converted.
 	 */
-	Object convert(Object fromValue, Class toType) throws Exception;
+	Object convert(Object fromValue, Object toType) throws Exception;
 	
 }
\ No newline at end of file

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java?rev=785908&r1=785907&r2=785908&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java
Thu Jun 18 05:09:51 2009
@@ -19,6 +19,7 @@
 import java.io.ByteArrayInputStream;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
@@ -60,15 +61,16 @@
         converters.remove(converter);
     }
 
-    public boolean canConvert(Object fromValue, Class toType) {
+    public boolean canConvert(Object fromValue, Object toType) {
         if (fromValue == null) {
             return true;
         }
-        if (TypeUtils.isInstance(toType, fromValue)) {
+        Type type = (Type) toType;
+        if (TypeUtils.isInstance(type, fromValue)) {
             return true;
         }
         for (Converter converter : converters) {
-            if (converter.canConvert(fromValue, toType)) {
+            if (converter.canConvert(fromValue, type)) {
                 return true;
             }
         }
@@ -78,26 +80,27 @@
         return false;
     }
 
-    public Object convert(Object fromValue, Class toType) throws Exception {
+    public Object convert(Object fromValue, Object toType) throws Exception {
         if (fromValue == null) {
             return null;
         }
-        if (TypeUtils.isInstance(toType, fromValue)) {
+        Type type = (Type) toType;
+        if (TypeUtils.isInstance(type, fromValue)) {
             return fromValue;
         }
-        Object value = doConvert(fromValue, toType);        
+        Object value = doConvert(fromValue, type);        
         if (value == null) {
-            if (fromValue instanceof String) {
-                return convertString((String) fromValue, toType);
+            if (fromValue instanceof String && toType instanceof Class) {
+                return convertString((String) fromValue, (Class) type);
             } else {
-                throw new Exception("Unable to convert value " + fromValue + " to type: "
+ toType.getName());
+                throw new Exception("Unable to convert value " + fromValue + " to type "
+ type);
             }
         } else {
             return value;
         }
     }
 
-    private Object doConvert(Object source, Class type) throws Exception {
+    private Object doConvert(Object source, Type type) throws Exception {
         Object value = null;
         for (Converter converter : converters) {
             if (converter.canConvert(source, type)) {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java?rev=785908&r1=785907&r2=785908&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java
Thu Jun 18 05:09:51 2009
@@ -144,7 +144,7 @@
             }
             return newCol;
         }
-        return converter.convert(obj, toClass(type));
+        return converter.convert(obj, type);
     }
 
     public static Class getMap(Class type) {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/AggregateConverterTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/AggregateConverterTest.java?rev=785908&r1=785907&r2=785908&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/AggregateConverterTest.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/AggregateConverterTest.java
Thu Jun 18 05:09:51 2009
@@ -165,28 +165,28 @@
     private interface AsianRegion extends Region {}
     
     private static class RegionConverter implements Converter {
-        public boolean canConvert(Object fromValue, Class toType) {
+        public boolean canConvert(Object fromValue, Object toType) {
             return Region.class == toType;
         }
-        public Object convert(Object source, Class toType) throws Exception {
+        public Object convert(Object source, Object toType) throws Exception {
             return new Region() {} ;
         }
     }
     
     private static class EuRegionConverter implements Converter {
-        public boolean canConvert(Object fromValue, Class toType) {
-            return toType.isAssignableFrom(EuRegion.class);
+        public boolean canConvert(Object fromValue, Object toType) {
+            return ((Class) toType).isAssignableFrom(EuRegion.class);
         }
-        public Object convert(Object source, Class toType) throws Exception {
+        public Object convert(Object source, Object toType) throws Exception {
             return new EuRegion() {} ;
         }
     }
     
     private static class AsianRegionConverter implements Converter {
-        public boolean canConvert(Object fromValue, Class toType) {
-            return toType.isAssignableFrom(AsianRegion.class);
+        public boolean canConvert(Object fromValue, Object toType) {
+            return ((Class) toType).isAssignableFrom(AsianRegion.class);
         }
-        public Object convert(Object source, Class toType) throws Exception {
+        public Object convert(Object source, Object toType) throws Exception {
             return new AsianRegion() {} ;
         }
     }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterA.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterA.java?rev=785908&r1=785907&r2=785908&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterA.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterA.java
Thu Jun 18 05:09:51 2009
@@ -24,11 +24,11 @@
 
 public class ConverterA implements Converter {
 
-    public boolean canConvert(Object fromValue, Class toType) {
+    public boolean canConvert(Object fromValue, Object toType) {
         return fromValue instanceof String && toType == File.class;
     }
 
-    public Object convert(Object source, Class toType) throws Exception {
+    public Object convert(Object source, Object toType) throws Exception {
         if (source instanceof String) {
             return new File((String) source);
         }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterB.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterB.java?rev=785908&r1=785907&r2=785908&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterB.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterB.java
Thu Jun 18 05:09:51 2009
@@ -25,11 +25,11 @@
 
 public class ConverterB implements Converter {
 
-    public boolean canConvert(Object fromValue, Class toType) {
+    public boolean canConvert(Object fromValue, Object toType) {
         return fromValue instanceof String && toType == URI.class;
     }
 
-    public Object convert(Object source, Class toType) throws Exception {
+    public Object convert(Object source, Object toType) throws Exception {
         if (source instanceof String) {
             return new URI((String) source);
         }

Modified: geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/CurrencyTypeConverter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/CurrencyTypeConverter.java?rev=785908&r1=785907&r2=785908&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/CurrencyTypeConverter.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/CurrencyTypeConverter.java
Thu Jun 18 05:09:51 2009
@@ -22,11 +22,11 @@
 
 public class CurrencyTypeConverter implements Converter {
 
-    public boolean canConvert(Object fromValue, Class toType) {
-        return Currency.class.isAssignableFrom(toType);
+    public boolean canConvert(Object fromValue, Object toType) {
+        return Currency.class.isAssignableFrom((Class) toType);
     }
 
-    public Object convert(Object source, Class toType) throws Exception {
+    public Object convert(Object source, Object toType) throws Exception {
         return Currency.getInstance(source.toString());
     }
 

Modified: geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/DateTypeConverter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/DateTypeConverter.java?rev=785908&r1=785907&r2=785908&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/DateTypeConverter.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/DateTypeConverter.java
Thu Jun 18 05:09:51 2009
@@ -30,12 +30,12 @@
         dateFormat = new SimpleDateFormat(format);
     }
     
-    public Object convert(Object source, Class toType) throws Exception {
+    public Object convert(Object source, Object toType) throws Exception {
         return dateFormat.parse(source.toString());
     }
 
-    public boolean canConvert(Object fromValue, Class toType) {
-        return Date.class.isAssignableFrom(toType);
+    public boolean canConvert(Object fromValue, Object toType) {
+        return Date.class.isAssignableFrom((Class) toType);
     }
 
 }



Mime
View raw message