edu.cuny.cat.comm
Class CatpMessage

java.lang.Object
  extended by edu.cuny.cat.comm.Message
      extended by edu.cuny.cat.comm.CatpMessage
Direct Known Subclasses:
CatpRequest, CatpResponse

public abstract class CatpMessage
extends Message

provides constant values used in catp messages and utility functions helpful to compose a catp message. Fore more details, please refer to the cat protocol specification.

Version:
$Revision: 1.35 $
Author:
Jinzhong Niu

Field Summary
static java.lang.String ASK
          ASK request type
static java.lang.String BID
          BID request type
static java.lang.String BUYER
          a header field value, telling the involved entity is a buyer.
static java.lang.String CHECKIN
          CHECKIN request type
static java.lang.String CLIENT
          a constant telling the context is about a catp client.
static java.lang.String CURRENT_VERSION
          catp version information.
static java.lang.String DAYCLOSED
          a header field value, telling a day is closed.
static java.lang.String DAYOPENED
          a header field value, telling a day is opened.
static java.lang.String DAYOPENING
          a header field value, telling a day is opening.
static java.lang.String ERROR
          ERROR response status code
static java.lang.String FEE
          a header field value, telling it is concerning market charging information.
static java.lang.String GAMEOVER
          a header field value, telling a game is over.
static java.lang.String GAMESTARTED
          a header field value, telling a game is started.
static java.lang.String GAMESTARTING
          a header field value, telling a game is starting.
static java.lang.String GET
          GET request type
static java.lang.String HEADER_SEPARATOR
          the string separating the name of a header field from its value.
protected  java.util.Map<java.lang.String,java.lang.String> headers
          stores header fields parsed out from the message
static java.lang.String ID
          ID header name.
static java.lang.String INFORMATION
          an identifier telling the context is about market information subscription.
static java.lang.String INVALID
          INVALID response status code
static java.lang.String OK
          OK response status code
static java.lang.String OPTIONS
          OPTIONS request type
static java.lang.String POST
          POST request type
static java.lang.String PROFIT
          a header field value, telling it is concerning profit of traders or specialists.
static java.lang.String REGISTER
          REGISTER request type
static java.lang.String REGISTRATION
          an identifier telling the context is about trader's registration with a market.
static java.lang.String ROUNDCLOSED
          a header field value, telling a round is closed.
static java.lang.String ROUNDCLOSING
          a header field value, telling a round is closing.
static java.lang.String ROUNDOPENED
          a header field value, telling a round is opened.
static java.lang.String ROUNDOPENING
          a header field value, telling a round is opening.
static java.lang.String SELLER
          a header field value, telling the involved entity is a seller.
static java.lang.String SHOUT
          an identifier telling the context is about a shout.
static java.lang.String SPECIALIST
          a header field value, telling the involved entity is a specialist.
protected  java.lang.String startLine
          the first line of the message
static java.lang.String SUBSCRIBE
          SUBSCRIBE request type
static java.lang.String TAG
          TAG header name.
static java.lang.String TEXT
          TEXT header name.
static java.lang.String TIME
          TIME header name.
static java.lang.String TRADER
          a header field value, telling the involved entity is a trader.
static java.lang.String TRANSACTION
          TRANSACTION request type
static java.lang.String TYPE
          TYPE header name.
static java.lang.String VALUE
          VALUE header name.
static java.lang.String VERSION
          VERSION header name.
static java.lang.String WRONGTIME
          a header field value used in a response message, telling the corresponding request arrives at a wrong time.
 
Fields inherited from class edu.cuny.cat.comm.Message
CRLF, VALUE_SEPARATOR
 
