cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject git commit: [CXF-5813]add completers for cxf karaf shell commands
Date Wed, 18 Jun 2014 10:23:45 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 46509e756 -> 86c613b12


[CXF-5813]add completers for cxf karaf shell commands


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/86c613b1
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/86c613b1
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/86c613b1

Branch: refs/heads/master
Commit: 86c613b126816aee9eecce6cf510f80f83508bd8
Parents: 46509e7
Author: Freeman Fang <freeman.fang@gmail.com>
Authored: Wed Jun 18 18:20:40 2014 +0800
Committer: Freeman Fang <freeman.fang@gmail.com>
Committed: Wed Jun 18 18:20:40 2014 +0800

----------------------------------------------------------------------
 .../karaf/commands/completers/BusCompleter.java | 55 +++++++++++++++
 .../completers/EndpointCompleterSupport.java    | 72 ++++++++++++++++++++
 .../completers/StartedEndpointCompleter.java    | 31 +++++++++
 .../completers/StoppedEndpointCompleter.java    | 32 +++++++++
 .../OSGI-INF/blueprint/cxf-karaf-commands.xml   | 22 ++++++
 5 files changed, 212 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/86c613b1/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/BusCompleter.java
----------------------------------------------------------------------
diff --git a/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/BusCompleter.java
b/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/BusCompleter.java
new file mode 100644
index 0000000..51e3a34
--- /dev/null
+++ b/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/BusCompleter.java
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.karaf.commands.completers;
+
+import java.util.List;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.karaf.commands.CXFController;
+
+import org.apache.karaf.shell.console.Completer;
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+
+public class BusCompleter implements Completer {
+    
+    private CXFController cxfController;
+
+    public void setController(CXFController controller) {
+        this.cxfController = controller;
+    }
+
+    @Override
+    public int complete(final String buffer, 
+                        final int cursor, 
+                        @SuppressWarnings("rawtypes") final List candidates) {
+        StringsCompleter delegate = new StringsCompleter();
+        try {
+            List<Bus> busses = cxfController.getBusses();
+           
+            for (Bus bus : busses) {
+                delegate.getStrings().add(bus.getId());
+            }
+            
+        } catch (Exception e) {
+            // Ignore
+        }
+        return delegate.complete(buffer, cursor, candidates);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/86c613b1/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/EndpointCompleterSupport.java
----------------------------------------------------------------------
diff --git a/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/EndpointCompleterSupport.java
b/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/EndpointCompleterSupport.java
new file mode 100644
index 0000000..65a8bb8
--- /dev/null
+++ b/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/EndpointCompleterSupport.java
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.karaf.commands.completers;
+
+import java.util.List;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.endpoint.ServerRegistry;
+import org.apache.cxf.karaf.commands.CXFController;
+import org.apache.karaf.shell.console.Completer;
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+
+public abstract class EndpointCompleterSupport implements Completer {
+    
+    private CXFController cxfController;
+
+    public void setController(CXFController controller) {
+        this.cxfController = controller;
+    }
+
+    @Override
+    public int complete(final String buffer, 
+                        final int cursor, 
+                        @SuppressWarnings("rawtypes") final List candidates) {
+        StringsCompleter delegate = new StringsCompleter();
+        try {
+            List<Bus> busses = cxfController.getBusses();
+           
+            for (Bus b : busses) {
+                ServerRegistry reg = b.getExtension(ServerRegistry.class);
+                List<Server> servers = reg.getServers();
+                
+                for (Server serv : servers) {
+                    if (acceptsFeature(serv)) {
+                        String qname = serv.getEndpoint().getEndpointInfo().getName().getLocalPart();
+                        delegate.getStrings().add(qname);
+                    }
+                }
+            }
+            
+        } catch (Exception e) {
+            // Ignore
+        }
+        return delegate.complete(buffer, cursor, candidates);
+    }
+    
+    /**
+     * Method for filtering endpoint.
+     *
+     * @param server The endpoint Server.
+     * @return True if endpoint Server should be available in completer.
+     */
+    protected abstract boolean acceptsFeature(Server server);
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/86c613b1/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StartedEndpointCompleter.java
----------------------------------------------------------------------
diff --git a/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StartedEndpointCompleter.java
b/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StartedEndpointCompleter.java
new file mode 100644
index 0000000..7f09dff
--- /dev/null
+++ b/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StartedEndpointCompleter.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.karaf.commands.completers;
+
+
+import org.apache.cxf.endpoint.Server;
+
+public class StartedEndpointCompleter extends EndpointCompleterSupport {
+
+    @Override
+    protected boolean acceptsFeature(Server server) {
+        return server.isStarted();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/86c613b1/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StoppedEndpointCompleter.java
----------------------------------------------------------------------
diff --git a/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StoppedEndpointCompleter.java
b/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StoppedEndpointCompleter.java
new file mode 100644
index 0000000..1ccbd00
--- /dev/null
+++ b/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StoppedEndpointCompleter.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.karaf.commands.completers;
+
+
+import org.apache.cxf.endpoint.Server;
+
+public class StoppedEndpointCompleter extends EndpointCompleterSupport {
+
+    
+    @Override
+    protected boolean acceptsFeature(Server server) {
+        return !server.isStarted();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/86c613b1/osgi/karaf/commands/src/main/resources/OSGI-INF/blueprint/cxf-karaf-commands.xml
----------------------------------------------------------------------
diff --git a/osgi/karaf/commands/src/main/resources/OSGI-INF/blueprint/cxf-karaf-commands.xml
b/osgi/karaf/commands/src/main/resources/OSGI-INF/blueprint/cxf-karaf-commands.xml
index ee62650..561c304 100644
--- a/osgi/karaf/commands/src/main/resources/OSGI-INF/blueprint/cxf-karaf-commands.xml
+++ b/osgi/karaf/commands/src/main/resources/OSGI-INF/blueprint/cxf-karaf-commands.xml
@@ -31,11 +31,21 @@
             <action class="org.apache.cxf.karaf.commands.StartEndpointCommand">
                 <property name="controller" ref="cxfController"/>
             </action>
+            <completers>
+                <ref component-id="busCompleter" />
+                <ref component-id="stoppedEndpointCompleter" />
+                <null/>
+            </completers>
         </command>
         <command name="cxf/stop-endpoint">
             <action class="org.apache.cxf.karaf.commands.StopEndpointCommand">
                 <property name="controller" ref="cxfController"/>
             </action>
+            <completers>
+                <ref component-id="busCompleter" />
+                <ref component-id="startedEndpointCompleter" />
+                <null/>
+            </completers>
         </command>
     </command-bundle>
     <reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"/>
@@ -43,4 +53,16 @@
         <property name="bundleContext" ref="blueprintBundleContext"/>
         <property name="configAdmin" ref="configAdmin"/>
     </bean>
+    <bean id="busCompleter" class="org.apache.cxf.karaf.commands.completers.BusCompleter">
+        <property name="controller" ref="cxfController" />
+    </bean>
+
+    <bean id="stoppedEndpointCompleter" class="org.apache.cxf.karaf.commands.completers.StoppedEndpointCompleter">
+        <property name="controller" ref="cxfController" />
+    </bean>
+
+    <bean id="startedEndpointCompleter" class="org.apache.cxf.karaf.commands.completers.StartedEndpointCompleter">
+        <property name="controller" ref="cxfController" />
+    </bean>
+
 </blueprint>


Mime
View raw message