You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by db...@apache.org on 2010/05/11 17:26:31 UTC

svn commit: r943145 - in /felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell: CommandProcessorImpl.java CommandSessionImpl.java

Author: dbaum
Date: Tue May 11 15:26:31 2010
New Revision: 943145

URL: http://svn.apache.org/viewvc?rev=943145&view=rev
Log:
continue tidy-up: move SCOPE path handling into CommandProcessorImpl. FELIX-2328

Modified:
    felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProcessorImpl.java
    felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandSessionImpl.java

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProcessorImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProcessorImpl.java?rev=943145&r1=943144&r2=943145&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProcessorImpl.java (original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProcessorImpl.java Tue May 11 15:26:31 2010
@@ -67,27 +67,44 @@ public class CommandProcessorImpl implem
         return commands.keySet();
     }
 
-    public Function getCommand(String name)
+    public Function getCommand(String name, final Object path)
     {
-        name = name.toLowerCase();
-        int n = name.indexOf(':');
+        int colon = name.indexOf(':');
 
-        if (n < 0)
+        if (colon < 0)
         {
             return null;
         }
         
-        String scope = name.substring(0, n);
-        String function = name.substring(n + 1);
+        name = name.toLowerCase();
         Object cmd = commands.get(name);
+        String cfunction = name.substring(colon);
+        boolean anyScope = (colon == 1 && name.charAt(0) == '*');
         
-        if (null == cmd && scope.equals("*"))
+        if (null == cmd && anyScope)
         {
-            for (String key : commands.keySet())
+            String scopePath = (null == path ? "*" : path.toString());
+            
+            for (String scope : scopePath.split(":"))
             {
-                if (key.endsWith(":" + function))
+                if (scope.equals("*"))
+                {
+                    for (String key : commands.keySet())
+                    {
+                        if (key.endsWith(cfunction))
+                        {
+                            cmd = commands.get(key);
+                            break;
+                        }
+                    }
+                }
+                else
+                {
+                    cmd = commands.get(scope + cfunction);
+                }
+                
+                if (cmd != null)
                 {
-                    cmd = commands.get(key);
                     break;
                 }
             }
@@ -98,7 +115,7 @@ public class CommandProcessorImpl implem
             return (Function) cmd;
         }
 
-        return new CommandProxy(cmd, function);
+        return new CommandProxy(cmd, cfunction.substring(1));
     }
 
     public void addCommand(String scope, Object target)

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandSessionImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandSessionImpl.java?rev=943145&r1=943144&r2=943145&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandSessionImpl.java (original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandSessionImpl.java Tue May 11 15:26:31 2010
@@ -101,25 +101,7 @@ public class CommandSessionImpl implemen
             return variables.get(name);
         }
 
-        // add SCOPE support
-        if (name.startsWith("*:"))
-        {
-            String func = name.substring(2);
-            String path = variables.containsKey("SCOPE") ? variables.get("SCOPE").toString()
-                : "osgi:*";
-            
-            for (String scope : path.split(":"))
-            {
-                Object result = processor.getCommand(scope + ":" + func);
-                if (result != null)
-                {
-                    return result;
-                }
-            }
-            return null;
-        }
-
-        return processor.getCommand(name);
+        return processor.getCommand(name, variables.get("SCOPE"));
     }
 
     public void put(String name, Object value)