public abstract class Stanza extends Object
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 | Field and Description |
|---|---|
protected Jid |
from |
protected String |
id |
protected String |
language |
protected Jid |
to |
| Constructor and Description |
|---|
Stanza() |
| Modifier and Type | Method and Description |
|---|---|
abstract Stanza |
createError(StanzaError error)
Creates an error response for this stanza.
|
protected void |
createError(Stanza stanza,
StanzaError error)
Swaps the 'from' and 'to' addresses from the generated stanza and adds a 'by' attribute to the error.
|
StanzaError |
getError()
Gets the stanza's 'error' element.
|
abstract <T> T |
getExtension(Class<T> type)
Gets an extension by type.
|
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.
|
Jid |
getTo()
Gets the stanza's 'to' attribute.
|
void |
setError(StanzaError stanzaError)
Sets the stanza's 'error' element.
|
void |
setFrom(Jid from)
Sets the stanza's 'from' attribute.
|
void |
setId(String id)
Sets the stanza's 'id' attribute.
|
void |
setLanguage(String language)
Sets the stanza's 'xml:lang' attribute.
|
void |
setTo(Jid to)
Sets the stanza's 'to' attribute.
|
String |
toString() |
protected Jid from
protected String id
protected Jid to
protected String language
public final Jid getTo()
The 'to' attribute specifies the JID of the intended recipient for the stanza.
setTo(rocks.xmpp.core.Jid)public final void setTo(Jid to)
to - The JID.getTo()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.
setId(String)public final void setId(String id)
id - The id.getId()public final Jid getFrom()
The 'from' attribute specifies the JID of the sender.
setFrom(rocks.xmpp.core.Jid)public final void setFrom(Jid from)
from - The JID.getFrom()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.
setLanguage(String)public final void setLanguage(String language)
language - The language.getLanguage()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)
setError(StanzaError)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(),
createError(Stanza, StanzaError)protected final void createError(Stanza stanza, StanzaError error)
stanza - The stanza to create the error for.error - The error.createError(StanzaError)public abstract <T> T getExtension(Class<T> type)
T - The type.type - The class.Copyright © 2014 XMPP.rocks. All rights reserved.