Class Stanza
- java.lang.Object
-
- rocks.xmpp.core.stanza.model.Stanza
-
- All Implemented Interfaces:
LanguageElement
,StreamElement
- Direct Known Subclasses:
ExtensibleStanza
,IQ
public abstract class Stanza extends Object implements LanguageElement, StreamElement
The abstract base class for a XML stanza.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/>
.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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.Locale
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.static boolean
isToItselfOrServer(Stanza stanza, CharSequence domain, Jid connectedResource)
Checks if a stanza is addressed either to itself or to the server.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(Locale 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()
-
-
-
Method Detail
-
getFrom
public final Jid getFrom()
Gets the stanza's 'from' attribute.The 'from' attribute specifies the JID of the sender.
- Returns:
- The JID.
-
setFrom
public final void setFrom(Jid from)
Sets the stanza's 'from' attribute, i.e. the sender.- Parameters:
from
- The sender.- See Also:
()
-
getId
public final String getId()
Gets the stanza's 'id' attribute.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.
- Returns:
- The id.
-
setId
public final void setId(String id)
Sets the stanza's 'id' attribute.- Parameters:
id
- The id.- See Also:
getId()
-
getTo
public final Jid getTo()
Gets the stanza's 'to' attribute, i.e. the recipient.The 'to' attribute specifies the JID of the intended recipient for the stanza.
- Returns:
- The recipient.
-
setTo
public final void setTo(Jid to)
Sets the stanza's 'to' attribute, i.e. the recipient.- Parameters:
to
- The recipient.- See Also:
getTo()
-
getLanguage
public final Locale getLanguage()
Gets the stanza's 'xml:lang' attribute, i.e. its language.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.
- Specified by:
getLanguage
in interfaceLanguageElement
- Returns:
- The language.
-
setLanguage
public final void setLanguage(Locale language)
Sets the stanza's 'xml:lang' attribute, i.e. its language.- Parameters:
language
- The language.- See Also:
getLanguage()
-
getExtension
public final <T> T getExtension(Class<T> clazz)
Gets the extension of the given type or null, if there's no such extension.- Type Parameters:
T
- The extension type.- Parameters:
clazz
- The extension class.- Returns:
- The extension.
-
hasExtension
public final boolean hasExtension(Class<?> clazz)
Checks if the stanza has an extension of the given type.- Parameters:
clazz
- The extension class.- Returns:
- If the extension could be removed.
-
getError
public final StanzaError getError()
Gets the stanza's 'error' element.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)
- Returns:
- The stanza error.
-
setError
public final void setError(StanzaError stanzaError)
Sets the stanza's 'error' element.- Parameters:
stanzaError
- The stanza error.- See Also:
getError()
-
createError
public abstract Stanza createError(StanzaError error)
Creates an error response for this stanza.- Parameters:
error
- The error which is appended to the stanza.- Returns:
- The error response.
- See Also:
getError()
-
createError
public abstract Stanza createError(Condition condition)
Creates an error response for this stanza.- Parameters:
condition
- The error condition which is appended to the stanza.- Returns:
- The error response.
- See Also:
getError()
-
isToItselfOrServer
public static boolean isToItselfOrServer(Stanza stanza, CharSequence domain, Jid connectedResource)
Checks if a stanza is addressed either to itself or to the server. This is useful to check, if it's allowed to send a stanza before stream negotiation has completed.4.3.5. Completion of Stream Negotiation
The initiating entity MUST NOT attempt to send XML stanzas to entities other than itself (i.e., the client's connected resource or any other authenticated resource of the client's account) or the server to which it is connected until stream negotiation has been completed.- Parameters:
stanza
- The stanza.domain
- The domain.connectedResource
- The connected resource.- Returns:
- True, if the stanza is addressed to itself or to the server.
-
-