|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectautohit.server.command.Command
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
EPG - Initial - 24Jul03
EPG - Rewrite - 31Jul03
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 |
public static final char RESPONSE_ELEMENT_SEPERATOR
public static final int UNI_LIST_INDEX
public static final int RESPONSE_LIST_INDEX
public static final int TARGET_LIST_INDEX
public static final int CLASS_LIST_INDEX
public static final int COMMAND_LIST_INDEX
public static final int OBJECT_LIST_INDEX
public Universe uni
public Injector response
public Injector target
public java.lang.String classobject
public java.lang.String command
public java.lang.Object data
public int uniqueID
protected SystemContext sc
Constructor Detail |
public Command()
Method Detail |
public abstract java.lang.String execute() throws ServerException
ServerException
public abstract java.lang.String verify() throws ServerException
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.";
}
ServerException
public abstract java.lang.String getName()
public Receipt call(SystemContext c, java.util.Vector cl) throws ServerException
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.
c
- the System Contextcl
- the command list in a Vector
ServerException
protected void assertparam(boolean univ, boolean resp, boolean targ, boolean cobj, boolean cmd, boolean dobj) throws ServerException
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?
ServerException.
- Do not intercept it!
ServerException
public java.lang.String getMsgHeader()
public void respond(java.lang.String info, int code, Receipt rr) throws java.lang.Exception
info
- text of the responsecode
- code of the response. Usually an EVENTrr
- Receipt for the command. May be null, if none was issued.
java.lang.Exception
public void sendTarget(java.lang.String info, int code, Receipt rr) throws java.lang.Exception
info
- text of the responsecode
- code of the response. Usually an EVENTrr
- Receipt for the command. May be null, if none was issued.
java.lang.Exception
public static java.util.Vector createCommand(Universe univ, Injector resp, Injector targ, java.lang.String cobj, java.lang.String cmd, java.lang.Object dobj)
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?
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |