Smack

org.jivesoftware.smack.packet
Class IQ

java.lang.Object
  extended by org.jivesoftware.smack.packet.Packet
      extended by org.jivesoftware.smack.packet.IQ
Direct Known Subclasses:
AdHocCommandData, AgentChatHistory, AgentInfo, AgentStatusRequest, AgentWorkgroups, Authentication, Bind, Bytestream, ChatMetadata, ChatNotes, ChatSettings, Close, Data, DepartQueuePacket, DiscoverInfo, DiscoverItems, GenericSettings, LastActivity, Macros, MonitorPacket, MUCAdmin, MUCOwner, OccupantsInfo, OfferConfirmation, OfferRequestProvider.OfferRequestPacket, OfferRevokeProvider.OfferRevokePacket, OfflineMessageRequest, OfflineSettings, Open, PEPPubSub, Privacy, PubSub, Registration, RosterPacket, SearchSettings, Session, SharedGroupsInfo, SoundSettings, StreamInitiation, Time, Transcript, Transcripts, TranscriptSearch, UserSearch, VCard, Version, WorkgroupForm, WorkgroupProperties

public abstract class IQ
extends Packet

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 packet 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 packet it is. Some example IQ subpacket snippets:

Author:
Matt Tucker

Nested Class Summary
static class IQ.Type
          A class to represent the type of the IQ packet.
 
Field Summary
 
Fields inherited from class org.jivesoftware.smack.packet.Packet
DEFAULT_LANGUAGE, ID_NOT_AVAILABLE
 
Constructor Summary
IQ()
           
 
Method Summary
static IQ createErrorResponse(IQ request, XMPPError error)
          Convenience method to create a new IQ.Type.ERROR IQ based on a IQ.Type.GET or IQ.Type.SET IQ.
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.
abstract  String getChildElementXML()
          Returns the sub-element XML section of the IQ packet, or null if there isn't one.
 IQ.Type getType()
          Returns the type of the IQ packet.
 void setType(IQ.Type type)
          Sets the type of the IQ packet.
 String toXML()
          Returns the packet as XML.
 
Methods inherited from class org.jivesoftware.smack.packet.Packet
addExtension, deleteProperty, equals, getDefaultLanguage, getError, getExtension, getExtension, getExtensions, getExtensionsXML, getFrom, getPacketID, getProperty, getPropertyNames, getTo, getXmlns, hashCode, nextID, removeExtension, setDefaultXmlns, setError, setFrom, setPacketID, setProperty, setTo
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IQ

public IQ()
Method Detail

getType

public IQ.Type getType()
Returns the type of the IQ packet.

Returns:
the type of the IQ packet.

setType

public void setType(IQ.Type type)
Sets the type of the IQ packet.

Parameters:
type - the type of the IQ packet.

toXML

public String toXML()
Description copied from class: Packet
Returns the packet as XML. Every concrete extension of Packet must implement this method. In addition to writing out packet-specific data, every sub-class should also write out the error and the extensions data if they are defined.

Specified by:
toXML in class Packet
Returns:
the XML format of the packet as a String.

getChildElementXML

public abstract String getChildElementXML()
Returns the sub-element XML section of the IQ packet, or null if there isn't one. Packet extensions must be included, if any are defined.

Extensions of this class must override this method.

Returns:
the child element section of the IQ XML.

createResultIQ

public 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. The new packet will be initialized with:

Parameters:
iq - the IQ.Type.GET or IQ.Type.SET IQ packet.
Returns:
a new IQ.Type.RESULT IQ based on the originating IQ.
Throws:
IllegalArgumentException - if the IQ packet does not have a type of IQ.Type.GET or IQ.Type.SET.

createErrorResponse

public static IQ createErrorResponse(IQ request,
                                     XMPPError error)
Convenience method to create a new IQ.Type.ERROR IQ based on a IQ.Type.GET or IQ.Type.SET IQ. The new packet will be initialized with:

Parameters:
iq - the IQ.Type.GET or IQ.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 packet does not have a type of IQ.Type.GET or IQ.Type.SET.

Smack

Copyright © 2003-2007 Jive Software.