1 // Copyright 2009 Google Inc. All Rights Reserved.
3 package com
.google
.appengine
.api
.xmpp
;
5 import java
.util
.Arrays
;
8 * Class that represents an XMPP message. {@code Message} objects can
9 * be constructed (via {@link MessageBuilder} and sent as outgoing
10 * messages, or can be parsed as incoming messages by {@link
11 * XMPPService#parseMessage}.
14 public class Message
{
15 private final MessageType messageType
;
16 private final boolean asXml
;
17 private final String body
;
18 private final String stanza
;
19 private final JID fromJid
;
20 private final JID
[] recipientJids
;
23 * Constructor for an XMPP message.
25 * @param messageType Type of the message.
26 * @param asXml Whether the body should be interpreted as XML.
27 * @param body The body of the message.
28 * @param fromJid The JID to use as the sender.
29 * @param recipientJids Recipients of the message.
30 * @param stanza The full XMP message stanza, or {@code null} if not
33 Message(MessageType messageType
, boolean asXml
, String body
, String stanza
,
35 JID
... recipientJids
) {
36 this.messageType
= messageType
;
40 this.fromJid
= fromJid
;
41 this.recipientJids
= recipientJids
;
44 public MessageType
getMessageType() {
48 public boolean isXml() {
52 public String
getBody() {
56 public JID
getFromJid() {
60 public JID
[] getRecipientJids() {
65 * This returns the entire XML message stanza for incoming XMPP
66 * messages. For outgoing messages, this field will be ignored.
68 public String
getStanza() {
73 public String
toString() {
74 String formattedStanza
;
76 formattedStanza
= "null";
78 formattedStanza
= "\"" + stanza
.replace("\"", "\\\"") + "\"";
83 formattedBody
= "null";
85 formattedBody
= "\"" + body
.replace("\"", "\\\"") + "\"";
89 "Message(messageType=%s, asXml=%b, body=%s, stanza=%s, " +
90 "fromJid=%s, recipientJids=%s)",
91 messageType
, asXml
, formattedBody
, formattedStanza
, fromJid
,
92 Arrays
.toString(recipientJids
));