org.PingOO.DLAI.PPM.net
Class MasterMessageFormatter

java.lang.Object
  |
  +--org.PingOO.DLAI.lib.util.MessageFormatter
        |
        +--org.PingOO.DLAI.PPM.net.MasterMessageFormatter

public final class MasterMessageFormatter
extends MessageFormatter

Formats outgoing message so they conform the PingOO protocol and so they can be understood by the server. Also formats incoming messages by removing all parts that are must remain hidden from the upper classes.

Since:
PingOO 2.0
Version:
2.0
Author:
Fabrice Bouyé (bouye@cur-archamps.fr)
See Also:
MessageHashtable

Field Summary
private static java.lang.String ARRAY_TAG
          Indicates a simple value.
private  byte[] byteBuffer
          Byte buffer, used when reading lines.
private static java.lang.String END_TAG
          Indicates the end of the parameters list in the PingOO protocol.
private static java.lang.String FILE_TAG
          Indicates a file.
private static java.lang.String HASH_KEY_TAG
          Indicates a list of hastable keys.
private static java.lang.String HASH_VALUE_TAG
          Indicates a list of hashtable values.
private static java.lang.String KEY_SEPARATORS
          Separator for the inner keys.
private static java.lang.String KEY_TAG
          Separates the different the inner keys.
private static java.lang.String LINE_TAG
          Terminates the line.
private static java.lang.String OBJECT_SEPARATORS
          Separator for the objets lists.
private static java.lang.String PARAM_TAG
          Separates the type from the values.
private static java.lang.String PORT_TAG
          Separates the server's name from it's port.
private static java.lang.String PROTOCOL_NAME_TAG
          Stores the name of the pingoo protocol.
private static java.lang.String PROTOCOL_TAG
          Separates the protocol descriptor from th rest of the URL.
private static java.lang.String REQUEST_ID_TAG
          Indicates an id line.
private static java.lang.String SIMPLE_TAG
          Indicates a simple value.
private static java.lang.String TYPE_CLOSE_TAG
          Last separator for the type.
private static java.lang.String TYPE_OPEN_TAG
          First separator for the type.
private static java.lang.String TYPE_SEPARATORS
          Separators for the type.
private static java.lang.String URL_TAG
          Separates the parts of the URL.
private static java.lang.String VALUE_TAG
          Separates the type from the values.
 
Fields inherited from class org.PingOO.DLAI.lib.util.MessageFormatter
ACCEPTED_NO_TAG, ACCEPTED_TAG, ACCEPTED_YES_TAG, COMMENT_TAG
 
Constructor Summary
MasterMessageFormatter()
          Creates a new message formatter.
 
Method Summary
private  void parseHashtable(ValueHashtable hashtable, java.lang.StringBuffer lastKey, java.lang.StringBuffer keyLine, java.lang.StringBuffer valueLine)
          Takes a ValueHashtable and make the two needed line for the PingOO protocol.
private  void parseHashToken(ValueHashtable hashtable, java.lang.String key, java.lang.String value)
          Correctly formats incoming (recursive) Hashtables.
 java.lang.String parseIn(MessageHashtable message, java.lang.String server, java.lang.String port)
          Formats the outgoing message so it can be sent and unstertood by the server.
 MessageHashtable parseOut(byte[] data, java.lang.String module, java.lang.String function)
          Formats an incoming message so it can be used and routed by the PingOO PPM.
private  java.lang.String readLine()
          Get a line from a byte buffer.
 
Methods inherited from class org.PingOO.DLAI.lib.util.MessageFormatter
parseIn, parseIn
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

OBJECT_SEPARATORS

private static final java.lang.String OBJECT_SEPARATORS
Separator for the objets lists. ":, "

TYPE_SEPARATORS

private static final java.lang.String TYPE_SEPARATORS
Separators for the type. "{} "

KEY_SEPARATORS

private static final java.lang.String KEY_SEPARATORS
Separator for the inner keys.

PROTOCOL_NAME_TAG

private static final java.lang.String PROTOCOL_NAME_TAG
Stores the name of the pingoo protocol.

