Class WfBasicMessage

java.lang.Object
org.whiteflagprotocol.java.core.WfBasicMessage

public class WfBasicMessage extends Object
Whiteflag basic message class

This is a class defining a generic basic Whiteflag message. It includes common properties and methods of all message types, and implementation independent logic specified by the Whiteflag standard. A message is composed of two WfMessageSegments: a message header and a message body.

Since:
1.0
Whiteflag standard x-reference:
4. Message Format
  • Field Details

    • type

      public final WfMessageType type
      The type of the message
      Whiteflag standard x-reference:
      2.4.2 Message Functionality
    • body

      public final WfMessageSegment body
      The message body
      Whiteflag standard x-reference:
      4.3 Message Body
  • Constructor Details

    • WfBasicMessage

      protected WfBasicMessage(WfMessageType type, WfMessageSegment header, WfMessageSegment body)
      Creates a basic Whiteflag message from a header and a body
      Parameters:
      type - the message type
      header - the message header
      body - the message body
    • WfBasicMessage

      protected WfBasicMessage(WfBasicMessage message)
      Creates a basic Whiteflag message from an existing basic message
      Parameters:
      message - the basic message
      Since:
      1.1
  • Method Details

    • toString

      public String toString()
      Returns the message as a concatinated string of field values
      Overrides:
      toString in class Object
      Returns:
      the serialized message
    • isValid

      public boolean isValid()
      Checks if this message contains valid data
      Returns:
      TRUE if all message fields contain valid data, else FALSE
    • isValid

      public final boolean isValid(String fieldname)
      Checks if the specified message field contains valid data
      Parameters:
      fieldname - the name of the field
      Returns:
      TRUE if the field contains valid data, else FALSE
    • isValid

      public final boolean isValid(String fieldname, String data)
      Checks if the provided data is valid for the specified message field
      Parameters:
      fieldname - the name of the field
      data - the value to be checked
      Returns:
      TRUE if the field contains valid data, else FALSE
    • getNoFields

      public final int getNoFields()
      Gets the number of fields in this message
      Returns:
      the number of message fields
    • getFieldNames

      public Set<String> getFieldNames()
      Gets the field names of this message
      Returns:
      a string set with all field names
    • get

      public String get(String fieldname)
      Gets the value of the specified field
      Parameters:
      fieldname - the name of the requested field
      Returns:
      the field value, or NULL if field does not exist
    • set

      public boolean set(String fieldname, String data)
      Sets the value of the specified field
      Parameters:
      fieldname - the name of the field
      data - data to be set as the field value
      Returns:
      TRUE if field value is set, FALSE if field does not exits, isalready set, or data is invalid
    • serialize

      public String serialize() throws WfCoreException
      Serializes the Whiteflag message
      Returns:
      the serialized message, i.e. the concatinated string of field values
      Throws:
      WfCoreException - if any of the fields does not contain valid data
    • encode

      public WfBinaryBuffer encode() throws WfCoreException
      Encodes the Whiteflag message
      Returns:
      a buffer with the binary encoded Whiteflag message
      Throws:
      WfCoreException - if any of the fields does not contain valid data