com.echomine.jabber
Class JabberJDOMMessage

java.lang.Object
  extended by com.echomine.jabber.JabberMessage
      extended by com.echomine.jabber.JabberJDOMMessage
All Implemented Interfaces:
JabberMessageParsable
Direct Known Subclasses:
AbstractJabberMessage, DataXMessage, DelayXMessage, EventXMessage, ExpireXMessage, OOBXMessage, PGPEncryptedXMessage, PGPSignedXMessage, RosterXMessage

public class JabberJDOMMessage
extends JabberMessage
implements JabberMessageParsable

The default message type that essentially contains all the data in a JDOM tree. Subclasses can actually extend from this class to parse the tree and store the data in more easily access form. They can also provide getXXX methods to retrieve the data. JDOM is provided as part of the distribution.

If you do not want to create a new message class that extends from this class, you can retrieve the internal JDOM tree and then manipulate it manually. It is suggested that you create a new message class to handle and process the information so you can reuse it in the future. Then you can also contribute the message class back to the project. :)

By default, JDOM Messages adds the X Namespaces. Thus, they are automatically inserted into the DOM tree and sent along with the message. If you do not want the X Messages to be sent, you can use the setSendXMessage() method to disable it.


Field Summary
 
Fields inherited from class com.echomine.jabber.JabberMessage
messageID
 
Constructor Summary
protected JabberJDOMMessage()
           
  JabberJDOMMessage(Element rootElem)
          normally used internally or creating outgoing messages.
 
Method Summary
 java.lang.String encode()
          The default encoding will serialize the DOM Tree.
 Element getDOM()
          retrieves the DOM tree related to the message..
 int getMessageType()
          the default message type is unknown.
protected  XMLOutputter getXMLOutputter()
          retrieves the XML Outputter associated with every jabber jdom message.
 JabberMessage parse(JabberMessageParser parser, Element msgTree)
          parse element/incoming message into a message object.
 void setMessageID(java.lang.String messageID)
          sets the message id.
 java.lang.String 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
 

Constructor Detail

JabberJDOMMessage

protected JabberJDOMMessage()

JabberJDOMMessage

public JabberJDOMMessage(Element rootElem)
normally used internally or creating outgoing messages.

Method Detail

parse

public JabberMessage parse(JabberMessageParser parser,
                           Element msgTree)
                    throws ParseException
Description copied from interface: JabberMessageParsable
parse element/incoming message into a message object. Note that the parsing is unique in that during normal behavior, you will return "this" at the end of the method. However, for those message that require "morphing" into another message type (ie. IQ Messages), the method can return a new instance of another JabberMessage to replace the current one.

Specified by:
parse in interface JabberMessageParsable
Throws:
ParseException

setMessageID

public void setMessageID(java.lang.String messageID)
sets the message id. This is not used by outsiders to set the message id since ID's are automatically generated. Basically, all outgoing message have automatic IDs generated, but incoming message IDs are sent by the remote server. However, sometimes you may need to manipulate the id yourself, though it's normally not the case.

Overrides:
setMessageID in class JabberMessage

getDOM

public Element getDOM()
retrieves the DOM tree related to the message.. NOTE: this method is highly unstable. Child classes may not synchronize data with the DOM tree unless it's during the parsing of the incoming message or the encoding of an outgoing message (basically, when parse() and encode() are run). Otherwise, within any given time between those two methods are run, the DOM may be out of sync with the current data stored in the object. It is thus advisable that you do NOT retrieve the DOM unless you know what you're doing. In fact, if you want to retrieve certain information and you require accessing the internal DOM structure, subclass the message object and override the parse() and encode() to retrieve the data you want. Another alternative is to call encode() every time you need to access the DOM. This will ensure that the data inside the DOM is updated (but at the price of performance since you have to go through one encode to get data sync'ed). The best way is not to touch this method at all. :)


encode

public java.lang.String encode()
                        throws ParseException
The default encoding will serialize the DOM Tree. If there are X Messages, it will also get included one level below the main "root" element. By one level below, it means that the X Messages will be put as children of the DOM Tree's main element. If this is not a desired behavior, you will need to override and encode your own message.

Specified by:
encode in class JabberMessage
Throws:
ParseException - if something went wrong during encoding

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getXMLOutputter

protected XMLOutputter getXMLOutputter()
retrieves the XML Outputter associated with every jabber jdom message. it does lazy loading for memory conservation.


getMessageType

public int getMessageType()
the default message type is unknown. It doesn't mean that there is no type. It just means that there is no known message parser for this particular object.

Specified by:
getMessageType in class JabberMessage
Returns:
a message code that is unique to the message
See Also:
JabberCode


Copyright © 2001-2005 Echomine. All Rights Reserved.