comm2j
Class Message

java.lang.Object
  |
  +--comm2j.Message
All Implemented Interfaces:
MessageI
Direct Known Subclasses:
ByteMessage, DateMessage, IntegerMessage, LongMessage, ShortMessage, StringMessage, VectorMessage

public abstract class Message
extends java.lang.Object
implements MessageI

Message is the basic class used to send and receive message to/from remote server.
It will be derived to manage different type of message.

Do NOT use this class directly!

Version:
1.0
Author:
Luca Bertoncello <lucabert@lucabert.de>
See Also:
Comm2J

Field Summary
protected  java.lang.String className
           
protected  java.lang.Object message
           
protected  boolean messageHasBeenSet
           
 
Constructor Summary
Message()
          Constructor.
 
Method Summary
 java.lang.Object getMessage()
          Returns the current message
 java.lang.String getName()
          Returns the name of the message class
 boolean isMessageSet()
          Used to know if a message was set (by setMessage or writeMessage)
 java.lang.String readHeader(java.io.InputStream is)
          Gets the header identifying the message type from the give InputStream
 int readMessage(java.io.InputStream is)
          Reads a message from give InputStream.
protected abstract  void setInternalObject(java.lang.Object obj)
          Sets the internal object.
 void setMessage(java.lang.Object message)
          Sets the message
 java.lang.String toString()
          Returns a string with the content of the message
 int writeHeader(java.io.OutputStream os)
          Send an header identifying the message type throw the give OutputStream
 int writeMessage(java.io.OutputStream os)
          Send current message throw given OutputStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

messageHasBeenSet

protected boolean messageHasBeenSet

message

protected java.lang.Object message

className

protected java.lang.String className
Constructor Detail

Message

public Message()
Constructor.
Method Detail

setMessage

public void setMessage(java.lang.Object message)
Sets the message
Specified by:
setMessage in interface MessageI
Parameters:
message - Message to be used

getMessage

public java.lang.Object getMessage()
Returns the current message
Specified by:
getMessage in interface MessageI
Returns:
The current message

readMessage

public int readMessage(java.io.InputStream is)
                throws java.io.IOException
Reads a message from give InputStream.
Specified by:
readMessage in interface MessageI
Parameters:
is - The InputStream used to read data
Returns:
Number of read bytes
Throws:
java.io.IOException - if an error occours

writeMessage

public int writeMessage(java.io.OutputStream os)
                 throws java.io.IOException
Send current message throw given OutputStream
Specified by:
writeMessage in interface MessageI
Parameters:
os - The OutputStream used to read data
Returns:
Number of wrote bytes
Throws:
java.io.IOException - if an error occours

isMessageSet

public boolean isMessageSet()
Used to know if a message was set (by setMessage or writeMessage)
Specified by:
isMessageSet in interface MessageI
Returns:
true is message was set

writeHeader

public int writeHeader(java.io.OutputStream os)
                throws java.io.IOException
Send an header identifying the message type throw the give OutputStream
Specified by:
writeHeader in interface MessageI
Parameters:
os - The OutputStream used to read data
Returns:
Number of wrote bytes
Throws:
java.io.IOException - if an error occours

readHeader

public java.lang.String readHeader(java.io.InputStream is)
                            throws java.io.IOException
Gets the header identifying the message type from the give InputStream
Specified by:
readHeader in interface MessageI
Parameters:
is - The InputStream used to read data
Returns:
The message type
Throws:
java.io.IOException - if an error occours

toString

public java.lang.String toString()
Returns a string with the content of the message
Specified by:
toString in interface MessageI
Overrides:
toString in class java.lang.Object
Returns:
A String identifying the message

getName

public java.lang.String getName()
Returns the name of the message class
Specified by:
getName in interface MessageI
Returns:
The class name

setInternalObject

protected abstract void setInternalObject(java.lang.Object obj)
Sets the internal object. This function is used by readMessage.
Usually you don't need to use it directly.
Parameters:
obj - Internal object to be set