Package org.jivesoftware.smack.packet
Class IQ
- java.lang.Object
-
- org.jivesoftware.smack.packet.Stanza
-
- org.jivesoftware.smack.packet.IQ
-
- All Implemented Interfaces:
Element
,FullyQualifiedElement
,IqView
,NamedElement
,StanzaView
,TopLevelStreamElement
,XmlLangElement
- Direct Known Subclasses:
AbstractHttpOverXmpp
,AdHocCommandData
,AgentChatHistory
,AgentInfo
,AgentStatusRequest
,AgentWorkgroups
,Bind
,BlockContactsIQ
,BlockListIQ
,BoBIQ
,Bytestream
,ChatMetadata
,ChatNotes
,ChatSettings
,Close
,Data
,DepartQueuePacket
,DisablePushNotificationsIQ
,DiscoverInfo
,DiscoverItems
,DnsIq
,EmptyResultIQ
,EnablePushNotificationsIQ
,GenericSettings
,IoTClaimed
,IoTDataReadOutAccepted
,IoTDataRequest
,IoTDisown
,IoTDisowned
,IoTIsFriend
,IoTIsFriendResponse
,IoTMine
,IoTRegister
,IoTRemove
,IoTRemoved
,IoTSetRequest
,IoTSetResponse
,IoTUnregister
,JidPrepIq
,Jingle
,Jingle
,LastActivity
,Macros
,MamFinIQ
,MamPrefsIQ
,MamQueryIQ
,MonitorPacket
,MUCAdmin
,MUCLightAffiliationsIQ
,MUCLightBlockingIQ
,MUCLightChangeAffiliationsIQ
,MUCLightConfigurationIQ
,MUCLightCreateIQ
,MUCLightDestroyIQ
,MUCLightGetAffiliationsIQ
,MUCLightGetConfigsIQ
,MUCLightGetInfoIQ
,MUCLightInfoIQ
,MUCLightSetConfigsIQ
,MUCOwner
,OccupantsInfo
,OfferRequestProvider.OfferRequestPacket
,OfferRevokeProvider.OfferRevokePacket
,OfflineMessageRequest
,Open
,Privacy
,PrivateDataIQ
,PubSub
,Registration
,RoomInvitation.RoomInvitationIQ
,RoomTransfer.RoomTransferIQ
,RosterPacket
,RTPBridge
,SharedGroupsInfo
,SimpleIQ
,Slot
,SlotRequest
,StreamInitiation
,Time
,Transcript
,Transcripts
,UnblockContactsIQ
,UnparsedIQ
,VCard
,Version
,WorkgroupProperties
public abstract class IQ extends Stanza implements IqView
The base IQ (Info/Query) packet. IQ packets are used to get and set information on the server, including authentication, roster operations, and creating accounts. Each IQ stanza has a specific type that indicates what type of action is being taken: "get", "set", "result", or "error".IQ packets can contain a single child element that exists in a specific XML namespace. The combination of the element name and namespace determines what type of IQ stanza it is. Some example IQ subpacket snippets:
- <query xmlns="jabber:iq:auth"> -- an authentication IQ.
- <query xmlns="jabber:iq:private"> -- a private storage IQ.
- <pubsub xmlns="http://jabber.org/protocol/pubsub"> -- a pubsub IQ.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IQ.IQChildElementXmlStringBuilder
static class
IQ.ResponseType
static class
IQ.Type
A enum to represent the type of the IQ stanza.
-
Field Summary
Fields Modifier and Type Field Description static String
IQ_ELEMENT
static String
QUERY_ELEMENT
-
Fields inherited from class org.jivesoftware.smack.packet.Stanza
DEFAULT_LANGUAGE, ITEM, language, TEXT
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static ErrorIQ
createErrorResponse(IQ request, StanzaError error)
static ErrorIQ
createErrorResponse(IQ request, StanzaError.Builder error)
Deprecated.usecreateErrorResponse(IQ, StanzaError)
instead.static ErrorIQ
createErrorResponse(IQ request, StanzaError.Condition condition)
static IQ
createResultIQ(IQ request)
Convenience method to create a new emptyIQ.Type.result
IQ based on aIQ.Type.get
orIQ.Type.set
IQ.String
getChildElementName()
String
getChildElementNamespace()
QName
getChildElementQName()
XmlStringBuilder
getChildElementXML()
Returns the sub-element XML section of the IQ packet, or the empty String if there isn't one.String
getElementName()
Returns the root element name.protected abstract IQ.IQChildElementXmlStringBuilder
getIQChildElementBuilder(IQ.IQChildElementXmlStringBuilder xml)
This method must be overwritten by IQ subclasses to create their child content.IQ.Type
getType()
Returns the type of the IQ packet.boolean
isRequestIQ()
Return true if this IQ is a request IQ, i.e.boolean
isResponseIQ()
Return true if this IQ is a request, i.e.void
setType(IQ.Type type)
Sets the type of the IQ packet.String
toString()
Returns a short String describing the Stanza.XmlStringBuilder
toXML(XmlEnvironment enclosingXmlEnvironment)
-
Methods inherited from class org.jivesoftware.smack.packet.Stanza
addCommonAttributes, addExtension, addExtensions, appendErrorIfExists, getDefaultLanguage, getError, getExtension, getExtension, getExtension, getExtensionElement, getExtensions, getExtensions, getExtensions, getExtensions, getExtensionsMap, getFrom, getLanguage, getNamespace, getStanzaId, getTo, hasExtension, hasExtension, hasStanzaIdSet, logCommonAttributes, overrideExtension, removeExtension, removeExtension, setError, setError, setFrom, setLanguage, setNewStanzaId, setStanzaId, setStanzaId, setTo, throwIfNoStanzaId
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.smack.packet.FullyQualifiedElement
getQName
-
Methods inherited from interface org.jivesoftware.smack.packet.StanzaView
getError, getExtension, getExtension, getExtensions, getExtensions, getExtensions, getFrom, getStanzaId, getTo, hasExtension, hasExtension, hasExtension
-
-
-
-
Field Detail
-
IQ_ELEMENT
public static final String IQ_ELEMENT
- See Also:
- Constant Field Values
-
QUERY_ELEMENT
public static final String QUERY_ELEMENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getType
public IQ.Type getType()
Description copied from interface:IqView
Returns the type of the IQ packet.
-
setType
public void setType(IQ.Type type)
Sets the type of the IQ packet.Since the type of an IQ must present, an IllegalArgmentException will be thrown when type is
null
.- Parameters:
type
- the type of the IQ packet.
-
isRequestIQ
public boolean isRequestIQ()
Return true if this IQ is a request IQ, i.e. an IQ of typeIQ.Type.get
orIQ.Type.set
.- Returns:
- true if IQ type is 'get' or 'set', false otherwise.
- Since:
- 4.1
-
isResponseIQ
public boolean isResponseIQ()
Return true if this IQ is a request, i.e. an IQ of typeIQ.Type.result
orIQ.Type.error
.- Returns:
- true if IQ type is 'result' or 'error', false otherwise.
- Since:
- 4.4
-
getChildElementQName
public final QName getChildElementQName()
-
getChildElementName
public final String getChildElementName()
-
getChildElementNamespace
public final String getChildElementNamespace()
-
getElementName
public final String getElementName()
Description copied from interface:NamedElement
Returns the root element name.- Specified by:
getElementName
in interfaceNamedElement
- Returns:
- the element name.
-
toString
public final String toString()
Description copied from class:Stanza
Returns a short String describing the Stanza. This method is suited for log purposes.
-
toXML
public final XmlStringBuilder toXML(XmlEnvironment enclosingXmlEnvironment)
-
getChildElementXML
public final XmlStringBuilder getChildElementXML()
Returns the sub-element XML section of the IQ packet, or the empty String if there isn't one.- Returns:
- the child element section of the IQ XML.
-
getIQChildElementBuilder
protected abstract IQ.IQChildElementXmlStringBuilder getIQChildElementBuilder(IQ.IQChildElementXmlStringBuilder xml)
This method must be overwritten by IQ subclasses to create their child content. It is important you don't use the builder to add the final end tag. This will be done automatically byIQ.IQChildElementXmlStringBuilder
after eventual existingExtensionElement
s have been added.For example to create an IQ with a extra attribute and an additional child element
<iq to='foo@example.org' id='123'> <bar xmlns='example:bar' extraAttribute='blaz'> <extraElement>elementText</extraElement> </bar> </iq>
getIQChildElementBuilder
looks like// The builder 'xml' will already have the child element and the 'xmlns' attribute added // So the current builder state is "<bar xmlns='example:bar'" xml.attribute("extraAttribute", "blaz"); xml.rightAngleBracket(); xml.element("extraElement", "elementText"); // Do not close the 'bar' attribute by calling xml.closeElement('bar')
xml.attribute("myAttribute", "myAttributeValue"); xml.setEmptyElement();
If your IQ does not contain any attributes or child elements (besidesExtensionElement
s), consider sub-classingSimpleIQ
instead.- Parameters:
xml
- a pre-created builder which already has the child element and the 'xmlns' attribute set.- Returns:
- the build to create the IQ child content.
-
createResultIQ
public static IQ createResultIQ(IQ request)
Convenience method to create a new emptyIQ.Type.result
IQ based on aIQ.Type.get
orIQ.Type.set
IQ. The new stanza will be initialized with:- The sender set to the recipient of the originating IQ.
- The recipient set to the sender of the originating IQ.
- The type set to
IQ.Type.result
. - The id set to the id of the originating IQ.
- No child element of the IQ element.
- Parameters:
request
- theIQ.Type.get
orIQ.Type.set
IQ packet.- Returns:
- a new
IQ.Type.result
IQ based on the originating IQ. - Throws:
IllegalArgumentException
- if the IQ stanza does not have a type ofIQ.Type.get
orIQ.Type.set
.
-
createErrorResponse
public static ErrorIQ createErrorResponse(IQ request, StanzaError error)
Convenience method to create a newIQ.Type.error
IQ based on aIQ.Type.get
orIQ.Type.set
IQ. The new stanza will be initialized with:- The sender set to the recipient of the originating IQ.
- The recipient set to the sender of the originating IQ.
- The type set to
IQ.Type.error
. - The id set to the id of the originating IQ.
- The child element contained in the associated originating IQ.
- The provided
XMPPError
.
- Parameters:
request
- theIQ.Type.get
orIQ.Type.set
IQ packet.error
- the error to associate with the created IQ packet.- Returns:
- a new
IQ.Type.error
IQ based on the originating IQ. - Throws:
IllegalArgumentException
- if the IQ stanza does not have a type ofIQ.Type.get
orIQ.Type.set
.
-
createErrorResponse
@Deprecated public static ErrorIQ createErrorResponse(IQ request, StanzaError.Builder error)
Deprecated.usecreateErrorResponse(IQ, StanzaError)
instead.Deprecated.- Parameters:
request
- the request.error
- the error.- Returns:
- an error IQ.
-
createErrorResponse
public static ErrorIQ createErrorResponse(IQ request, StanzaError.Condition condition)
-
-