public class IQ extends Stanza
The implementation of the <iq/>
stanza.
This class is thread-safe.Info/Query, or IQ, is a “request-response” mechanism, similar in some ways to the Hypertext Transfer Protocol [HTTP]. The semantics of IQ enable an entity to make a request of, and receive a response from, another entity. The data content of the request and response is defined by the schema or other structural definition associated with the XML namespace that qualifies the direct child element of the IQ element (see Section 8.4), and the interaction is tracked by the requesting entity through use of the ‘id’ attribute. Thus, IQ interactions follow a common pattern of structured data exchange such as get/result or set/result (although an error can be returned in reply to a request if appropriate)
To enforce these semantics, the following rules apply:
- The ‘id’ attribute is REQUIRED for IQ stanzas.
- The ‘type’ attribute is REQUIRED for IQ stanzas. The value MUST be one of the following; if not, the recipient or an intermediate router MUST return a
<bad-request/>
stanza error (Section 8.3.3.1).
- get – The stanza requests information, inquires about what data is needed in order to complete further operations, etc.
- set – The stanza provides data that is needed for an operation to be completed, sets new values, replaces existing values, etc.
- result – The stanza is a response to a successful get or set request.
- error – The stanza reports an error that has occurred regarding processing or delivery of a get or set request (see Section 8.3).
- An entity that receives an IQ request of type “get” or “set” MUST reply with an IQ response of type “result” or “error”. The response MUST preserve the ‘id’ attribute of the request (or be empty if the generated stanza did not include an ‘id’ attribute).
- An entity that receives a stanza of type “result” or “error” MUST NOT respond to the stanza by sending a further IQ response of type “result” or “error”; however, the requesting entity MAY send another request (e.g., an IQ of type “set” to provide obligatory information discovered through a get/result pair).
- An IQ stanza of type “get” or “set” MUST contain exactly one child element, which specifies the semantics of the particular request.
- An IQ stanza of type “result” MUST include zero or one child elements.
- An IQ stanza of type “error” MAY include the child element contained in the associated “get” or “set” and MUST include an
<error/>
child.
Modifier and Type | Class and Description |
---|---|
static class |
IQ.Type
Represents a
<iq/> ‘type’ attribute. |
Constructor and Description |
---|
IQ(IQ.Type type,
java.lang.Object extension)
Creates an IQ stanza with the given type and extension.
|
IQ(IQ.Type type,
java.lang.Object extension,
java.lang.String id)
Creates an IQ stanza with the given id, type and extension.
|
IQ(Jid to,
IQ.Type type,
java.lang.Object extension)
Creates an IQ stanza with the given receiver, type and extension.
|
IQ(Jid to,
IQ.Type type,
java.lang.Object extension,
java.lang.String id)
Creates an IQ stanza with the given receiver, id, type and extension.
|
IQ(Jid to,
IQ.Type type,
java.lang.Object extension,
java.lang.String id,
Jid from,
java.util.Locale language,
StanzaError error)
Creates an IQ stanza with the given receiver, id, type, extension and error.
|
Modifier and Type | Method and Description |
---|---|
IQ |
createError(Condition condition)
Creates an error response for this stanza.
|
IQ |
createError(StanzaError error)
Creates an error response for this stanza.
|
IQ |
createResult()
Creates a result IQ stanza, i.e. it uses the same id as this IQ, sets the type to ‘result’ and switches the ‘to’ and ‘from’ attribute.
|
IQ |
createResult(java.lang.Object extension)
Creates a result IQ stanza with a payload, i.e. it uses the same id as this IQ, sets the type to ‘result’ and switches the ‘to’ and ‘from’ attribute.
|
static IQ |
get(Jid to,
java.lang.Object extension)
Creates an IQ of type ‘get’ with a random id.
|
static IQ |
get(java.lang.Object extension)
Creates an IQ of type ‘get’ with a random id.
|
IQ.Type |
getType()
Gets the type.
|
boolean |
isRequest()
Returns if this is a request IQ, i.e. of type get or set.
|
boolean |
isResponse()
Returns true, if this IQ is a response (either a positive result or an error).
|
static IQ |
set(Jid to,
java.lang.Object extension)
Creates an IQ of type ‘set’ with a random id.
|
static IQ |
set(java.lang.Object extension)
Creates an IQ of type ‘set’ with a random id.
|
void |
setType(IQ.Type type)
Sets the type.
|
java.lang.String |
toString() |
getError, getExtension, getFrom, getId, getLanguage, getTo, hasExtension, isToItselfOrServer, setError, setFrom, setId, setLanguage, setTo
public IQ(IQ.Type type, java.lang.Object extension)
Creates an IQ stanza with the given type and extension. The id attribute will be generated randomly.
type
- The type.extension
- The extension.public IQ(IQ.Type type, java.lang.Object extension, java.lang.String id)
Creates an IQ stanza with the given id, type and extension.
type
- The type.extension
- The extension.id
- The id.public IQ(Jid to, IQ.Type type, java.lang.Object extension)
Creates an IQ stanza with the given receiver, type and extension. The id attribute will be generated randomly.
to
- The receiver.type
- The type.extension
- The extension.public IQ(Jid to, IQ.Type type, java.lang.Object extension, java.lang.String id)
Creates an IQ stanza with the given receiver, id, type and extension.
to
- The receiver.type
- The type.extension
- The extension.id
- The id.public IQ(Jid to, IQ.Type type, java.lang.Object extension, java.lang.String id, Jid from, java.util.Locale language, StanzaError error)
Creates an IQ stanza with the given receiver, id, type, extension and error.
to
- The receiver.type
- The type.extension
- The extension.id
- The id.from
- The sender.language
- The language.error
- The error.public static IQ get(Jid to, java.lang.Object extension)
Creates an IQ of type ‘get’ with a random id.
to
- The ‘to’ attribute.extension
- The extension.public static IQ set(Jid to, java.lang.Object extension)
Creates an IQ of type ‘set’ with a random id.
to
- The ‘to’ attribute.extension
- The extension.public static IQ get(java.lang.Object extension)
Creates an IQ of type ‘get’ with a random id.
extension
- The extension.public static IQ set(java.lang.Object extension)
Creates an IQ of type ‘set’ with a random id.
extension
- The extension.public final IQ.Type getType()
Gets the type.
public final void setType(IQ.Type type)
Sets the type.
type
- The type.public final boolean isRequest()
Returns if this is a request IQ, i.e. of type get or set.
public final boolean isResponse()
Returns true, if this IQ is a response (either a positive result or an error).
public IQ createResult()
Creates a result IQ stanza, i.e. it uses the same id as this IQ, sets the type to ‘result’ and switches the ‘to’ and ‘from’ attribute.
public final IQ createResult(java.lang.Object extension)
Creates a result IQ stanza with a payload, i.e. it uses the same id as this IQ, sets the type to ‘result’ and switches the ‘to’ and ‘from’ attribute.
extension
- The extension.public final IQ createError(StanzaError error)
Stanza
Creates an error response for this stanza.
createError
in class Stanza
error
- The error which is appended to the stanza.Stanza.getError()
public final IQ createError(Condition condition)
Stanza
Creates an error response for this stanza.
createError
in class Stanza
condition
- The error condition which is appended to the stanza.Stanza.getError()
Copyright © 2014–2019 XMPP.rocks. All rights reserved.