QJCC homepage

biz.chitec.quarterback.gjsa
Class ServerRequest

java.lang.Object
  extended bybiz.chitec.quarterback.gjsa.ServerRequest
All Implemented Interfaces:
java.io.Serializable

public final class ServerRequest
extends java.lang.Object
implements java.io.Serializable

Representation of a Request sent by a GJSA client to a server. A request consists of a command and an arbitrary list of parameters.

Version:
$Id: b1b7bef5b8e9815d583813689116160ff77142b2 $
Author:
Dirk Hillbrecht 1997-2000, chitec/Dirk Hillbrecht 2000. Distributed under the terms of the GNU LGPL.
See Also:
Serialized Form

Field Summary
 int command
           
static java.util.List cshv
           
private static Logger mess
           
 java.lang.Object[] param
           
 
Constructor Summary
ServerRequest()
           
ServerRequest(int c)
           
ServerRequest(int c, java.lang.Object p1)
           
ServerRequest(int c, java.lang.Object[] x)
           
ServerRequest(int c, java.lang.Object p1, java.lang.Object p2)
           
ServerRequest(int c, java.lang.Object p1, java.lang.Object p2, java.lang.Object p3)
           
ServerRequest(int c, java.lang.Object p1, java.lang.Object p2, java.lang.Object p3, java.lang.Object p4)
           
 
Method Summary
static void addChatSymbolHolder(ChatSymbolHolder cshx)
           
static boolean convertBooleanArgument(java.lang.Object arg, boolean defaultvalue)
          Converts an argument with boolean background into a boolean.
static int convertIntegerArgument(java.lang.Object o)
          Return an integer representation of the given object.
static int convertIntegerArgument(java.lang.Object o, int defaultvalue)
          Return an integer representation of the given object or the default value if the object is null.
 boolean getBooleanParam(int i)
          Returns the i-th parameter as boolean value.
 boolean getBooleanParam(int i, boolean defaultvalue)
          Returns the i-th parameter as boolean value or default if parameter is not given.
 int getCommand()
           
 java.lang.String getCommandName()
           
static int getCommandNum(java.lang.String n)
           
 java.util.List getIntListParam(int i)
          Returns the i-th parameter as List of Integer, even if it is not a List.
 int getIntParam(int i)
          Returns the i-th parameter as int value or default if paramter is not given.
 int getIntParam(int i, int defaultvalue)
          Returns the i-th parameter as int value or default if paramter is not given.
 java.lang.Object getParam(int i)
          Return i-th parameter or null if parameter array is shorter.
 int getParamCount()
          Return the number of parameters which is taken from the length of the parameter array.
 QuickIntArray getQuickIntArrayParam(int i)
          Returns the i-th parameter as QuickIntArray, even if it is not one in the first place.
 int getSymbolTableArgument(int i, ChatSymbolHolder symboltable)
          Returns the i-th parameter as symbol table argument.
 java.util.List getVersion()
           
 void prependParam(java.lang.Object o)
          Prepend the given parameter as first one.
 ServerRequest setCmdAndParams(int cmd, java.lang.Object[] params)
          Combined functional init method.
 void setCommand(int cmd)
           
static void setLogger(Logger m)
          Set a class logger.
 void setParam(int i, java.lang.Object prms)
           
 void setParam(java.lang.Object[] prms)
           
 java.lang.String toString()
          convert to a string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mess

private static Logger mess

cshv

public static java.util.List cshv

command

public int command

param

public java.lang.Object[] param
Constructor Detail

ServerRequest

public ServerRequest()

ServerRequest

public ServerRequest(int c)

ServerRequest

public ServerRequest(int c,
                     java.lang.Object[] x)

ServerRequest

public ServerRequest(int c,
                     java.lang.Object p1)

ServerRequest

public ServerRequest(int c,
                     java.lang.Object p1,
                     java.lang.Object p2)

ServerRequest

public ServerRequest(int c,
                     java.lang.Object p1,
                     java.lang.Object p2,
                     java.lang.Object p3)

ServerRequest

public ServerRequest(int c,
                     java.lang.Object p1,
                     java.lang.Object p2,
                     java.lang.Object p3,
                     java.lang.Object p4)
Method Detail

setLogger

public static void setLogger(Logger m)
Set a class logger.


addChatSymbolHolder

public static void addChatSymbolHolder(ChatSymbolHolder cshx)

prependParam

public void prependParam(java.lang.Object o)
Prepend the given parameter as first one. All currently available parameters are shifted one index higher and the new parameter is added at index 0.

Parameters:
o - New parameter

getVersion

public java.util.List getVersion()

getCommandName

public java.lang.String getCommandName()

getCommandNum

public static int getCommandNum(java.lang.String n)

toString

public java.lang.String toString()
convert to a string


setCommand

public void setCommand(int cmd)

getCommand

public int getCommand()

setParam

public void setParam(java.lang.Object[] prms)

setParam

public void setParam(int i,
                     java.lang.Object prms)

