felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1785891 - in /felix/trunk/converter/converter: ./ src/main/java/org/apache/felix/converter/impl/ src/main/java/org/osgi/util/converter/ src/test/java/org/apache/felix/converter/impl/
Date Tue, 07 Mar 2017 21:42:43 GMT
Author: davidb
Date: Tue Mar  7 21:42:43 2017
New Revision: 1785891

URL: http://svn.apache.org/viewvc?rev=1785891&view=rev
Log:
Felix Converter - pick up OSGi API from snapshot repository.

Copied API has been removed since the OSGi API is now available via a snapshot repository.
Also updated the ConvertFunction handling.

Removed:
    felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/ConversionException.java
    felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/ConvertFunction.java
    felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converter.java
    felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/ConverterBuilder.java
    felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converting.java
    felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Rule.java
    felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/TypeReference.java
    felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/package-info.java
Modified:
    felix/trunk/converter/converter/pom.xml
    felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.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/ConverterTest.java

Modified: felix/trunk/converter/converter/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/pom.xml?rev=1785891&r1=1785890&r2=1785891&view=diff
==============================================================================
--- felix/trunk/converter/converter/pom.xml (original)
+++ felix/trunk/converter/converter/pom.xml Tue Mar  7 21:42:43 2017
@@ -90,6 +90,12 @@
     <dependencies>
         <dependency>
             <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.util.converter</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.osgi</groupId>
             <artifactId>org.osgi.util.function</artifactId>
             <version>1.0.0</version>
         </dependency>
@@ -121,4 +127,12 @@
             <scope>test</scope>            
         </dependency>
     </dependencies>
+    
+    <repositories>
+        <repository>
+            <id>osgi-snapshots</id>
+            <name>OSGi Snapshot Repository</name>
+            <url>https://oss.sonatype.org/content/repositories/osgi/</url>
+        </repository>
+    </repositories>    
 </project>

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=1785891&r1=1785890&r2=1785891&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
Tue Mar  7 21:42:43 2017
@@ -82,8 +82,6 @@ public class AdapterImpl implements Inte
         private volatile Object defaultValue;
         private volatile Class<?> treatAsClass;
         private volatile boolean hasDefault;
