You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by cc...@apache.org on 2009/03/09 07:17:21 UTC
svn commit: r751595 - in
/servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main:
java/org/apache/servicemix/kernel/gshell/config/completers/
resources/META-INF/spring/
Author: ccustine
Date: Mon Mar 9 06:17:18 2009
New Revision: 751595
URL: http://svn.apache.org/viewvc?rev=751595&view=rev
Log:
SMX4KNL-233 - Add argument completion for core gshell commands
Added:
servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/
servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationCompleter.java
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/resources/META-INF/spring/gshell-config.xml
Added: servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationCompleter.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationCompleter.java?rev=751595&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationCompleter.java (added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationCompleter.java Mon Mar 9 06:17:18 2009
@@ -0,0 +1,94 @@
+/*
+ * 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.kernel.gshell.config.completers;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+
+import jline.Completor;
+import org.apache.geronimo.gshell.console.completer.StringsCompleter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.cm.ConfigurationListener;
+import org.osgi.service.cm.ConfigurationEvent;
+import org.springframework.osgi.context.BundleContextAware;
+
+/**
+ * {@link jline.Completor} for Configuration Admin configurations.
+ *
+ * Displays a list of existing config admin configurations for completion.
+ *
+ */
+public class ConfigurationCompleter
+ implements Completor, ConfigurationListener
+{
+ private final StringsCompleter delegate = new StringsCompleter();
+
+ private ConfigurationAdmin admin;
+
+ public void setAdmin(ConfigurationAdmin admin) {
+ this.admin = admin;
+ }
+
+ @PostConstruct
+ public void init() {
+ Configuration[] configs;
+ try {
+ configs = admin.listConfigurations(null);
+ } catch (Exception e) {
+ return;
+ }
+
+ Collection<String> pids = new ArrayList<String>();
+
+ for (Configuration config : configs) {
+ if (config.getFactoryPid() != null) {
+ pids.add(config.getFactoryPid());
+ } else {
+ pids.add(config.getPid());
+ }
+ }
+
+ delegate.getStrings().addAll(pids);
+
+ }
+
+ @Override
+ public int complete(final String buffer, final int cursor, final List candidates) {
+ return delegate.complete(buffer, cursor, candidates);
+ }
+
+ @Override
+ public void configurationEvent(ConfigurationEvent configurationEvent) {
+ String pid = configurationEvent.getFactoryPid()!=null ? configurationEvent.getFactoryPid() : configurationEvent.getPid();
+ if (configurationEvent.getType() == ConfigurationEvent.CM_DELETED) {
+ delegate.getStrings().remove(pid);
+ } else if (configurationEvent.getType() == ConfigurationEvent.CM_UPDATED) {
+ delegate.getStrings().add(pid);
+ }
+ }
+}
\ No newline at end of file
Modified: servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/resources/META-INF/spring/gshell-config.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/resources/META-INF/spring/gshell-config.xml?rev=751595&r1=751594&r2=751595&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/resources/META-INF/spring/gshell-config.xml (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/resources/META-INF/spring/gshell-config.xml Mon Mar 9 06:17:18 2009
@@ -42,7 +42,10 @@
<gshell:action class="org.apache.servicemix.kernel.gshell.config.CancelCommand" />
</gshell:command>
<gshell:command name="config/edit">
- <gshell:action class="org.apache.servicemix.kernel.gshell.config.EditCommand" />
+ <gshell:action class="org.apache.servicemix.kernel.gshell.config.EditCommand"/>
+ <gshell:completers>
+ <ref bean="configCompleter" />
+ </gshell:completers>
</gshell:command>
<gshell:command name="config/list">
<gshell:action class="org.apache.servicemix.kernel.gshell.config.ListCommand" />
@@ -61,4 +64,12 @@
</gshell:command>
</gshell:command-bundle>
+ <bean id="configCompleter" class="org.apache.servicemix.kernel.gshell.config.completers.ConfigurationCompleter" init-method="init">
+ <property name="admin" ref="configAdmin"/>
+ </bean>
+
+ <osgi:reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin" />
+
+ <osgi:service ref="configCompleter" interface="org.osgi.service.cm.ConfigurationListener" />
+
</beans>
\ No newline at end of file