proper.remote.messages
Class Message

java.lang.Object
  extended by proper.core.ProperObject
      extended by proper.remote.messages.Message
All Implemented Interfaces:
ProperInterface
Direct Known Subclasses:
DataMessage, JobMessage

public class Message
extends ProperObject

This class encapsulates the standard behaviour and methods for all messages. A message looks like this:

 <?xml version="1.0" encoding="UTF-8"?>
 
 <message>
    <head>
       <from>
          <ip>some ip</ip>
          <port>some port</port>
       </from>
       <type>type of the message</type>
    </head>
    <body>
       the actual data of the message...
    </body>
 </message>
 

Version:
$Revision: 1.2 $
Author:
FracPete

Field Summary
static java.lang.String BODY
          the body node (the actual payload)
static java.lang.String FROM
          the from node in the header
static java.lang.String HEADER
          the header node
static java.lang.String IP
          the ip node in the from node
static java.lang.String MESSAGE
          the xml root node
static java.lang.String PORT
          the port node in the from node
static java.lang.String TYPE
          the type of the message node in the header
 
Fields inherited from interface proper.core.ProperInterface
VERSION
 
Constructor Summary
Message()
          initializes the object
Message(int port)
          initializes the object with the given Port, IP/Hostname is determined automatically
Message(Message msg)
          initializes the object with the given Message
Message(java.io.Reader reader)
          initializes the object with the given xml data
Message(java.lang.String ip, int port)
          initializes the object with the given IP and Port
 
Method Summary
 void clear()
          creates an empty message with header and body, derived classes only need to override clearBody()
 void clearBody()
          sets the body back to standard
 Element getBody()
          returns the body element
 java.lang.String getBodyContent()
          returns the content of the body element, can be NULL
 java.lang.String getContent(Element node)
          returns the content of the specified node, can be NULL (e.g.
 java.lang.String getContent(Element node, boolean returnEmptyIfNull)
          returns the content of the specified node, can be NULL (e.g.
 java.util.Vector getContent(Element node, java.lang.String path)
          returns all the contents of nodes found according to the path from starting from the given node
 java.util.Vector getContent(Element node, java.lang.String path, boolean returnEmptyIfNull)
          returns all the contents of nodes found according to the path from starting from the given node
 java.util.Vector getContent(java.lang.String path)
          returns all the contents of nodes found according to the path from starting from the root node
 Element getHeader()
          returns the header element
 java.lang.String getIP()
          returns the content of the IP node
 int getPort()
          returns the content of the PORT node, -1 if not successful
 java.lang.String getType()
          returns the type of the message
static void main(java.lang.String[] args)
          for testing only
 void setBodyContent(java.lang.String content)
          sets the content of the body element, can be NULL
 void setContent(Element node, java.lang.Object content)
          sets the content of the specified node, but only if the node is not NULL
 void setIP(java.lang.String ip)
          sets the IP
 void setPort(int port)
          sets the port
 void setType(java.lang.String type)
          sets the type of the message
 java.lang.String toString()
          the message in string representation, i.e.
 
Methods inherited from class proper.core.ProperObject
addListener, addOutput, classInVerbose, debugprint, debugprint, debugprint, debugprint, debugprintln, debugprintln, debugprintln, debugprintln, debugprintln, getListeners, getRuntime, getVerbose, getVerboseLevel, getVerboseLevelForClass, getVerboseString, getVerboseStringForClass, notifyListener, notifyListeners, print, print, print, print, println, println, println, println, println, printMemory, removeListener, setOutput, setVerbose, setVerboseLevel, setVerboseString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MESSAGE

public static final java.lang.String MESSAGE
the xml root node

See Also:
Constant Field Values

HEADER

public static final java.lang.String HEADER
the header node

See Also:
Constant Field Values

FROM

public static final java.lang.String FROM
the from node in the header

See Also:
Constant Field Values

IP

public static final java.lang.String IP
the ip node in the from node

See Also:
Constant Field Values

PORT

public static final java.lang.String PORT
the port node in the from node

See Also:
Constant Field Values

TYPE

public static final java.lang.String TYPE
the type of the message node in the header

See Also:
Constant Field Values

BODY

public static final java.lang.String BODY
the body node (the actual payload)

See Also:
Constant Field Values
Constructor Detail

Message

public Message()
initializes the object


Message

public Message(java.io.Reader reader)
initializes the object with the given xml data


Message

public Message(Message msg)
initializes the object with the given Message


Message

public Message(int port)
initializes the object with the given Port, IP/Hostname is determined automatically


Message

public Message(java.lang.String ip,
               int port)
initializes the object with the given IP and Port

Method Detail

getHeader

public Element getHeader()
returns the header element


getBody

public Element getBody()
returns the body element


getBodyContent

public java.lang.String getBodyContent()
returns the content of the body element, can be NULL


setBodyContent

public void setBodyContent(java.lang.String content)
sets the content of the body element, can be NULL


getContent

public java.lang.String getContent(Element node)
returns the content of the specified node, can be NULL (e.g. if node is also NULL)


getContent

public java.lang.String getContent(Element node,
                                   boolean returnEmptyIfNull)
returns the content of the specified node, can be NULL (e.g. if node is also NULL)

Parameters:
node - the node to return it's content from
returnEmptyIfNull - if this is TRUE we return an empty String instead of null

setContent

public void setContent(Element node,
                       java.lang.Object content)
sets the content of the specified node, but only if the node is not NULL


getContent

public java.util.Vector getContent(java.lang.String path)
returns all the contents of nodes found according to the path from starting from the root node

Parameters:
path - the search path
Returns:
the content of all found nodes

getContent

public java.util.Vector getContent(Element node,
                                   java.lang.String path)
returns all the contents of nodes found according to the path from starting from the given node

Parameters:
node - the node to start the search from
path - the search path
Returns:
the content of all found nodes

getContent

public java.util.Vector getContent(Element node,
                                   java.lang.String path,
                                   boolean returnEmptyIfNull)
returns all the contents of nodes found according to the path from starting from the given node

Parameters:
node - the node to start the search from
path - the search path
returnEmptyIfNull - returns an empty string instead of null in the result vector
Returns:
the content of all found nodes

clear

public void clear()
creates an empty message with header and body, derived classes only need to override clearBody()

See Also:
MESSAGE, HEADER, BODY, clearBody()

clearBody

public void clearBody()
sets the body back to standard


getIP

public java.lang.String getIP()
returns the content of the IP node


setIP

public void setIP(java.lang.String ip)
sets the IP


getPort

public int getPort()
returns the content of the PORT node, -1 if not successful


setPort

public void setPort(int port)
sets the port


getType

public java.lang.String getType()
returns the type of the message


setType

public void setType(java.lang.String type)
sets the type of the message


toString

public java.lang.String toString()
the message in string representation, i.e. the XML document

Overrides:
toString in class ProperObject

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
for testing only

Throws:
java.lang.Exception