-        private volatile List<Object> keys = new ArrayList<>();
-        private volatile Object root;
 
         ConvertingWrapper(Object obj, InternalConverting c) {
             object = obj;
@@ -190,7 +188,7 @@ public class AdapterImpl implements Inte
 
                     for (ConvertFunction<Object,Object> cf : converters) {
                         try {
-                            Object res = cf.convert(object, type, root, keys.toArray());
+                            Object res = cf.convert(object, type);
                             if (res != null) {
                                 return res;
                             }
@@ -208,7 +206,7 @@ public class AdapterImpl implements Inte
             } catch (Exception ex) {
                 // do custom error handling
                 for (ConvertFunction<Object, Object> cf : converters) {
-                    Object eh = cf.handleError(object, type, root, keys.toArray());
+                    Object eh = cf.handleError(object, type);
                     if (eh != null)
                         return eh;
                 }
@@ -273,7 +271,7 @@ public class AdapterImpl implements Inte
         }
 
         @Override
-        public T convert(F obj, Type targetType, Object root, Object[] keys) throws Exception
{
+        public T convert(F obj, Type targetType) throws Exception {
             return function.apply(obj);
         }
     }

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=1785891&r1=1785890&r2=1785891&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
Tue Mar  7 21:42:43 2017
@@ -85,7 +85,7 @@ public class ConverterBuilderTest {
         cb.rule(char[].class, String.class, ConverterBuilderTest::convertToString, null);
         cb.rule(new Rule<String, Number>(String.class, Number.class, new ConvertFunction<String,
Number>() {
             @Override
-            public Number convert(String obj, Type targetType, Object root, Object[] key)
throws Exception {
+            public Number convert(String obj, Type targetType) throws Exception {
                 if (Integer.class.equals(targetType))
                     return Integer.valueOf(-1);
                 else if (Long.class.equals(targetType))
@@ -110,7 +110,7 @@ public class ConverterBuilderTest {
         Converter ca = converter.newConverterBuilder().rule(
                 new Rule<Integer, Long>(Integer.class, Long.class, new ConvertFunction<Integer,Long>()
{
             @Override
-            public Long convert(Integer obj, Type targetType, Object root, Object[] key)
throws Exception {
+            public Long convert(Integer obj, Type targetType) throws Exception {
                 if (obj.intValue() != 1)
                     return new Long(-obj.intValue());
                 return null;
@@ -127,7 +127,7 @@ public class ConverterBuilderTest {
     public void testWildcardAdapter() {
         ConvertFunction<List, Object> foo = new ConvertFunction<List, Object>()
{
             @Override
-            public Object convert(List t, Type type, Object root, Object[] key) throws Exception
{
+            public Object convert(List t, Type type) throws Exception {
                 if (type instanceof Class) {
                     if (Number.class.isAssignableFrom((Class<?>) type))
                         return converter.convert(t.size()).to(type);
@@ -138,7 +138,7 @@ public class ConverterBuilderTest {
 
         Rule<List, Object> r = new Rule<>(List.class, Object.class, foo);
         Rule<Object, Object> allCatch = new Rule<>(Object.class, Object.class,
-                (v,t,o,k) -> v.toString());
+                (v,t) -> v.toString());
 
         ConverterBuilder cb = converter.newConverterBuilder();
         cb.rule(r);
@@ -154,13 +154,13 @@ public class ConverterBuilderTest {
     public void testWildcardAdapter2() {
         Map<Object, Object> snooped = new HashMap<>();
         Rule<Object, ArrayList> r = new Rule<>(Object.class, ArrayList.class,
-                (v,t,o,k) -> null,
-                (v,t,o,k) -> "arraylist");
+                (v,t) -> null,
+                (v,t) -> "arraylist");
         Rule<Object, List> r2 = new Rule<>(Object.class, List.class,
-                (v,t,o,k) -> null,
-                (v,t,o,k) -> "list");
+                (v,t) -> null,
+                (v,t) -> "list");
         Rule<Object, Object> allCatch = new Rule<>(Object.class, Object.class,
-                (v,t,o,k) -> {snooped.put(v,t); return null;}, null);
+                (v,t) -> {snooped.put(v,t); return null;}, null);
 
         ConverterBuilder cb = converter.newConverterBuilder();
         cb.rule(r);
@@ -184,9 +184,9 @@ public class ConverterBuilderTest {
     public void testConvertAs() {
         ConverterBuilder cb = converter.newConverterBuilder();
         cb.rule(new Rule<>(MyIntf.class, MyCustomDTO.class,
-                (i, t, o, k) -> { MyCustomDTO dto = new MyCustomDTO(); dto.field = ""
+ i.value(); return dto; }));
+                (i, t) -> { MyCustomDTO dto = new MyCustomDTO(); dto.field = "" + i.value();
return dto; }));
         cb.rule(new Rule<>(MyBean.class, MyCustomDTO.class,
-                (b, t, o, k) -> { MyCustomDTO dto = new MyCustomDTO(); dto.field = b.getValue();
return dto; }));
+                (b, t) -> { MyCustomDTO dto = new MyCustomDTO(); dto.field = b.getValue();
return dto; }));
         Converter cc = cb.build();
 
         MyBean mb = new MyBean();
@@ -223,16 +223,12 @@ public class ConverterBuilderTest {
         ConverterBuilder cb = converter.newConverterBuilder();
         ConvertFunction<MyDTO6, Map> fun = new ConvertFunction<MyDTO6, Map>()
{
             @Override @SuppressWarnings("unchecked")
-            public Map convert(MyDTO6 obj, Type targetType, Object root, Object[] keys) throws
Exception {
+            public Map convert(MyDTO6 obj, Type targetType) throws Exception {
                 StringBuilder sb = new StringBuilder();
                 for (Character c : obj.chars) {
                     sb.append(c);
                 }
 
-                if ("sub2".equals(keys[0]) && "subsub1".equals(keys[1])) {
-                    sb.append(sb.toString());
-                }
-
                 Map m = new HashMap();
                 m.put("chars", sb.toString());
                 return m;

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=1785891&r1=1785890&r2=1785891&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
Tue Mar  7 21:42:43 2017
@@ -350,12 +350,12 @@ public class ConverterTest {
     public void testCustomErrorHandling() {
         ConvertFunction<String,Integer> func = new ConvertFunction<String,Integer>()
{
             @Override
-            public Integer convert(String obj, Type targetType, Object root, Object[] keyPath)
throws Exception {
+            public Integer convert(String obj, Type targetType) throws Exception {
                 return null;
             }
 
             @Override
-            public Integer handleError(String obj, Type targetType, Object root, Object[]
keyPath) {
+            public Integer handleError(String obj, Type targetType) {
                 if ("hello".equals(obj)) {
                     return -1;
                 }
@@ -379,39 +379,6 @@ public class ConverterTest {
         }
     }
 
-    /*
-    @Test
-    @SuppressWarnings({ "rawtypes", "unchecked" })
-    public void testCustomDefaultHandling() {
-        // TODO re-enable
-        Map<String, String> m = new HashMap<>();
-//        MyAnnotation ann = converter.convert(m).to(MyAnnotation.class);
-//        assertEquals(17, ann.value());
-
-        // Now register a custom default handler
-        ConvertFunction<Map,MyAnnotation> func = new ConvertFunction<Map,MyAnnotation>()
{
-            @Override
-            public MyAnnotation convert(Map obj, Type targetType, Object root, Object[] keyPath)
throws Exception {
-                return null;
-            }
-
-            @Override
-            public MyAnnotation handleDefault(Map obj, Class<?> targetType, Object
root, Object[] keyPath) {
-                return 42;
-            }
-        };
-
-        ConverterBuilder cb = converter.newConverterBuilder();
-        Rule r = new Rule(Map.class, MyAnnotation.class, func);
-        cb.rule(r);
-        Converter adapted = cb.build();
-
-        MyAnnotation ann2 = adapted.convert(m).to(MyAnnotation.class);
-        assertEquals("The default value from the annotation should have been overridden by
the default handler",
-                42, ann2.value());
-    }
-    */
-
     @Test
     public void testUUIDConversion() {
         UUID uuid = UUID.randomUUID();



Mime
View raw message