Search in sources :

Example 16 with StringsCompleter

use of org.apache.karaf.shell.support.completers.StringsCompleter in project karaf by apache.

the class ArgumentCompleter method getDefaultCompleter.

@SuppressWarnings({ "unchecked", "rawtypes" })
private Completer getDefaultCompleter(Field field, boolean multi) {
    Completer completer = null;
    Class<?> type = field.getType();
    GenericType genericType = new GenericType(field.getGenericType());
    if (Collection.class.isAssignableFrom(genericType.getRawClass()) && multi) {
        type = genericType.getActualTypeArgument(0).getRawClass();
    }
    if (type.isAssignableFrom(URI.class)) {
        completer = new UriCompleter();
    } else if (type.isAssignableFrom(File.class)) {
        completer = new FileCompleter();
    } else if (type.isAssignableFrom(Boolean.class) || type.isAssignableFrom(boolean.class)) {
        completer = new StringsCompleter(new String[] { "false", "true" }, false);
    } else if (Enum.class.isAssignableFrom(type)) {
        Set<String> values = new HashSet<>();
        for (Object o : EnumSet.allOf((Class<Enum>) type)) {
            values.add(o.toString());
        }
        completer = new StringsCompleter(values, false);
    }
    return completer;
}
Also used : GenericType(org.apache.karaf.shell.support.converter.GenericType) HashSet(java.util.HashSet) EnumSet(java.util.EnumSet) Set(java.util.Set) FileCompleter(org.apache.karaf.shell.support.completers.FileCompleter) UriCompleter(org.apache.karaf.shell.support.completers.UriCompleter) Completer(org.apache.karaf.shell.api.console.Completer) NullCompleter(org.apache.karaf.shell.support.completers.NullCompleter) UriCompleter(org.apache.karaf.shell.support.completers.UriCompleter) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) FileCompleter(org.apache.karaf.shell.support.completers.FileCompleter) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) Collection(java.util.Collection) File(java.io.File)

Example 17 with StringsCompleter

use of org.apache.karaf.shell.support.completers.StringsCompleter in project cxf by apache.

the class EndpointCompleterSupport method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> list) {
    StringsCompleter delegate = new StringsCompleter();
    try {
        List<Bus> busses = 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(session, commandLine, list);
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry)

Aggregations

StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)17 ArrayList (java.util.ArrayList)4 Completer (org.apache.karaf.shell.api.console.Completer)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Command (org.apache.karaf.shell.api.console.Command)2 File (java.io.File)1 Collection (java.util.Collection)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 CamelContext (org.apache.camel.CamelContext)1 Bus (org.apache.cxf.Bus)1 Server (org.apache.cxf.endpoint.Server)1 ServerRegistry (org.apache.cxf.endpoint.ServerRegistry)1 CommandLine (org.apache.karaf.shell.api.console.CommandLine)1 Session (org.apache.karaf.shell.api.console.Session)1 ArgumentCommandLine (org.apache.karaf.shell.support.completers.ArgumentCommandLine)1