Author: davidb
Date: Thu Dec  1 18:04:24 2016
New Revision: 1772243

URL: http://svn.apache.org/viewvc?rev=1772243&view=rev
Log:
Felix Converter - update API with changes from OSGi

Removed:
    
felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/ConvertingTypeSettings.java
Modified:
    
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java
    
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
    
felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converting.java
    
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterBuilderTest.java
    
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java
    
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java

Modified: 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java?rev=1772243&r1=1772242&r2=1772243&view=diff
==============================================================================
--- 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java
 (original)
+++ 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java
 Thu Dec  1 18:04:24 2016
@@ -33,7 +33,6 @@ import org.osgi.util.converter.ConvertFu
 import org.osgi.util.converter.Converter;
 import org.osgi.util.converter.ConverterBuilder;
 import org.osgi.util.converter.Converting;
-import org.osgi.util.converter.ConvertingTypeSettings;
 import org.osgi.util.converter.Rule;
 import org.osgi.util.converter.TypeReference;
 import org.osgi.util.function.Function;
@@ -129,37 +128,28 @@ public class AdapterImpl implements Inte
         }
 
         @Override
-        public ConvertingTypeSettings source() {
-            return new ConvertingTypeSettings() {
-                @Override
-                public Converting asBean() {
-                    del.source().asBean();
-                    return ConvertingWrapper.this;
-                }
-
-                @Override
-                public Converting as(Class<?> type) {
-                    treatAsClass = type;
-                    del.source().as(type);
-                    return ConvertingWrapper.this;
-                }
-            };
+        public Converting sourceAsBean() {
+            del.sourceAsBean();
+            return this;
+        }
+
+        @Override
+        public Converting sourceAs(Class<?> type) {
+            treatAsClass = type;
+            del.sourceAs(type);
+            return this;
         }
 
         @Override
-        public ConvertingTypeSettings target() {
-            return new ConvertingTypeSettings() {
-                @Override
-                public Converting asBean() {
-                    return ConvertingWrapper.this;
-                }
-
-                @Override
-                public Converting as(Class<?> cls) {
-                    del.target().as(cls);
-                    return ConvertingWrapper.this;
-                }
-            };
+        public Converting targetAsBean() {
+            // TODO not yet implemented
+            return this;
+        }
+
+        @Override
+        public Converting targetAs(Class<?> cls) {
+            del.targetAs(cls);
+            return this;
         }
 
         @SuppressWarnings("unchecked")

Modified: 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java?rev=1772243&r1=1772242&r2=1772243&view=diff
==============================================================================
--- 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
 (original)
+++ 
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
 Thu Dec  1 18:04:24 2016
@@ -45,7 +45,6 @@ import org.osgi.dto.DTO;
 import org.osgi.util.converter.ConversionException;
 import org.osgi.util.converter.Converter;
 import org.osgi.util.converter.Converting;
-import org.osgi.util.converter.ConvertingTypeSettings;
 import org.osgi.util.converter.TypeReference;
 
 public class ConvertingImpl implements Converting, InternalConverting {
@@ -78,37 +77,27 @@ public class ConvertingImpl implements C
     }
 
     @Override
-    public ConvertingTypeSettings source() {
-        return new ConvertingTypeSettings() {
-            @Override
-            public Converting asBean() {
-                sourceAsJavaBean = true;
-                return ConvertingImpl.this;
-            }
-
-            @Override
-            public Converting as(Class<?> type) {
-                sourceAsClass = type;
-                return ConvertingImpl.this;
-            }
-        };
+    public Converting sourceAsBean() {
+        sourceAsJavaBean = true;
+        return this;
+    }
+
+    @Override
+    public Converting sourceAs(Class<?> cls) {
+        sourceAsClass = cls;
+        return this;
     }
 
     @Override
-    public ConvertingTypeSettings target() {
-        return new ConvertingTypeSettings() {
-            @Override
-            public Converting asBean() {
-                // TODO not yet implemented
-                return ConvertingImpl.this;
-            }
-
-            @Override
-            public Converting as(Class<?> cls) {
-                targetAsClass = cls;
-                return ConvertingImpl.this;
-            }
-        };
+    public Converting targetAsBean() {
+        // TODO not yet implemented
+        return this;
+    }
+
+    @Override
+    public Converting targetAs(Class<?> cls) {
+        targetAsClass = cls;
+        return this;
     }
 
     @Override
@@ -218,7 +207,7 @@ public class ConvertingImpl implements C
             return res2;
         } else {
             if (defaultValue != null)
-                return 
converter.convert(defaultValue).source().as(sourceAsClass).target().as(targetAsClass).to(targetActualClass);
+                return 
converter.convert(defaultValue).sourceAs(sourceAsClass).targetAs(targetAsClass).to(targetActualClass);
             else
                 return null;
         }

Modified: 
felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converting.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converting.java?rev=1772243&r1=1772242&r2=1772243&view=diff
==============================================================================
--- 
felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converting.java
 (original)
+++ 
felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converting.java
 Thu Dec  1 18:04:24 2016
@@ -51,18 +51,44 @@ public interface Converting {
        Converting defaultValue(Object defVal);
 
        /**
-        * Provide additional information on how to treat the source object.
+        * Treat the source object as the specified class. This can be used to
+        * disambiguate a type if it implements multiple interfaces or extends
+        * multiple classes.
+        *
+        * @param cls The class to treat the object as.
+        * @return The current {@code Converting} object so that additional 
calls
+        *         can be chained.
+        */
+       Converting sourceAs(Class< ? > cls);
+
+       /**
+        * Treat the source object as a JavaBean. By default objects will not be
+        * treated as JavaBeans, this has to be specified using this method.
         *
-        * @return A {@link ConvertingTypeSettings} to provide the details.
+        * @return The current {@code Converting} object so that additional 
calls
+        *         can be chained.
+        */
+       Converting sourceAsBean();
+
+       /**
+        * Treat the target object as the specified class. This can be used to
+        * disambiguate a type if it implements multiple interfaces or extends
+        * multiple classes.
+        *
+        * @param cls The class to treat the object as.
+        * @return The current {@code Converting} object so that additional 
calls
+        *         can be chained.
         */
-       ConvertingTypeSettings source();
+       Converting targetAs(Class< ? > cls);
 
        /**
-        * Provide additional information on how to treat the target type.
+        * Treat the target object as a JavaBean. By default objects will not be
+        * treated as JavaBeans, this has to be specified using this method.
         *
-        * @return A {@link ConvertingTypeSettings} to provide the details.
+        * @return The current {@code Converting} object so that additional 
calls
+        *         can be chained.
         */
-       ConvertingTypeSettings target();
+       Converting targetAsBean();
 
        /**
         * Specify the target object type for the conversion as a class object.
@@ -73,6 +99,15 @@ public interface Converting {
        <T> T to(Class<T> cls);
 
        /**
+        * Specify the target object type as a Java Reflection Type object.
+        *
+        * @param type A Type object to represent the target type to be 
converted
+        *            to.
+        * @return The converted object.
+        */
+       Object to(Type type);
+
+       /**
         * Specify the target object type as a {@link TypeReference}. If the 
target
         * class carries generics information a TypeReference should be used as 
this
         * preserves the generic information whereas a Class object has this
@@ -87,13 +122,4 @@ public interface Converting {
         * @return The converted object.
         */
        <T> T to(TypeReference<T> ref);
-
-       /**
-        * Specify the target object type as a Java Reflection Type object.
-        *
-        * @param type A Type object to represent the target type to be 
converted
-        *            to.
-        * @return The converted object.
-        */
-       Object to(Type type);
 }

Modified: 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterBuilderTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterBuilderTest.java?rev=1772243&r1=1772242&r2=1772243&view=diff
==============================================================================
--- 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterBuilderTest.java
 (original)
+++ 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterBuilderTest.java
 Thu Dec  1 18:04:24 2016
@@ -194,9 +194,9 @@ public class ConverterBuilderTest {
         mb.beanVal = "Hello";
 
         assertNull(converter.convert(mb).to(MyCustomDTO.class).field);
-        
assertNull(converter.convert(mb).source().as(MyIntf.class).to(MyCustomDTO.class).field);
+        
assertNull(converter.convert(mb).sourceAs(MyIntf.class).to(MyCustomDTO.class).field);
         assertEquals("Hello", cc.convert(mb).to(MyCustomDTO.class).field);
-        assertEquals("17", 
cc.convert(mb).source().as(MyIntf.class).to(MyCustomDTO.class).field);
+        assertEquals("17", 
cc.convert(mb).sourceAs(MyIntf.class).to(MyCustomDTO.class).field);
     }
 
     @Test

Modified: 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java?rev=1772243&r1=1772242&r2=1772243&view=diff
==============================================================================
--- 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java
 (original)
+++ 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java
 Thu Dec  1 18:04:24 2016
@@ -84,7 +84,7 @@ public class ConverterMapTest {
         mb.setNumbers(new int[] {3,2,1});
 
         @SuppressWarnings("rawtypes")
-        Map m = converter.convert(mb).source().asBean().to(Map.class);
+        Map m = converter.convert(mb).sourceAsBean().to(Map.class);
         assertEquals(5, m.size());
         assertEquals("You", m.get("me"));
         assertTrue((boolean) m.get("f"));
@@ -105,7 +105,7 @@ public class ConverterMapTest {
         ConverterBuilder cb = new StandardConverter().newConverterBuilder();
         cb.rule(Date.class, String.class, v -> sdf.format(v), v -> 
sdf.parse(v));
         Converter ca = cb.build();
-        Map<String, String> m = ca.convert(mb).source().asBean().to(new 
TypeReference<Map<String, String>>(){});
+        Map<String, String> m = ca.convert(mb).sourceAsBean().to(new 
TypeReference<Map<String, String>>(){});
         assertEquals("true", m.get("enabled"));
         assertEquals(expectedDate, m.get("startDate"));
     }

Modified: 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java?rev=1772243&r1=1772242&r2=1772243&view=diff
==============================================================================
--- 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java
 (original)
+++ 
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java
 Thu Dec  1 18:04:24 2016
@@ -501,7 +501,7 @@ public class ConverterTest {
     @Test
     public void testMap2DTOView() {
         Map<String, Object> src = Collections.singletonMap("pong", 42);
-        MyDTOWithMethods dto = 
converter.convert(src).target().as(MyDTO.class).to(MyDTOWithMethods.class);
+        MyDTOWithMethods dto = 
converter.convert(src).targetAs(MyDTO.class).to(MyDTOWithMethods.class);
         assertEquals(42, dto.pong);
     }
 
@@ -591,7 +591,7 @@ public class ConverterTest {
         mb.beanVal = "Hello";
 
         assertEquals(Collections.singletonMap("value", "Hello"),
-                converter.convert(mb).source().asBean().to(Map.class));
+                converter.convert(mb).sourceAsBean().to(Map.class));
     }
 
     @Test
@@ -601,7 +601,7 @@ public class ConverterTest {
         mb.beanVal = "Hello";
 
         assertEquals(17,
-                
converter.convert(mb).source().as(MyIntf.class).to(Map.class).get("value"));
+                
converter.convert(mb).sourceAs(MyIntf.class).to(Map.class).get("value"));
     }
 
     @Test
@@ -611,7 +611,7 @@ public class ConverterTest {
         mb.beanVal = "Hello";
 
         assertEquals(Collections.singletonMap("value", "Hello"),
-                converter.convert(mb).source().asBean().to(Map.class));
+                converter.convert(mb).sourceAsBean().to(Map.class));
     }
 
     @Test


Reply via email to