Package org.jivesoftware.smack.packet
Class IQ
java.lang.Object
org.jivesoftware.smack.packet.Stanza
org.jivesoftware.smack.packet.IQ
- All Implemented Interfaces:
Element,IqView,NamedElement,StanzaView,TopLevelStreamElement,XmlElement,XmlLangElement
- Direct Known Subclasses:
Bind,EmptyResultIQ,ErrorIQ,SimpleIQ,UnparsedIQ
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 ClassesModifier and TypeClassDescriptionstatic classstatic enumstatic enumA enum to represent the type of the IQ stanza. -
Field Summary
FieldsFields inherited from class org.jivesoftware.smack.packet.Stanza
DEFAULT_LANGUAGE, ITEM, language, TEXT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ErrorIQcreateErrorResponse(IQ request, StanzaError error) static ErrorIQcreateErrorResponse(IQ request, StanzaError.Condition condition) static IQcreateResultIQ(IQ request) Convenience method to create a new emptyIQ.Type.resultIQ based on aIQ.Type.getorIQ.Type.setIQ.final Stringfinal Stringfinal QNamefinal XmlStringBuilderReturns the sub-element XML section of the IQ packet, or the empty String if there isn't one.final StringReturns the root element name.protected abstract IQ.IQChildElementXmlStringBuilderThis method must be overwritten by IQ subclasses to create their child content.final IQ.TypegetType()Returns the type of the IQ packet.voidSets the type of the IQ packet.final StringtoString()Returns a short String describing the Stanza.final XmlStringBuildertoXML(XmlEnvironment enclosingXmlEnvironment) Methods inherited from class org.jivesoftware.smack.packet.Stanza
addCommonAttributes, addExtension, addExtensions, appendErrorIfExists, getDefaultLanguage, getError, getExtension, getExtension, getExtensionElement, getExtensions, getExtensions, getExtensions, getExtensions, getExtensionsMap, getFrom, getLanguage, getNamespace, getStanzaId, getTo, hasExtension, hasExtension, hasStanzaIdSet, logCommonAttributes, overrideExtension, removeExtension, setError, setFrom, setNewStanzaId, setStanzaId, setTo, throwIfNoStanzaIdMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jivesoftware.smack.packet.IqView
isRequestIQ, isResponseIQMethods inherited from interface org.jivesoftware.smack.packet.StanzaView
getError, getExtension, getExtension, getExtensions, getExtensions, getExtensions, getFrom, getStanzaId, getTo, hasExtension, hasExtension, hasExtensionMethods inherited from interface org.jivesoftware.smack.packet.XmlElement
getQName
-
Field Details
-
IQ_ELEMENT
- See Also:
-
QUERY_ELEMENT
- See Also:
-
-
Constructor Details
-
IQ
-
IQ
-
IQ
-
IQ
-
-
Method Details
-
getType
Description copied from interface:IqViewReturns the type of the IQ packet. -
setType
Sets the type of the IQ packet.Since the type of an IQ must present, an IllegalArgumentException will be thrown when type is
null.- Parameters:
type- the type of the IQ packet.
-
getChildElementQName
-
getChildElementName
-
getChildElementNamespace
-
getElementName
Description copied from interface:NamedElementReturns the root element name.- Specified by:
getElementNamein interfaceNamedElement- Returns:
- the element name.
-
toString
Description copied from class:StanzaReturns a short String describing the Stanza. This method is suited for log purposes. -
toXML
-
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.IQChildElementXmlStringBuilderafter eventual existingExtensionElements have been added.For example to create an IQ with a extra attribute and an additional child element
the body of the<iq to='foo@example.org' id='123'> <bar xmlns='example:bar' extraAttribute='blaz'> <extraElement>elementText</extraElement> </bar> </iq>getIQChildElementBuilderlooks like
If your IQ only contains attributes and no child elements, i.e. it can be represented as empty element, then you can mark it as such.// 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 (besidesExtensionElements), consider sub-classingSimpleIQinstead.- 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
Convenience method to create a new emptyIQ.Type.resultIQ based on aIQ.Type.getorIQ.Type.setIQ. 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.getorIQ.Type.setIQ packet.- Returns:
- a new
IQ.Type.resultIQ based on the originating IQ. - Throws:
IllegalArgumentException- if the IQ stanza does not have a type ofIQ.Type.getorIQ.Type.set.
-
createErrorResponse
Convenience method to create a newIQ.Type.errorIQ based on aIQ.Type.getorIQ.Type.setIQ. 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.getorIQ.Type.setIQ packet.error- the error to associate with the created IQ packet.- Returns:
- a new
IQ.Type.errorIQ based on the originating IQ. - Throws:
IllegalArgumentException- if the IQ stanza does not have a type ofIQ.Type.getorIQ.Type.set.
-
createErrorResponse
-