public abstract class IQ extends Stanza
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(/packet) it is. Some example IQ subpacket snippets:
Modifier and Type | Class and Description |
---|---|
static class |
IQ.IQChildElementXmlStringBuilder |
static class |
IQ.Type
A enum to represent the type of the IQ stanza.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
IQ_ELEMENT |
static java.lang.String |
QUERY_ELEMENT |
DEFAULT_LANGUAGE, ITEM, language, TEXT
Modifier | Constructor and Description |
---|---|
|
IQ(IQ iq) |
protected |
IQ(java.lang.String childElementName) |
protected |
IQ(java.lang.String childElementName,
java.lang.String childElementNamespace) |
Modifier and Type | Method and Description |
---|---|
static ErrorIQ |
createErrorResponse(IQ request,
XMPPError.Builder error)
|
static ErrorIQ |
createErrorResponse(IQ request,
XMPPError.Condition condition) |
static ErrorIQ |
createErrorResponse(IQ request,
XMPPError error)
|
static IQ |
createResultIQ(IQ request)
Convenience method to create a new empty
IQ.Type.result
IQ based on a IQ.Type.get or IQ.Type.set
IQ. |
java.lang.String |
getChildElementName() |
java.lang.String |
getChildElementNamespace() |
XmlStringBuilder |
getChildElementXML()
Returns the sub-element XML section of the IQ packet, or the empty String if there
isn't one.
|
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.
|
protected void |
initializeAsResultFor(IQ request) |
protected void |
initialzeAsResultFor(IQ request)
Deprecated.
use
initializeAsResultFor(IQ) instead. |
boolean |
isRequestIQ()
Return true if this IQ is a request IQ, i.e.
|
void |
setType(IQ.Type type)
Sets the type of the IQ packet.
|
java.lang.String |
toString()
Returns a short String describing the Stanza.
|
XmlStringBuilder |
toXML()
Returns the XML representation of this Element.
|
addCommonAttributes, addExtension, addExtensions, appendErrorIfExists, getDefaultLanguage, getError, getExtension, getExtension, getExtensions, getExtensions, getExtensionsXML, getFrom, getLanguage, getPacketID, getStanzaId, getTo, hasExtension, hasExtension, hasStanzaIdSet, logCommonAttributes, overrideExtension, removeExtension, removeExtension, setError, setError, setFrom, setFrom, setLanguage, setPacketID, setStanzaId, setStanzaId, setTo, setTo
public static final java.lang.String IQ_ELEMENT
public static final java.lang.String QUERY_ELEMENT
protected IQ(java.lang.String childElementName)
protected IQ(java.lang.String childElementName, java.lang.String childElementNamespace)
public IQ.Type getType()
public void setType(IQ.Type type)
Since the type of an IQ must present, an IllegalArgmentException will be thrown when type is
null
.
type
- the type of the IQ packet.public boolean isRequestIQ()
IQ.Type.get
or IQ.Type.set
.public final java.lang.String getChildElementName()
public final java.lang.String getChildElementNamespace()
public final java.lang.String toString()
Stanza
public final XmlStringBuilder toXML()
Element
public final XmlStringBuilder getChildElementXML()
protected abstract IQ.IQChildElementXmlStringBuilder getIQChildElementBuilder(IQ.IQChildElementXmlStringBuilder xml)
IQ.IQChildElementXmlStringBuilder
after eventual existing ExtensionElement
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>
the body of the 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')
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.
xml.attribute("myAttribute", "myAttributeValue"); xml.setEmptyElement();If your IQ does not contain any attributes or child elements (besides
ExtensionElement
s), consider sub-classing
SimpleIQ
instead.xml
- a pre-created builder which already has the child element and the 'xmlns' attribute set.@Deprecated protected final void initialzeAsResultFor(IQ request)
initializeAsResultFor(IQ)
instead.protected final void initializeAsResultFor(IQ request)
public static IQ createResultIQ(IQ request)
IQ.Type.result
IQ based on a IQ.Type.get
or IQ.Type.set
IQ. The new stanza(/packet) will be initialized with:IQ.Type.result
.
request
- the IQ.Type.get
or IQ.Type.set
IQ packet.IQ.Type.result
IQ based on the originating IQ.java.lang.IllegalArgumentException
- if the IQ stanza(/packet) does not have a type of
IQ.Type.get
or IQ.Type.set
.public static ErrorIQ createErrorResponse(IQ request, XMPPError.Builder error)
IQ.Type.error
IQ
based on a IQ.Type.get
or IQ.Type.set
IQ. The new stanza(/packet) will be initialized with:IQ.Type.error
.
XMPPError
.
request
- the IQ.Type.get
or IQ.Type.set
IQ packet.error
- the error to associate with the created IQ packet.IQ.Type.error
IQ based on the originating IQ.java.lang.IllegalArgumentException
- if the IQ stanza(/packet) does not have a type of
IQ.Type.get
or IQ.Type.set
.public static ErrorIQ createErrorResponse(IQ request, XMPPError.Condition condition)
public static ErrorIQ createErrorResponse(IQ request, XMPPError error)
IQ.Type.error
IQ
based on a IQ.Type.get
or IQ.Type.set
IQ. The new stanza(/packet) will be initialized with:IQ.Type.error
.
XMPPError
.
request
- the IQ.Type.get
or IQ.Type.set
IQ packet.error
- the error to associate with the created IQ packet.IQ.Type.error
IQ based on the originating IQ.java.lang.IllegalArgumentException
- if the IQ stanza(/packet) does not have a type of
IQ.Type.get
or IQ.Type.set
.