Repository: cxf Updated Branches: refs/heads/2.7.x-fixes e5014f1be -> a2cfbf0cb
[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/a2cfbf0c Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a2cfbf0c Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a2cfbf0c Branch: refs/heads/2.7.x-fixes Commit: a2cfbf0cb1d5e9f7a71204a504db847d1b2b1def Parents: e5014f1 Author: Freeman Fang <[email protected]> Authored: Wed Jun 18 18:12:49 2014 +0800 Committer: Freeman Fang <[email protected]> Committed: Wed Jun 18 18:12:49 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 | 23 +++++++ 5 files changed, 213 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/a2cfbf0c/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/a2cfbf0c/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/a2cfbf0c/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/a2cfbf0c/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/a2cfbf0c/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 b4efdf7..910ae1a 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 @@ -32,11 +32,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> @@ -46,4 +56,17 @@ <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>
