Package org.mycore.frontend.cli
Class MCRCommand
java.lang.Object
org.mycore.frontend.cli.MCRCommand
Represents a command understood by the command line interface. A command has an external input syntax that the user
uses to invoke the command and points to a method in a class that implements the command.
- Version:
- $Revision$ $Date$
- Author:
- Frank Lützenkirchen, Jens Kupferschmidt
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
The class providing the implementation methodprotected String
The help text Stringprotected MessageFormat
The input format used for invoking this commandprotected String
The method implementing this commandprotected Class<?>[]
The types of the invocation parametersprotected String
The beginning of the message format up to the first parameter -
Constructor Summary
ModifierConstructorDescriptionprotected
use this to overwrite this class.MCRCommand
(Method cmd) MCRCommand
(String format, String methodSignature, String helpText) Creates a new MCRCommand. -
Method Summary
Modifier and TypeMethodDescriptionThe method return the helpt text of this command.final String
Returns the input syntax to be used for invoking this command from the command prompt.Tries to invoke the method that implements the behavior of this command given the user input from the command line.invoke
(String input, ClassLoader classLoader) void
protected Object[]
parseCommandLine
(String commandLine) Parses an input string and tries to match it with the message format used to invoke this command.void
-
Field Details
-
messageFormat
The input format used for invoking this command -
parameterTypes
The types of the invocation parameters -
className
The class providing the implementation method -
methodName
The method implementing this command -
suffix
The beginning of the message format up to the first parameter -
help
The help text String
-
-
Constructor Details
-
MCRCommand
protected MCRCommand()use this to overwrite this class. -
MCRCommand
Creates a new MCRCommand.- Parameters:
format
- the command syntax, e.g. "save document {0} to directory {1}"methodSignature
- the method to invoke, e.g. "miless.commandline.DocumentCommands.saveDoc int String"helpText
- the helpt text for this command
-
MCRCommand
-
-
Method Details
-
getHelpText
The method return the helpt text of this command.- Returns:
- the help text as String
-
parseCommandLine
Parses an input string and tries to match it with the message format used to invoke this command.- Parameters:
commandLine
- The input from the command line- Returns:
- null, if the input does not match the message format; otherwise an array holding the parameter values from the command line
-
invoke
public List<String> invoke(String input) throws IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException Tries to invoke the method that implements the behavior of this command given the user input from the command line. This is only done when the command line syntax matches the syntax used by this command.- Parameters:
input
- The command entered by the user at the command prompt- Returns:
- null, if the command syntax did not match and the command was not invoked, otherwise a List of commands is returned which may be empty or otherwise contains commands that should be processed next
- Throws:
IllegalAccessException
- when the method can not be invokedInvocationTargetException
- when an exception is thrown by the invoked methodClassNotFoundException
- when the class providing the method could not be foundNoSuchMethodException
- when the method specified does not exist
-
invoke
public List<String> invoke(String input, ClassLoader classLoader) throws IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException -
getSyntax
Returns the input syntax to be used for invoking this command from the command prompt.- Returns:
- the input syntax for this command
-
outputHelp
public void outputHelp() -
setMethod
- Parameters:
method
- the method to set
-