|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.uniba.wiai.lspi.util.console.CommandFactory
public class CommandFactory
Factory responsible to create instances of Command given the commands
name. The factory must be supplied with a mapping from the commands' names to
the commands' classes, which are subclasses of Command. The mapping
is provided through a Hashtable containing keys (Strings) representing
command names and values (Strings) representing class names.
MyClass toCommand = new MyClass(...);
Hashtable
myMapping = new Hashtable();
myMapping.put("exit",
MyExitCommand.class.getName());
...
CommandFactory factory = new
CommandFactory(toCommand, myMapping);
CommandFactory.
This factory is used by ConsoleThread.
| Constructor Summary | |
|---|---|
CommandFactory(java.lang.Object[] toCommand,
java.io.PrintStream out,
java.util.Map<java.lang.String,java.lang.String> commandMapping)
Creates a new instance of CommandFactory. |
|
| Method Summary | |
|---|---|
void |
addCommand(java.lang.String name,
java.lang.String cmdClass)
Add the given Command cmd to this command factory. |
Command |
createCommand(java.lang.String commandLine)
Creates the Command instance corresponding to the given command
name. |
java.io.PrintStream |
getPrintStream()
Get the PrintStream, to that all Commands created by this
factory, print their output to. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CommandFactory(java.lang.Object[] toCommand,
java.io.PrintStream out,
java.util.Map<java.lang.String,java.lang.String> commandMapping)
out - The PrintStream, to that all Commands created by this
factory, print their output to.toCommand - The Objects to execute commands on.commandMapping - The mapping from command name to command class. This must not
be null or have a size of zero!| Method Detail |
|---|
public void addCommand(java.lang.String name,
java.lang.String cmdClass)
Command cmd to this command factory.
name - The name of the command to add.cmdClass - The class name of Command to add.public java.io.PrintStream getPrintStream()
Commands created by this
factory, print their output to.
public Command createCommand(java.lang.String commandLine)
throws ConsoleException
Command instance corresponding to the given command
name. Therefore the given command line is parsed with help of
CommandParser, the command name and parameters extracted from
it, the correspondig Command created and the parameters passed to
the command. Then the command is returned.
commandLine - The command line entered into the console (See
ConsoleThread).
ConsoleException - Any Exception during creation of command.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||