|
|||||||||
| 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.
| Field Summary | |
|---|---|
protected Map<String,String> |
commandMapping
The mapping from command name to command class name. |
protected Map<String,Command> |
instanceMap
Map containing already instantiated commands. |
protected PrintStream |
out
The PrintStream to that all Commands print their outputs. |
protected Object[] |
toCommand
The Objects given to the Commands to execute commands on. |
| Constructor Summary | |
|---|---|
CommandFactory(Object[] toCommand,
PrintStream out,
Map<String,String> commandMapping)
Creates a new instance of CommandFactory. |
|
| Method Summary | |
|---|---|
void |
addCommand(String name,
String cmdClass)
Add the given Command cmd to this command factory. |
Command |
createCommand(String commandLine)
Creates the Command instance corresponding to the given command
name. |
PrintStream |
getPrintStream()
Get the PrintStream, to that all Commands created by this
factory, print their output to. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Object[] toCommand
protected Map<String,String> commandMapping
protected Map<String,Command> instanceMap
Command .
protected PrintStream out
Commands print their outputs.
| Constructor Detail |
|---|
public CommandFactory(Object[] toCommand,
PrintStream out,
Map<String,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(String name,
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 PrintStream getPrintStream()
Commands created by this
factory, print their output to.
public Command createCommand(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 | ||||||||