001: /*
002: * This is free software, licensed under the Gnu Public License (GPL)
003: * get a copy from <http://www.gnu.org/licenses/gpl.html>
004: *
005: * author: Henner Zeller <H.Zeller@acm.org>
006: */
007: package henplus;
008:
009: import java.util.Iterator;
010: import java.util.StringTokenizer;
011:
012: import org.apache.commons.cli.CommandLine;
013: import org.apache.commons.cli.Option;
014: import org.apache.commons.cli.Options;
015:
016: /**
017: * Implementation of a Command with default settings. Override
018: * what is necessary in your Command. It makes sense to derive plug-ins
019: * from this AbstractCommand - this makes the plug-in more robust
020: * with regard to newly added methods.
021: * @author Henner Zeller
022: */
023: public abstract class AbstractCommand implements Command {
024:
025: private Options options;
026:
027: // no description by default.
028: public String getShortDescription() {
029: return null;
030: }
031:
032: public String getLongDescription(String cmd) {
033: return null;
034: }
035:
036: public String getSynopsis(String cmd) {
037: return null;
038: }
039:
040: // All commands are completed by default.
041: public boolean participateInCommandCompletion() {
042: return true;
043: }
044:
045: // no completion support by the commmand
046: public Iterator complete(CommandDispatcher disp,
047: String partialCommand, String lastWord) {
048: return null;
049: }
050:
051: public void shutdown() { /* don't care */
052: }
053:
054: // the simple commands are always complete on newline or semicolon
055: public boolean isComplete(String command) {
056: return true;
057: }
058:
059: public boolean requiresValidSession(String cmd) {
060: return true;
061: }
062:
063: /**
064: * convenience method: returns the number of elements in this
065: * string, separated by whitespace.
066: */
067: protected int argumentCount(String command) {
068: return (new StringTokenizer(command)).countTokens();
069: }
070:
071: protected Options getOptions() {
072: return options;
073: }
074:
075: public void setOptions(Options options) {
076: this .options = options;
077: }
078:
079: public Option getOption(String arg0) {
080: return options.getOption(arg0);
081: }
082:
083: /**
084: * Override this method if you want to register command-specific options
085: * @param r
086: */
087: public void registerOptions(Options r) {
088:
089: }
090:
091: public void handleCommandline(CommandLine line) {
092:
093: }
094: }
095:
096: /*
097: * Local variables:
098: * c-basic-offset: 4
099: * compile-command: "ant -emacs -find build.xml"
100: * End:
101: */
|