com.web_visage.ichat
Class IChatMessage

java.lang.Object
  extended by com.web_visage.ichat.IChatMessage
All Implemented Interfaces:
ByteRepresentable, IChatMessageConstants
Direct Known Subclasses:
IChatAlertMessage, IChatBoardMessage, IChatConnectMessage, IChatCreateLineMessage, IChatCreateMessage, IChatDisconnectMessage, IChatMeMessage, IChatReceivedMessage, IChatRefreshBoardMessage, IChatRefreshMessage, IChatRenameMessage, IChatStatusMessage, IChatStatusReqMessage, IChatTextMessage

public abstract class IChatMessage
extends java.lang.Object
implements IChatMessageConstants, ByteRepresentable

Represents abstract iChat message structure.

iChat message pattern is following:
[0x13] ["iChat"] [incremental id string] [0x13 0x13] [sender] [0x13 0x13] [command name] [0x13 0x13] [command parameters]
Command parameter pattern is following:
[parameter string] [0x13 0x13] [parameter string] [0x13]

This implementation is not completely immutable since it changes it's inner state, but is is free from the external changes and is compeletely thread-safe.

Author:
K.Baturytski

Field Summary
 
Fields inherited from interface com.web_visage.ichat.IChatMessageConstants
BEGIN_END_MARKER, COMMON_LINE, ICHAT_TAG, PRIVATE_TAG, SEPARATOR, WILDCARD
 
Constructor Summary
IChatMessage(int aMsgNumber, EnumIChatCommand aCommand, IChatSender aSender, java.lang.String[] aParameters)
          Constructor.
 
Method Summary
abstract  void acceptVisitor(IChatMessageVisitor aVisitor)
          Accepts the IChatMessageVisitorimplementations.
 byte[] asByteArray()
          Generates a byte array representation of the message.
 boolean equals(java.lang.Object anObj)
           
 EnumIChatCommand getCmd()
          Returns message's command.
 int getMsgNumber()
          Returns incremental message id.
 java.lang.String getParameter(int anIdx)
          Returns parameter by the given parameter index.
 java.lang.String[] getParameters()
          Returns command's parameters.
 IChatSender getSender()
          Returns a sender.
 int getSize()
          Returns byte-representation's size of the message.
 int hashCode()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IChatMessage

public IChatMessage(int aMsgNumber,
                    EnumIChatCommand aCommand,
                    IChatSender aSender,
                    java.lang.String[] aParameters)
Constructor.

Parameters:
aMsgNumber - - incremental message id
aCommand - - iChat command
aSender - - a sender
aParameters - - command's parameters, allows null
Method Detail

getSize

public final int getSize()
Returns byte-representation's size of the message.

Returns:

asByteArray

public final byte[] asByteArray()
Generates a byte array representation of the message.

iChat messages pattern is following:
[0x19] ["iChat"] [0x13 0x13] [incremental id string] [0x13 0x13] [Sender] [0x13 0x13] [Command name] [0x13 0x13] [parameters]

Command parameter pattern is following:
[parameter string] [0x13 0x13] [parameter string] [0x13]

Specified by:
asByteArray in interface ByteRepresentable
Returns:

getCmd

public final EnumIChatCommand getCmd()
Returns message's command.

Returns:

getMsgNumber

public final int getMsgNumber()
Returns incremental message id.

Returns:

getParameters

public final java.lang.String[] getParameters()
Returns command's parameters.

Returns:
command parameters

getParameter

public final java.lang.String getParameter(int anIdx)
Returns parameter by the given parameter index.

Parameters:
anIdx -
Returns:

getSender

public final IChatSender getSender()
Returns a sender.

Returns:

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

equals

public boolean equals(java.lang.Object anObj)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

acceptVisitor

public abstract void acceptVisitor(IChatMessageVisitor aVisitor)
Accepts the IChatMessageVisitorimplementations.

Parameters:
aVisitor -