continue tidy-up: move SCOPE path handling into CommandProcessorImpl. FELIX-2328
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@943145 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProcessorImpl.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProcessorImpl.java
index a37546f..4a40f5b 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProcessorImpl.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandProcessorImpl.java
@@ -67,27 +67,44 @@
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("*"))
{
- cmd = commands.get(key);
+ for (String key : commands.keySet())
+ {
+ if (key.endsWith(cfunction))
+ {
+ cmd = commands.get(key);
+ break;
+ }
+ }
+ }
+ else
+ {
+ cmd = commands.get(scope + cfunction);
+ }
+
+ if (cmd != null)
+ {
break;
}
}
@@ -98,7 +115,7 @@
return (Function) cmd;
}
- return new CommandProxy(cmd, function);
+ return new CommandProxy(cmd, cfunction.substring(1));
}
public void addCommand(String scope, Object target)
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandSessionImpl.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandSessionImpl.java
index ce47d0a..55c78a9 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandSessionImpl.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/CommandSessionImpl.java
@@ -101,25 +101,7 @@
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)