autohit.server.command
Class Command

java.lang.Object
  extended byautohit.server.command.Command
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
CommandCompile, CommandDump, CommandKill, CommandLoadProps, CommandProps, CommandPS, CommandRun, CommandSaveProps, CommandSet

public abstract class Command
extends java.lang.Object
implements java.io.Serializable

A command base class. All command inplementations should use extend it.

THIS IS NOT THREAD SAFE!!!! EVERY CommandServer should create their own instances!!!! There are object fields that store the command parameters. It's the cleanest way to do it. Cope and deal.

All exceptions should/will be caught and reported on the response channel except if the command is poorly formed (it still will try to report) or is a very serious problem.

Command sequence is as follows: 1- Command class instantiation 2- Get command parameters. Kept in a vector. Contstructed with the helper static method createCommand() 0-UNI - (has default) Universe 1-RESPONSE - (has default) Injector for control response channel 2-TARGET - (has default) Injector for target channel 3-CLASS - Implementation class 4-COMMAND - Command string 5-OBJECT - Data object 3- Call the command with call() - Setup base 4- Call verify in subclass() - Subclass should call assert method in base for required/optional for the parameters. - The assert method will set the object fields. - The base assert will throw an exception for any error. It MUST be passed along. The base will handle any reporting. 5- Base will accept the command. 6- Passed into chained execute() - Problems should be thrown as exceptions 7- Base will ack or nak the command. 8- Return a receipt

Version:
1.0 Version HistoryEPG - Initial - 24Jul03 EPG - Rewrite - 31Jul03
Author:
Erich P. Gatejen
See Also:
Serialized Form

Field Summary
static int CLASS_LIST_INDEX
           
 java.lang.String classobject
           
 java.lang.String command
           
static int COMMAND_LIST_INDEX
           
 java.lang.Object data
           
static int OBJECT_LIST_INDEX
           
 Injector response
           
static char RESPONSE_ELEMENT_SEPERATOR
          Constants
static int RESPONSE_LIST_INDEX
           
protected  SystemContext sc
           
 Injector target
           
static int TARGET_LIST_INDEX
           
 Universe uni
          Command objects.
static int UNI_LIST_INDEX
           
 int uniqueID
           
 
Constructor Summary
Command()
           
 
Method Summary
protected  void assertparam(boolean univ, boolean resp, boolean targ, boolean cobj, boolean cmd, boolean dobj)
          Assert the parameters.
 Receipt call(SystemContext c, java.util.Vector cl)
          Execute the command.
static java.util.Vector createCommand(Universe univ, Injector resp, Injector targ, java.lang.String cobj, java.lang.String cmd, java.lang.Object dobj)
          Create a command list.
abstract  java.lang.String execute()
          Execute the command.
 java.lang.String getMsgHeader()
           
abstract  java.lang.String getName()
          Get the textual name for the command.
 void respond(java.lang.String info, int code, Receipt rr)
          Send response.
 void sendTarget(java.lang.String info, int code, Receipt rr)
          Send target.
abstract  java.lang.String verify()
          Verify the command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESPONSE_ELEMENT_SEPERATOR

public static final char RESPONSE_ELEMENT_SEPERATOR
Constants

See Also:
Constant Field Values

UNI_LIST_INDEX

public static final int UNI_LIST_INDEX
See Also:
Constant Field Values

RESPONSE_LIST_INDEX

public static final int RESPONSE_LIST_INDEX
See Also:
Constant Field Values

TARGET_LIST_INDEX

public static final int TARGET_LIST_INDEX
See Also:
Constant Field Values

CLASS_LIST_INDEX

public static final int CLASS_LIST_INDEX
See Also:
Constant Field Values

COMMAND_LIST_INDEX

public static final int COMMAND_LIST_INDEX
See Also:
Constant Field Values

OBJECT_LIST_INDEX

public static final int OBJECT_LIST_INDEX
See Also:
Constant Field Values

uni

public Universe uni
Command objects. Don't change these!


response

public Injector response

target

public Injector target

classobject

public java.lang.String classobject

command

public java.lang.String command

data

public java.lang.Object data

uniqueID

public int uniqueID

sc

protected SystemContext sc
Constructor Detail

Command

public Command()
Method Detail

execute

public abstract java.lang.String execute()
                                  throws ServerException
Execute the command.

Returns:
return the manreadable message for success.
Throws:
ServerException

verify

public abstract java.lang.String verify()
                                 throws ServerException
Verify the command. Basically, it should just call the assert method with the six parameters indicating if the fields are required or not (optional). The first three (uni, target, and reponse) have defaults, if nothing is passed. However, the the assert will throw an exception if it is marked as required but isn't present.

The exception from accept should not be intercepted! The following is an example implementation.

public String verify() throws ServerException { this.assert(true,true,false,false,false,true); return "parameters are good."; }

Returns:
return the manreadable message for accepting the command.
Throws:
ServerException

getName

public abstract java.lang.String getName()
Get the textual name for the command.

Returns:
return the manreadable name of this command.

call

public Receipt call(SystemContext c,
                    java.util.Vector cl)
             throws ServerException
Execute the command. String Method.

it will throw a ServerException if the command is poorly formed and cannot be accepted or there is a serious system problem. Outwise it should just log issues to the response (or default) and return no receipt.

Parameters:
c - the System Context
cl - the command list in a Vector
Returns:
a receipt for the transaction (given by the responseChannel). This can be a log injector.
Throws:
ServerException

assertparam

protected void assertparam(boolean univ,
                           boolean resp,
                           boolean targ,
                           boolean cobj,
                           boolean cmd,
                           boolean dobj)
                    throws ServerException
Assert the parameters.

Parameters:
univ - is 0-UNI required?
resp - is 1-RESPONSE required?
targ - is 2-TARGET required?
cobj - is 3-CLASS required?
cmd - is 4-COMMAND required?
dobj - is 5-OBJECT required?
Throws:
ServerException. - Do not intercept it!
ServerException

getMsgHeader

public java.lang.String getMsgHeader()

respond

public void respond(java.lang.String info,
                    int code,
                    Receipt rr)
             throws java.lang.Exception
Send response. The response MUST be set.

Parameters:
info - text of the response
code - code of the response. Usually an EVENT
rr - Receipt for the command. May be null, if none was issued.
Throws:
java.lang.Exception

sendTarget

public void sendTarget(java.lang.String info,
                       int code,
                       Receipt rr)
                throws java.lang.Exception
Send target. The target MUST be set.

Parameters:
info - text of the response
code - code of the response. Usually an EVENT
rr - Receipt for the command. May be null, if none was issued.
Throws:
java.lang.Exception

createCommand

public static java.util.Vector createCommand(Universe univ,
                                             Injector resp,
                                             Injector targ,
                                             java.lang.String cobj,
                                             java.lang.String cmd,
                                             java.lang.Object dobj)
Create a command list. It is a very good object to make all passed items Serializable. You cannot predict how the command will be issued. you can pass null for any parameter you don't want to pass.

Parameters:
univ - Specify a universe object?
resp - Specify a response Injector?
targ - Specify a target Injector?
cobj - Specify a command Class implementation (string name)?
cmd - Specify a command string?
dobj - Specify a data object?
Returns:
a Vector representing the command.


Test.