com.echomine.jabber
Class AbstractJabberMessage

java.lang.Object
  extended by com.echomine.jabber.JabberMessage
      extended by com.echomine.jabber.JabberJDOMMessage
          extended by com.echomine.jabber.AbstractJabberMessage
All Implemented Interfaces:
JabberMessageParsable
Direct Known Subclasses:
JabberChatMessage, JabberIQMessage, JabberPresenceMessage

public abstract class AbstractJabberMessage
extends JabberJDOMMessage

This message adds some base functionality for those that uses it. It adds parsing of error messages, parsing of to, from, and type. The default for the message is not to look for reply and not sent synchronously.


Field Summary
static java.lang.String TYPE_ERROR
           
 
Fields inherited from class com.echomine.jabber.JabberMessage
messageID
 
Constructor Summary
protected AbstractJabberMessage()
           
  AbstractJabberMessage(java.lang.String type, Element root)
          this constructor is for creating outgoing messages.
 
Method Summary
 ErrorMessage getErrorMessage()
          retrieves the error message if this message is an error type.
 JID getFrom()
           
 JID getTo()
           
 java.lang.String getType()
           
 boolean isError()
          check to see if this is an error message.
 JabberMessage parse(JabberMessageParser parser, Element msgTree)
          parses the message.
 void setErrorMessage(ErrorMessage msg)
          sets the error message.
 void setFrom(JID from)
          sets the originator of the message.
 void setTo(JID to)
          sets the recipient of the message
 void setType(java.lang.String type)
          sets the type for the message.
 
Methods inherited from class com.echomine.jabber.JabberJDOMMessage
encode, getDOM, getMessageType, getXMLOutputter, setMessageID, toString
 
Methods inherited from class com.echomine.jabber.JabberMessage
getMessageID, getReplyMessage, getTimeout, getXMessage, getXMessages, interrupt, isReplyRequired, isSendXMessages, isSynchronized, replyReceived, setReplyRequired, setSendXMessages, setSynchronized, setTimeout, setXMessage, setXMessages
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_ERROR

public static final java.lang.String TYPE_ERROR
See Also:
Constant Field Values
Constructor Detail

AbstractJabberMessage

public AbstractJabberMessage(java.lang.String type,
                             Element root)
this constructor is for creating outgoing messages. It is here to be used by subclasses. The constructor simply creates a default element tree with the root element as the top top level tag, and then sets the message to use that tree.


AbstractJabberMessage

protected AbstractJabberMessage()
Method Detail

parse

public JabberMessage parse(JabberMessageParser parser,
                           Element msgTree)
                    throws ParseException
parses the message. The parser is really not used

Specified by:
parse in interface JabberMessageParsable
Overrides:
parse in class JabberJDOMMessage
Throws:
ParseException

getType

public java.lang.String getType()
Returns:
the type of the message (ie. error, get, etc)

setType

public void setType(java.lang.String type)
sets the type for the message. If the type is null, type will be not be


getTo

public JID getTo()
Returns:
the JID of the recipient

setTo

public void setTo(JID to)
sets the recipient of the message


getFrom

public JID getFrom()
Returns:
the from attribute of the message

setFrom

public void setFrom(JID from)
sets the originator of the message. Normally, this is used to set the incoming message. Outgoing messages will normally not use this because the server will automatically append this field for you.

Parameters:
from - the originator of the message

isError

public boolean isError()
check to see if this is an error message. There is a special way this method works (for pure convenience sake). It will first check to see if the message itself is an error message. If it is, it will return itself as the error. If it is not an error, then it will check to see if its reply message is an error message (if a reply exists). If it is, it will use its reply message as the error message.

Returns:
true if either the message itself or its reply message is an error message

getErrorMessage

public ErrorMessage getErrorMessage()
retrieves the error message if this message is an error type. The error message is dynamically processed. If the message itself is an error, it will return itself as the error message. Otherwise, it will check if its reply message (if a reply exists) is an error message, and if so, use the reply message as the error message. This is purely for convenience sake.

Returns:
the error message either from itself or from its reply message, null if no error message

setErrorMessage

public void setErrorMessage(ErrorMessage msg)
sets the error message. The message type will automatically be changed to TYPE_ERROR. You can still include any other data along with the error message, but the error message will be returned and the type is now TYPE_ERROR.

Parameters:
msg - the error message associated with this message


Copyright © 2001-2005 Echomine. All Rights Reserved.