Constructor Summary
CatpMessage()
           
 
Method Summary
 void addHeader(java.lang.String name, java.lang.String header)
          appends a value to a message header field's value list, or sets it if it does not exist.
 double getDoubleHeader(java.lang.String name)
          retrieves the value of a header field as double.
 java.lang.String getHeader(java.lang.String name)
          retrieves the value of a header field.
 java.util.Set<java.lang.String> getHeaderNames()
           
 int getIntHeader(java.lang.String name)
          retrieves the value of a header field as integer.
 java.lang.String getStartLine()
          gets the starting line of this message.
 java.lang.String getTag()
           
 void setHeader(java.lang.String name, java.lang.String header)
          sets a message header field.
 void setHeaders(java.lang.String[] pairs)
          sets message fields in a batch mode.
 void setStartLine(java.lang.String line)
          sets the starting line of this message.
 void setTag(int tag)
          sets an integer as the value of the TAG field in the message.
 void setTag(java.lang.String tag)
          sets a string as the value of the TAG field in the message.
 java.lang.String toString()
           
 
Methods inherited from class edu.cuny.cat.comm.Message
concatenate, concatenate, concatenate, concatenate, parseDoubles, parseIntegers, parseStrings
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CURRENT_VERSION

public static java.lang.String CURRENT_VERSION
catp version information.


HEADER_SEPARATOR

public static java.lang.String HEADER_SEPARATOR
the string separating the name of a header field from its value.


CHECKIN

public static final java.lang.String CHECKIN
CHECKIN request type

See Also:
Constant Field Values

OPTIONS

public static final java.lang.String OPTIONS
OPTIONS request type

See Also:
Constant Field Values

POST

public static final java.lang.String POST
POST request type

See Also:
Constant Field Values

GET

public static final java.lang.String GET
GET request type

See Also:
Constant Field Values

REGISTER

public static final java.lang.String REGISTER
REGISTER request type

See Also:
Constant Field Values

SUBSCRIBE

public static final java.lang.String SUBSCRIBE
SUBSCRIBE request type

See Also:
Constant Field Values

ASK

public static final java.lang.String ASK
ASK request type

See Also:
Constant Field Values

BID

public static final java.lang.String BID
BID request type

See Also:
Constant Field Values

TRANSACTION

public static final java.lang.String TRANSACTION
TRANSACTION request type

Also used as an identifier telling the context is about a transaction.

See Also:
Constant Field Values

OK

public static final java.lang.String OK
OK response status code

See Also:
Constant Field Values

INVALID

public static final java.lang.String INVALID
INVALID response status code

See Also:
Constant Field Values

ERROR

public static final java.lang.String ERROR
ERROR response status code

See Also:
Constant Field Values

ID

public static final java.lang.String ID
ID header name.

See Also:
Constant Field Values

TYPE

public static final java.lang.String TYPE
TYPE header name.

See Also:
Constant Field Values

VALUE

public static final java.lang.String VALUE
VALUE header name.

See Also:
Constant Field Values

TEXT

public static final java.lang.String TEXT
TEXT header name.

See Also:
Constant Field Values

VERSION

public static final java.lang.String VERSION
VERSION header name.

See Also:
Constant Field Values

TAG

public static final java.lang.String TAG
TAG header name.

See Also:
Constant Field Values

TIME

public static final java.lang.String TIME
TIME header name.

See Also:
Constant Field Values

GAMESTARTING

public static final java.lang.String GAMESTARTING
a header field value, telling a game is starting.

See Also:
Constant Field Values

GAMESTARTED

public static final java.lang.String GAMESTARTED
a header field value, telling a game is started.

See Also:
Constant Field Values

GAMEOVER

public static final java.lang.String GAMEOVER
a header field value, telling a game is over.

See Also:
Constant Field Values

DAYOPENING

public static final java.lang.String DAYOPENING
a header field value, telling a day is opening.

See Also:
Constant Field Values

DAYOPENED

public static final java.lang.String DAYOPENED
a header field value, telling a day is opened.

See Also:
Constant Field Values

DAYCLOSED

public static final java.lang.String DAYCLOSED
a header field value, telling a day is closed.

See Also:
Constant Field Values

ROUNDOPENING

public static final java.lang.String ROUNDOPENING
a header field value, telling a round is opening.

See Also:
Constant Field Values

ROUNDOPENED

public static final java.lang.String ROUNDOPENED
a header field value, telling a round is opened.

See Also:
Constant Field Values

ROUNDCLOSING

