From 741c1ae7c50d5efad38cd576dfe670e5ff471c8e Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sat, 5 May 2007 14:35:10 +0000 Subject: [PATCH] bring back ptql shell completion --- .../hyperic/sigar/cmd/SigarCommandBase.java | 7 +- .../sigar/shell/ProcessQueryCompleter.java | 186 ++++++++++++++++++ 2 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 bindings/java/src/org/hyperic/sigar/shell/ProcessQueryCompleter.java diff --git a/bindings/java/src/org/hyperic/sigar/cmd/SigarCommandBase.java b/bindings/java/src/org/hyperic/sigar/cmd/SigarCommandBase.java index e134d551..e2ae2121 100644 --- a/bindings/java/src/org/hyperic/sigar/cmd/SigarCommandBase.java +++ b/bindings/java/src/org/hyperic/sigar/cmd/SigarCommandBase.java @@ -38,6 +38,7 @@ import org.hyperic.sigar.util.GetlineCompleter; import org.hyperic.sigar.util.PrintfFormat; import org.hyperic.sigar.shell.CollectionCompleter; +import org.hyperic.sigar.shell.ProcessQueryCompleter; import org.hyperic.sigar.shell.ShellCommandBase; import org.hyperic.sigar.shell.ShellCommandExecException; import org.hyperic.sigar.shell.ShellCommandUsageException; @@ -53,6 +54,7 @@ public abstract class SigarCommandBase protected SigarProxy proxy; protected List output = new ArrayList(); private CollectionCompleter completer; + private GetlineCompleter ptqlCompleter; private Collection completions = new ArrayList(); private PrintfFormat formatter; private ArrayList printfItems = new ArrayList(); @@ -66,6 +68,9 @@ public abstract class SigarCommandBase //provide simple way for handlers to implement tab completion this.completer = new CollectionCompleter(shell); + if (isPidCompleter()) { + this.ptqlCompleter = new ProcessQueryCompleter(shell); + } } public SigarCommandBase() { @@ -205,7 +210,7 @@ public abstract class SigarCommandBase return line; } - return line; //XXX bring back ptql completion + return this.ptqlCompleter.complete(line); } public String complete(String line) { diff --git a/bindings/java/src/org/hyperic/sigar/shell/ProcessQueryCompleter.java b/bindings/java/src/org/hyperic/sigar/shell/ProcessQueryCompleter.java new file mode 100644 index 00000000..ee784566 --- /dev/null +++ b/bindings/java/src/org/hyperic/sigar/shell/ProcessQueryCompleter.java @@ -0,0 +1,186 @@ +/* + * Copyright (C) [2004, 2005, 2006], Hyperic, Inc. + * This file is part of SIGAR. + * + * SIGAR is free software; you can redistribute it and/or modify + * it under the terms version 2 of the GNU General Public License as + * published by the Free Software Foundation. This program is distributed + * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + */ + +package org.hyperic.sigar.shell; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.hyperic.sigar.SigarProxy; +import org.hyperic.sigar.util.GetlineCompleter; + +public class ProcessQueryCompleter implements GetlineCompleter { + + private static final String SIGAR_PACKAGE = + "org.hyperic.sigar."; + + private static final Map METHODS = new HashMap(); + + private static final Collection NOPS = + Arrays.asList(new String[] { + "eq", "ne", "gt", "ge", "lt", "le" + }); + + private static final Collection SOPS = + Arrays.asList(new String[] { + "eq", "ne", "re", "ct", "ew", "sw" + }); + + private static final Class[] NOPARAM = new Class[0]; + private static final String PROC_PREFIX = "getProc"; + + private ShellBase shell; + private GetlineCompleter m_completer; + private Map methods; + + static { + Method[] methods = SigarProxy.class.getMethods(); + + for (int i=0; i