org.crsh.command
Class BaseCommand<C,P>

java.lang.Object
  extended by groovy.lang.GroovyObjectSupport
      extended by org.crsh.command.GroovyCommand
          extended by org.crsh.command.BaseCommand<C,P>
Type Parameters:
C - the consumed type
P - the produced type
All Implemented Interfaces:
groovy.lang.GroovyObject, CommandInvoker<C,P>, ShellCommand
Direct Known Subclasses:
ClassCommand

public abstract class BaseCommand<C,P>
extends GroovyCommand
implements ShellCommand, CommandInvoker<C,P>

The base command.

Version:
$Revision$
Author:
Julien Viet

Constructor Summary
protected BaseCommand()
           
 
Method Summary
 Map<String,String> complete(CommandContext context, String line)
          Provide completions for the specified arguments.
 CommandInvoker<?,?> createInvoker(String line)
          Provides an invoker for the specified arguments.
 String describe(String line, DescriptionMode mode)
          Returns a description of the command or null if none can be found.
protected abstract  void execute(InvocationContext<C,P> context)
           
 Class<C> getConsumedType()
          Returns the class of the consumed type.
protected  InvocationContext<?,?> getContext()
           
 Class<P> getProducedType()
          Returns the class of the produced type.
 boolean getUnquoteArguments()
          Returns true if the command wants its arguments to be unquoted.
 void invoke(InvocationContext<C,P> context)
           
protected  String readLine(String msg)
           
protected  String readLine(String msg, boolean echo)
           
 void setUnquoteArguments(boolean unquoteArguments)
           
 
Methods inherited from class org.crsh.command.GroovyCommand
getProperty, invokeMethod, setProperty
 
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, setMetaClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseCommand

protected BaseCommand()
Method Detail

getProducedType

public Class<P> getProducedType()
Description copied from interface: CommandInvoker
Returns the class of the produced type.

Specified by:
getProducedType in interface CommandInvoker<C,P>
Returns:
the produced type

getConsumedType

public Class<C> getConsumedType()
Description copied from interface: CommandInvoker
Returns the class of the consumed type.

Specified by:
getConsumedType in interface CommandInvoker<C,P>
Returns:
the consumed type

getUnquoteArguments

public final boolean getUnquoteArguments()
Returns true if the command wants its arguments to be unquoted.

Returns:
true if arguments must be unquoted

setUnquoteArguments

public final void setUnquoteArguments(boolean unquoteArguments)

readLine

protected final String readLine(String msg)

readLine

protected final String readLine(String msg,
                                boolean echo)

getContext

protected final InvocationContext<?,?> getContext()
Specified by:
getContext in class GroovyCommand

complete

public final Map<String,String> complete(CommandContext context,
                                         String line)
Description copied from interface: ShellCommand
Provide completions for the specified arguments.

Specified by:
complete in interface ShellCommand
Parameters:
context - the command context
line - the original command line arguments
Returns:
the completions

describe

public String describe(String line,
                       DescriptionMode mode)
Description copied from interface: ShellCommand
Returns a description of the command or null if none can be found.

Specified by:
describe in interface ShellCommand
Parameters:
line - the usage line
mode - the description mode
Returns:
the description

createInvoker

public final CommandInvoker<?,?> createInvoker(String line)
Description copied from interface: ShellCommand
Provides an invoker for the specified arguments.

Specified by:
createInvoker in interface ShellCommand
Parameters:
line - the command line arguments
Returns:
the command to provide

invoke

public final void invoke(InvocationContext<C,P> context)
                  throws ScriptException
Specified by:
invoke in interface CommandInvoker<C,P>
Parameters:
context - the command execution context
Throws:
ScriptException - any script exception

execute

protected abstract void execute(InvocationContext<C,P> context)
                         throws ScriptException
Throws:
ScriptException


Copyright © 2011 eXo Platform SAS. All Rights Reserved.