org.limitless.nmc.Prototype1
Class CommandProcessor

java.lang.Object
  extended by org.limitless.nmc.Prototype1.CommandProcessor

public class CommandProcessor
extends java.lang.Object

This provides the command dispatcher. It doesn't actually parse commands, but rather, it maps keywords to command objects that will do the job. To add a command, put a map entry in this class's constructor.

Version:
1.0
Author:
Brian Jones

Nested Class Summary
static class CommandProcessor.UnknownCommandException
          A command was given that isn't defined.
 
Field Summary
 Command Command
           
private  java.util.Map commandMap
          This holds (String,Command).
private  CommandParser commandParser
          The command-parser worker (stateless object).
private static CommandProcessor instance
          Singleton instance variable.
private static org.apache.log4j.Logger logger
           
private  boolean shutdownRequested
          This goes to true when a shutdown/exit request is given.
 
Constructor Summary
private CommandProcessor()
          This populates the map of commands to command-objects.
 
Method Summary
 Command fetchCommand(java.lang.String command)
          This is used to gain access to the command that would be dispatched.
(package private)  java.util.Collection fetchDefinedCommands()
           
static CommandProcessor Instance()
          Fetch the object to do the work.
 void invoke(java.lang.String rawInput)
          This is given an input command and causes it to be called.
 boolean isShutdownRequested()
          This returns true if a shutdown request was made.
(package private)  void requestShutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static org.apache.log4j.Logger logger

commandParser

private CommandParser commandParser
The command-parser worker (stateless object).


commandMap

private java.util.Map commandMap
This holds (String,Command).


instance

private static CommandProcessor instance
Singleton instance variable.


shutdownRequested

private boolean shutdownRequested
This goes to true when a shutdown/exit request is given.


Command

public Command Command
Constructor Detail

CommandProcessor

private CommandProcessor()
This populates the map of commands to command-objects.

Method Detail

requestShutdown

void requestShutdown()

isShutdownRequested

public boolean isShutdownRequested()
This returns true if a shutdown request was made.

Returns:
true if shutdown is requested

Instance

public static CommandProcessor Instance()
Fetch the object to do the work.

Returns:
The one and only one object.

fetchCommand

public Command fetchCommand(java.lang.String command)
                     throws CommandProcessor.UnknownCommandException
This is used to gain access to the command that would be dispatched. This is an excellent way to fetch an object to get its help text for instance. This is legal for use to bypass the built-in dispatcher, but it would require a lot more work to use.

Parameters:
command - Raw string of a single command line
Returns:
A Command object.
Throws:
CommandProcessor.UnknownCommandException

invoke

public void invoke(java.lang.String rawInput)
            throws CommandProcessor.UnknownCommandException
This is given an input command and causes it to be called. This can be given a command from any source.

Parameters:
rawInput - String for the command.
Throws:
CommandProcessor.UnknownCommandException

fetchDefinedCommands

java.util.Collection fetchDefinedCommands()


Copyright © 1995, 2004 Limitless Knowledge Association, All Rights Reserved.