felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From db...@apache.org
Subject svn commit: r944310 - in /felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime: Closure.java CommandProxy.java Reflective.java
Date Fri, 14 May 2010 15:12:04 GMT
Author: dbaum
Date: Fri May 14 15:12:03 2010
New Revision: 944310

URL: http://svn.apache.org/viewvc?rev=944310&view=rev
Log:
Closure and CommandProxy unnecessarily extend Reflective, just so they can access its 'method()'
method. (FELIX-2328).


Modified:
    felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Closure.java
    felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProxy.java
    felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Closure.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Closure.java?rev=944310&r1=944309&r2=944310&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Closure.java (original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Closure.java Fri
May 14 15:12:03 2010
@@ -31,7 +31,7 @@ import org.apache.felix.gogo.runtime.Tok
 import org.osgi.service.command.CommandSession;
 import org.osgi.service.command.Function;
 
-public class Closure extends Reflective implements Function, Evaluate
+public class Closure implements Function, Evaluate
 {
     public static final String LOCATION = ".location";
     private static final String DEFAULT_LOCK = ".defaultLock";
@@ -449,7 +449,7 @@ public class Closure extends Reflective 
                 {
                     if (".".equals(arg))
                     {
-                        target = method(session, target, args.remove(0).toString(), args);
+                        target = Reflective.method(session, target, args.remove(0).toString(),
args);
                         args.clear();
                     }
                     else
@@ -463,11 +463,11 @@ public class Closure extends Reflective 
                     return target;
                 }
 
-                return method(session, target, args.remove(0).toString(), args);
+                return Reflective.method(session, target, args.remove(0).toString(), args);
             }
             else
             {
-                return method(session, cmd, values.remove(0).toString(), values);
+                return Reflective.method(session, cmd, values.remove(0).toString(), values);
             }
         }
     }

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProxy.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProxy.java?rev=944310&r1=944309&r2=944310&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProxy.java
(original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProxy.java
Fri May 14 15:12:03 2010
@@ -25,7 +25,7 @@ import org.osgi.service.command.CommandS
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.BundleContext;
 
-public class CommandProxy extends Reflective implements Function
+public class CommandProxy implements Function
 {
     private BundleContext context;
     private ServiceReference reference;
@@ -63,7 +63,7 @@ public class CommandProxy extends Reflec
             }
             else
             {
-                return method(session, tgt, function, arguments);
+                return Reflective.method(session, tgt, function, arguments);
             }
         }
         finally

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java?rev=944310&r1=944309&r2=944310&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java (original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java Fri
May 14 15:12:03 2010
@@ -18,34 +18,38 @@
  */
 package org.apache.felix.gogo.runtime;
 
-import java.lang.annotation.*;
-import java.lang.reflect.*;
-import java.util.*;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.osgi.service.command.CommandSession;
+import org.osgi.service.command.Flag;
+import org.osgi.service.command.Option;
 
-import org.osgi.service.command.*;
-
-public class Reflective
+public final class Reflective
 {
     public final static Object NO_MATCH = new Object();
-    public final static Set<String> KEYWORDS = new HashSet<String>(Arrays.asList(new
String[]
-        {
-            "abstract", "continue", "for", "new",
-            "switch", "assert", "default", "goto", "package",
-            "synchronized", "boolean", "do", "if", "private", "this",
-            "break", "double", "implements", "protected", "throw",
-            "byte", "else", "import", "public", "throws", "case",
-            "enum", "instanceof", "return", "transient", "catch",
-            "extends", "int", "short", "try", "char", "final",
-            "interface", "static", "void", "class", "finally", "long",
-            "strictfp", "volatile", "const", "float", "native",
-            "super", "while"
-        }));
     public final static String MAIN = "_main";
-
-    public Object method(
-        CommandSession session, Object target, String name, List<Object> args)
-        throws IllegalArgumentException, IllegalAccessException,
-            InvocationTargetException, Exception
+    public final static Set<String> KEYWORDS = new HashSet<String>(
+        Arrays.asList(new String[] { "abstract", "continue", "for", "new", "switch",
+                "assert", "default", "goto", "package", "synchronized", "boolean", "do",
+                "if", "private", "this", "break", "double", "implements", "protected",
+                "throw", "byte", "else", "import", "public", "throws", "case", "enum",
+                "instanceof", "return", "transient", "catch", "extends", "int", "short",
+                "try", "char", "final", "interface", "static", "void", "class",
+                "finally", "long", "strictfp", "volatile", "const", "float", "native",
+                "super", "while" }));
+
+    public static Object method(CommandSession session, Object target, String name,
+        List<Object> args) throws IllegalArgumentException, IllegalAccessException,
+        InvocationTargetException, Exception
     {
         Method[] methods = target.getClass().getMethods();
         name = name.toLowerCase();
@@ -59,17 +63,14 @@ public class Reflective
             name = "_" + name;
         }
 
-        if (target instanceof Class)
+        if (target instanceof Class<?>)
         {
             Method[] staticMethods = ((Class<?>) target).getMethods();
             for (Method m : staticMethods)
             {
                 String mname = m.getName().toLowerCase();
-                if (mname.equals(name)
-                    || mname.equals(get)
-                    || mname.equals(set)
-                    || mname.equals(is)
-                    || mname.equals(MAIN))
+                if (mname.equals(name) || mname.equals(get) || mname.equals(set)
+                    || mname.equals(is) || mname.equals(MAIN))
                 {
                     methods = staticMethods;
                     break;
@@ -85,11 +86,8 @@ public class Reflective
         for (Method m : methods)
         {
             String mname = m.getName().toLowerCase();
-            if (mname.equals(name)
-                || mname.equals(get)
-                || mname.equals(set)
-                || mname.equals(is)
-                || mname.equals(MAIN))
+            if (mname.equals(name) || mname.equals(get) || mname.equals(set)
+                || mname.equals(is) || mname.equals(MAIN))
             {
                 Class<?>[] types = m.getParameterTypes();
                 ArrayList<Object> xargs = new ArrayList<Object>(args);
@@ -102,8 +100,7 @@ public class Reflective
                 }
 
                 // Check if the command takes a session
-                if ((types.length > 0)
-                    && CommandSession.class.isAssignableFrom(types[0]))
+                if ((types.length > 0) && CommandSession.class.isAssignableFrom(types[0]))
                 {
                     xargs.add(0, session);
                 }
@@ -183,8 +180,8 @@ public class Reflective
                 list.add(buf.toString());
             }
 
-            throw new IllegalArgumentException(
-                String.format("Cannot coerce %s%s to any of %s", name, args, list));
+            throw new IllegalArgumentException(String.format(
+                "Cannot coerce %s%s to any of %s", name, args, list));
             // } derek
         }
     }
@@ -205,10 +202,8 @@ public class Reflective
      * @throws Exception
      */
     @SuppressWarnings("unchecked")
-    private int coerce(
-        CommandSession session, Object target, Method m,
-        Class<?> types[], Object out[], List<Object> in)
-        throws Exception
+    private static int coerce(CommandSession session, Object target, Method m,
+        Class<?> types[], Object out[], List<Object> in) throws Exception
     {
         Annotation[][] pas = m.getParameterAnnotations();
 
@@ -226,8 +221,7 @@ public class Reflective
                 }
                 else if (as[a] instanceof Flag)
                 {
-                    out[argIndex] = coerce(session, target, types[argIndex],
-                        false);
+                    out[argIndex] = coerce(session, target, types[argIndex], false);
                     start = argIndex + 1;
                 }
             }
@@ -345,7 +339,7 @@ public class Reflective
         return i;
     }
 
-    Object coerce(CommandSession session, Object target, Class<?> type,
+    private static Object coerce(CommandSession session, Object target, Class<?> type,
         Object arg) throws Exception
     {
         if (arg == null)
@@ -456,16 +450,4 @@ public class Reflective
         return NO_MATCH;
     }
 
-    public static boolean hasCommand(Object target, String function)
-    {
-        Method[] methods = target.getClass().getMethods();
-        for (Method m : methods)
-        {
-            if (m.getName().equals(function))
-            {
-                return true;
-            }
-        }
-        return false;
-    }
 }
\ No newline at end of file



Mime
View raw message