You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2009/03/10 23:51:09 UTC
svn commit: r752291 - in /servicemix/smx4/nmr/trunk/jbi/commands/src/main:
java/org/apache/servicemix/jbi/commands/JbiCommandCompleter.java
resources/META-INF/spring/servicemix-jbi-commands.xml
Author: gnodet
Date: Tue Mar 10 22:51:08 2009
New Revision: 752291
URL: http://svn.apache.org/viewvc?rev=752291&view=rev
Log:
SMX4NMR-119: Add command completion for jbi lifecycle commands
Added:
servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandCompleter.java
Modified:
servicemix/smx4/nmr/trunk/jbi/commands/src/main/resources/META-INF/spring/servicemix-jbi-commands.xml
Added: servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandCompleter.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandCompleter.java?rev=752291&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandCompleter.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/commands/src/main/java/org/apache/servicemix/jbi/commands/JbiCommandCompleter.java Tue Mar 10 22:51:08 2009
@@ -0,0 +1,77 @@
+/*
+ * 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.servicemix.jbi.commands;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import jline.Completor;
+import org.apache.geronimo.gshell.console.completer.StringsCompleter;
+import org.apache.servicemix.jbi.deployer.Component;
+import org.apache.servicemix.jbi.deployer.ServiceAssembly;
+import org.apache.servicemix.jbi.deployer.impl.Deployer;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.springframework.osgi.context.BundleContextAware;
+
+/**
+ * {@link jline.Completor} for JBI artifacts.
+ */
+public class JbiCommandCompleter implements Completor, BundleContextAware {
+
+ private BundleContext bundleContext;
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ public int complete(final String buffer, final int cursor, final List candidates) {
+ Collection<String> artifacts = getComponentsAndAssemblies();
+ StringsCompleter delegate = new StringsCompleter(artifacts);
+ return delegate.complete(buffer, cursor, candidates);
+ }
+
+ protected Set<String> getComponentsAndAssemblies() {
+ try {
+ Set<String> artifacts = new HashSet<String>();
+ ServiceReference[] references = bundleContext.getAllServiceReferences(Component.class.getName(), null);
+ if (references != null) {
+ for (ServiceReference ref : references) {
+ String name = (String) ref.getProperty(Deployer.NAME);
+ if (name != null) {
+ artifacts.add(name);
+ }
+ }
+ }
+ references = bundleContext.getAllServiceReferences(ServiceAssembly.class.getName(), null);
+ if (references != null) {
+ for (ServiceReference ref : references) {
+ String name = (String) ref.getProperty(Deployer.NAME);
+ if (name != null) {
+ artifacts.add(name);
+ }
+ }
+ }
+ return artifacts;
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+}
Modified: servicemix/smx4/nmr/trunk/jbi/commands/src/main/resources/META-INF/spring/servicemix-jbi-commands.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/commands/src/main/resources/META-INF/spring/servicemix-jbi-commands.xml?rev=752291&r1=752290&r2=752291&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/commands/src/main/resources/META-INF/spring/servicemix-jbi-commands.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/commands/src/main/resources/META-INF/spring/servicemix-jbi-commands.xml Tue Mar 10 22:51:08 2009
@@ -35,13 +35,24 @@
<gshell:link name="jbi/ls" target="jbi/list"/>
<gshell:command name="jbi/start">
<gshell:action class="org.apache.servicemix.jbi.commands.StartCommand" />
+ <gshell:completers>
+ <ref bean="jbiArtifactsCompleter" />
+ </gshell:completers>
</gshell:command>
<gshell:command name="jbi/stop">
<gshell:action class="org.apache.servicemix.jbi.commands.StopCommand" />
+ <gshell:completers>
+ <ref bean="jbiArtifactsCompleter" />
+ </gshell:completers>
</gshell:command>
<gshell:command name="jbi/shutdown">
<gshell:action class="org.apache.servicemix.jbi.commands.ShutdownCommand" />
+ <gshell:completers>
+ <ref bean="jbiArtifactsCompleter" />
+ </gshell:completers>
</gshell:command>
</gshell:command-bundle>
+ <bean id="jbiArtifactsCompleter" class="org.apache.servicemix.jbi.commands.JbiCommandCompleter" />
+
</beans>