REQUEST_ID_TAG

private static final java.lang.String REQUEST_ID_TAG
Indicates an id line.

SIMPLE_TAG

private static final java.lang.String SIMPLE_TAG
Indicates a simple value.

ARRAY_TAG

private static final java.lang.String ARRAY_TAG
Indicates a simple value.

HASH_KEY_TAG

private static final java.lang.String HASH_KEY_TAG
Indicates a list of hastable keys.

HASH_VALUE_TAG

private static final java.lang.String HASH_VALUE_TAG
Indicates a list of hashtable values.

FILE_TAG

private static final java.lang.String FILE_TAG
Indicates a file.

END_TAG

private static final java.lang.String END_TAG
Indicates the end of the parameters list in the PingOO protocol.

VALUE_TAG

private static final java.lang.String VALUE_TAG
Separates the type from the values.

PARAM_TAG

private static final java.lang.String PARAM_TAG
Separates the type from the values.

URL_TAG

private static final java.lang.String URL_TAG
Separates the parts of the URL.

PORT_TAG

private static final java.lang.String PORT_TAG
Separates the server's name from it's port.

KEY_TAG

private static final java.lang.String KEY_TAG
Separates the different the inner keys. "/"

PROTOCOL_TAG

private static final java.lang.String PROTOCOL_TAG
Separates the protocol descriptor from th rest of the URL. "://"

TYPE_OPEN_TAG

private static final java.lang.String TYPE_OPEN_TAG
First separator for the type.

TYPE_CLOSE_TAG

private static final java.lang.String TYPE_CLOSE_TAG
Last separator for the type.

LINE_TAG

private static final java.lang.String LINE_TAG
Terminates the line.

byteBuffer

private byte[] byteBuffer
Byte buffer, used when reading lines.
Constructor Detail

MasterMessageFormatter

public MasterMessageFormatter()
Creates a new message formatter.
Method Detail

parseIn

public final java.lang.String parseIn(MessageHashtable message,
                                      java.lang.String server,
                                      java.lang.String port)
                               throws java.lang.NullPointerException
Formats the outgoing message so it can be sent and unstertood by the server.
Parameters:
message - A MessageHashtable containing the keys and objects needed to be sent to the server.
server - The targeted server.
port - The targeted port.
Returns:
The result String line.
Throws:
java.lang.NullPointerException - If the message, the server or the port is null.
Overrides:
parseIn in class MessageFormatter

parseOut

public final MessageHashtable parseOut(byte[] data,
                                       java.lang.String module,
                                       java.lang.String function)
                                throws java.lang.NullPointerException,
                                       BadMessageException
Formats an incoming message so it can be used and routed by the PingOO PPM.
Parameters:
data - The byte array containing the message.
module - The name of the module wich requires this answer.
function - The name of the function wich requires this answer.
Returns:
A MessageHashtable containing all objects sent by the server associated with their key.
Throws:
java.lang.NullPointerException - If the datas are null.
BadMessageException - If the datas have a bad syntax, or when a problem is encountered during the parsing.
Overrides:
parseOut in class MessageFormatter

readLine

private final java.lang.String readLine()
                                 throws java.lang.NullPointerException
Get a line from a byte buffer.
A line has been red if a '\n', a '\r' or the end of the buffer has been encountered.
Parameters:
data - The buffer from which we want to get a line.
Returns:
One line from the buffer.
Throws:
java.lang.NullPointerException - If the buffer is null.

parseHashToken

private final void parseHashToken(ValueHashtable hashtable,
                                  java.lang.String key,
                                  java.lang.String value)
Correctly formats incoming (recursive) Hashtables.
Parameters:
hashtable -  
key -  
value -  

parseHashtable

private final void parseHashtable(ValueHashtable hashtable,
                                  java.lang.StringBuffer lastKey,
                                  java.lang.StringBuffer keyLine,
                                  java.lang.StringBuffer valueLine)
Takes a ValueHashtable and make the two needed line for the PingOO protocol.
Parameters:
hashtable -  
lastKey -  
keyLine -  
valueLine -