public static final java.lang.String ROUNDCLOSING
a header field value, telling a round is closing.

See Also:
Constant Field Values

ROUNDCLOSED

public static final java.lang.String ROUNDCLOSED
a header field value, telling a round is closed.

See Also:
Constant Field Values

SPECIALIST

public static final java.lang.String SPECIALIST
a header field value, telling the involved entity is a specialist.

See Also:
Constant Field Values

TRADER

public static final java.lang.String TRADER
a header field value, telling the involved entity is a trader.

See Also:
Constant Field Values

BUYER

public static final java.lang.String BUYER
a header field value, telling the involved entity is a buyer.

See Also:
Constant Field Values

SELLER

public static final java.lang.String SELLER
a header field value, telling the involved entity is a seller.

See Also:
Constant Field Values

FEE

public static final java.lang.String FEE
a header field value, telling it is concerning market charging information.

See Also:
Constant Field Values

PROFIT

public static final java.lang.String PROFIT
a header field value, telling it is concerning profit of traders or specialists.

Also used as an identifier telling the context is about a shout.

See Also:
Constant Field Values

WRONGTIME

public static final java.lang.String WRONGTIME
a header field value used in a response message, telling the corresponding request arrives at a wrong time.

See Also:
Constant Field Values

SHOUT

public static final java.lang.String SHOUT
an identifier telling the context is about a shout.

See Also:
Constant Field Values

INFORMATION

public static final java.lang.String INFORMATION
an identifier telling the context is about market information subscription.

See Also:
Constant Field Values

REGISTRATION

public static final java.lang.String REGISTRATION
an identifier telling the context is about trader's registration with a market.

See Also:
Constant Field Values

CLIENT

public static final java.lang.String CLIENT
a constant telling the context is about a catp client.

See Also:
Constant Field Values

headers

protected java.util.Map<java.lang.String,java.lang.String> headers
stores header fields parsed out from the message


startLine

protected java.lang.String startLine
the first line of the message

Constructor Detail

CatpMessage

public CatpMessage()
Method Detail

getStartLine

public java.lang.String getStartLine()
gets the starting line of this message.

Returns:
the starting line.

setStartLine

public void setStartLine(java.lang.String line)
sets the starting line of this message.

Parameters:
line - the string to be used as the starting line.

getHeaderNames

public java.util.Set<java.lang.String> getHeaderNames()
Returns:
a set of the header fields' names in this message.

getHeader

public java.lang.String getHeader(java.lang.String name)
retrieves the value of a header field.

Parameters:
name - the header field's name.
Returns:
the value of the header field.

getIntHeader

public int getIntHeader(java.lang.String name)
                 throws CatpMessageErrorException
retrieves the value of a header field as integer.

Parameters:
name - the header field's name.
Returns:
the integer value of the header field.
Throws:
CatpMessageErrorException - if the value cannot be parsed as integer.

getDoubleHeader

public double getDoubleHeader(java.lang.String name)
                       throws CatpMessageErrorException
retrieves the value of a header field as double.

Parameters:
name - the header field's name.
Returns:
the double value of the header field.
Throws:
CatpMessageErrorException - if the value cannot be parsed as double.

addHeader

public void addHeader(java.lang.String name,
                      java.lang.String header)
appends a value to a message header field's value list, or sets it if it does not exist.

Parameters:
name - header name
header - header value

setHeader

public void setHeader(java.lang.String name,
                      java.lang.String header)
sets a message header field.

Parameters:
name - header name
header - header value

setHeaders

public void setHeaders(java.lang.String[] pairs)
sets message fields in a batch mode.

Parameters:
pairs - an array of odd length, in the format: field1, value1, field2, value2, ...

setTag

public void setTag(java.lang.String tag)
sets a string as the value of the TAG field in the message.

Parameters:
tag -

setTag

public void setTag(int tag)
sets an integer as the value of the TAG field in the message.

Parameters:
tag -

getTag

public java.lang.String getTag()
Returns:
the value of the TAG field in the message.

toString

public java.lang.String toString()
Specified by:
toString in class Message
Returns:
the plain-text representation of this catp message.