setCmdAndParams

public ServerRequest setCmdAndParams(int cmd,
                                     java.lang.Object[] params)
Combined functional init method. Sets command and parameters and returns the object itself. This allows fast access for reusage of an already existing ServerRequest object. This method allows calls like sc.query(sq.setCmdAndParams(a,new Object[] {b,c,d}));.

Parameters:
cmd - The command to send
params - An array of parameters
Returns:
this very object (for a functional-like programming style)

getParam

public java.lang.Object getParam(int i)
Return i-th parameter or null if parameter array is shorter. There is no difference in the behaviour of this method between an array which is shorter than the given parameter index or an array which is large enough but has a null stored at the i-th position.

Parameters:
i - index of wanted parameter
Returns:
value of the parameter or null

convertBooleanArgument

public static boolean convertBooleanArgument(java.lang.Object arg,
                                             boolean defaultvalue)
Converts an argument with boolean background into a boolean. arg can be of type If arg is null, the given default value is returned.

Parameters:
arg - Some argument which should be evaluated as a boolean
defaultvalue - default value which is to be returned if the argument is null
Returns:
boolean evaluation of the argument, default value if argument is null

getBooleanParam

public boolean getBooleanParam(int i)
Returns the i-th parameter as boolean value.

Parameters:
i - index of wanted parameter
Returns:
parameter's value as boolean
Throws:
java.lang.NullPointerException - if parameter is not available
java.lang.ArrayIndexOutOfBoundsException - if number of parameters is too small

getBooleanParam

public boolean getBooleanParam(int i,
                               boolean defaultvalue)
Returns the i-th parameter as boolean value or default if parameter is not given.

Parameters:
i - index of wanted parameter
defaultvalue - value to return if parameter is not given
Returns:
parameter's value as boolean or default value
Throws:
java.lang.ClassCastException - if parameter is available but no Boolean

convertIntegerArgument

public static int convertIntegerArgument(java.lang.Object o)
Return an integer representation of the given object.

Parameters:
o - Some value.
Returns:
int of the given value
Throws:
java.lang.NullPointerException - if value is null
java.lang.NumberFormatException - if the value cannot be converted into an integer

convertIntegerArgument

public static int convertIntegerArgument(java.lang.Object o,
                                         int defaultvalue)
Return an integer representation of the given object or the default value if the object is null.

Parameters:
o - Some value.
defaultvalue - default value if the value is null
Returns:
int of the given value or the default value or any other problem arises

getSymbolTableArgument

public int getSymbolTableArgument(int i,
                                  ChatSymbolHolder symboltable)
Returns the i-th parameter as symbol table argument. If the parameter is a number, its intValue() is returned verbatim. It is not checked whether the number is a valid symbol in the table. Otherwise, toString() is called and a conversion into a symbol is performed.

Parameters:
i - index of the wanted parameter
symboltable - Symbol table to convert string-type value
Returns:
Numeric value of the symbol given.

getIntParam

public int getIntParam(int i)
Returns the i-th parameter as int value or default if paramter is not given. If the parameter is a Number, its intValue() is returned. In any other case, its String value is interpreted as an integer and the result is returned. Exceptions are thrown if the parameter does not exist or cannot be interpreted as a number.

Parameters:
i - position of the parameter in question
Returns:
parameter's value as int
Throws:
java.lang.NumberFormatException - if the parameter is no Number and cannot be converted into an int
java.lang.NullPointerException - if the parameter does not exist

getIntParam

public int getIntParam(int i,
                       int defaultvalue)
Returns the i-th parameter as int value or default if paramter is not given. If the parameter is a Number, its intValue() is returned. If it is null, the default value is returned. In any other case, its String value is taken. If it has no length, the default value is returned. Otherwise, the String is interpreted as an integer and the result is returned.

Parameters:
i - position of the parameter in question
defaultvalue - value to return if the parameter is not given
Returns:
parameter's value as int or default value

getIntListParam

public java.util.List getIntListParam(int i)
Returns the i-th parameter as List of Integer, even if it is not a List. The method converts the parameter internally into a List of Integers (using QuickIntArray), if it is not a list in the first place. Note that if it actually is a List, the type of the contents is not checked.

Parameters:
i - index of wanted parameter
Returns:
List of Integers or null if parameter does not exist or is null
Throws:
java.lang.ClassCastException - if parameter cannot be converted into List of Integers

getQuickIntArrayParam

public QuickIntArray getQuickIntArrayParam(int i)
Returns the i-th parameter as QuickIntArray, even if it is not one in the first place. The method converts the parameter internally into a QuickIntArray, if it is not in the first place.

Parameters:
i - index of wanted parameter
Returns:
QuickIntArray or null if parameter does not exist or is null
Throws:
java.lang.ClassCastException - if parameter cannot be converted into List of Integers

getParamCount

public int getParamCount()
Return the number of parameters which is taken from the length of the parameter array.

Returns:
number of parameters

QJCC homepage