public abstract class Stanza extends Object implements StreamElement
After a client and a server (or two servers) have completed stream negotiation, either party can send XML stanzas. Three kinds of XML stanza are defined for the 'jabber:client' and 'jabber:server' namespaces:
<message/>,<presence/>, and<iq/>.
| Modifier and Type | Method and Description |
|---|---|
abstract Stanza |
createError(Condition condition)
Creates an error response for this stanza.
|
abstract Stanza |
createError(StanzaError error)
Creates an error response for this stanza.
|
StanzaError |
getError()
Gets the stanza's 'error' element.
|
<T> T |
getExtension(Class<T> clazz)
Gets the extension of the given type or null, if there's no such extension.
|
Jid |
getFrom()
Gets the stanza's 'from' attribute.
|
String |
getId()
Gets the stanza's 'id' attribute.
|
String |
getLanguage()
Gets the stanza's 'xml:lang' attribute, i.e. its language.
|
Jid |
getTo()
Gets the stanza's 'to' attribute, i.e. the recipient.
|
boolean |
hasExtension(Class<?> clazz)
Checks if the stanza has an extension of the given type.
|
void |
setError(StanzaError stanzaError)
Sets the stanza's 'error' element.
|
void |
setFrom(Jid from)
Sets the stanza's 'from' attribute, i.e. the sender.
|
void |
setId(String id)
Sets the stanza's 'id' attribute.
|
void |
setLanguage(String language)
Sets the stanza's 'xml:lang' attribute, i.e. its language.
|
void |
setTo(Jid to)
Sets the stanza's 'to' attribute, i.e. the recipient.
|
String |
toString() |
public final Jid getFrom()
The 'from' attribute specifies the JID of the sender.
public final void setFrom(Jid from)
from - The sender.()public final String getId()
The 'id' attribute is used by the originating entity to track any response or error stanza that it might receive in relation to the generated stanza from another entity (such as an intermediate server or the intended recipient).
It is up to the originating entity whether the value of the 'id' attribute is unique only within its current stream or unique globally.
For
<message/>and<presence/>stanzas, it is RECOMMENDED for the originating entity to include an 'id' attribute; for<iq/>stanzas, it is REQUIRED.If the generated stanza includes an 'id' attribute then it is REQUIRED for the response or error stanza to also include an 'id' attribute, where the value of the 'id' attribute MUST match that of the generated stanza.
public final void setId(String id)
id - The id.getId()public final Jid getTo()
The 'to' attribute specifies the JID of the intended recipient for the stanza.
public final void setTo(Jid to)
to - The recipient.getTo()public final String getLanguage()
A stanza SHOULD possess an 'xml:lang' attribute (as defined in Section 2.12 of [XML]) if the stanza contains XML character data that is intended to be presented to a human user (as explained in [CHARSETS], "internationalization is for humans"). The value of the 'xml:lang' attribute specifies the default language of any such human-readable XML character data.
public final void setLanguage(String language)
language - The language.getLanguage()public final <T> T getExtension(Class<T> clazz)
T - The extension type.clazz - The extension class.public final boolean hasExtension(Class<?> clazz)
clazz - The extension class.public final StanzaError getError()
Stanza-related errors are handled in a manner similar to stream errors. Unlike stream errors, stanza errors are recoverable; therefore, they do not result in termination of the XML stream and underlying TCP connection. Instead, the entity that discovers the error condition returns an error stanza, which is a stanza that:
- is of the same kind (message, presence, or IQ) as the generated stanza that triggered the error
- has a 'type' attribute set to a value of "error"
- typically swaps the 'from' and 'to' addresses of the generated stanza
- mirrors the 'id' attribute (if any) of the generated stanza that triggered the error
- contains an
<error/>child element that specifies the error condition and therefore provides a hint regarding actions that the sender might be able to take in an effort to remedy the error (however, it is not always possible to remedy the error)
public final void setError(StanzaError stanzaError)
stanzaError - The stanza error.getError()public abstract Stanza createError(StanzaError error)
error - The error which is appended to the stanza.getError()public abstract Stanza createError(Condition condition)
condition - The error condition which is appended to the stanza.getError()Copyright © 2014–2015 XMPP.rocks. All rights reserved.