| java.lang.Object org.xmpp.packet.Packet org.xmpp.packet.IQ
All known Subclasses: org.xmpp.muc.RoomConfiguration, org.xmpp.muc.DestroyRoom, org.xmpp.packet.Roster,
IQ | public class IQ extends Packet (Code) | | 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 extended XML
namespace.
|
Inner Class :public enum Type | |
Constructor Summary | |
public | IQ() Constructs a new IQ with an automatically generated ID and a type
of
Type.get IQ.Type.get . | public | IQ(Type type) Constructs a new IQ using the specified type. | public | IQ(Type type, String ID) Constructs a new IQ using the specified type and ID. | public | IQ(Element element) Constructs a new IQ using an existing Element. | public | IQ(Element element, boolean skipValidation) Constructs a new IQ using an existing Element. |
Method Summary | |
public void | addExtension(PacketExtension extension) Adds the element contained in the PacketExtension to the child element of the IQ
packet. | public IQ | createCopy() Returns a deep copy of this IQ. | public static IQ | createResultIQ(IQ iq) Convenience method to create a new
Type.result IQ.Type.result IQ based
on a
Type.get IQ.Type.get or
Type.set IQ.Type.set IQ. | public boolean | deleteExtension(String name, String namespace) Deletes the first element whose element name and namespace matches the specified
element name and namespace in this packet's child element. | public Element | getChildElement() Returns the child element of this IQ. | public PacketExtension | getExtension(String name, String namespace) Returns a
PacketExtension on the first element found in this packet's
child element for the specified name and namespace or null if
none was found. | public Type | getType() Returns the type of this IQ. | public boolean | isRequest() Convenience routine to indicate if this is a request stanza. | public boolean | isResponse() Convenience routine to indicate if this is a response stanza. | public void | setChildElement(Element childElement) Sets the child element of this IQ. | public Element | setChildElement(String name, String namespace) Sets the child element of this IQ by constructing a new Element with the
given name and namespace. | public void | setType(Type type) Sets the type of this IQ. |
IQ | public IQ()(Code) | | Constructs a new IQ with an automatically generated ID and a type
of
Type.get IQ.Type.get .
|
IQ | public IQ(Type type)(Code) | | Constructs a new IQ using the specified type. A packet ID will
be automatically generated.
Parameters: type - the IQ type. |
IQ | public IQ(Type type, String ID)(Code) | | Constructs a new IQ using the specified type and ID.
Parameters: ID - the packet ID of the IQ. Parameters: type - the IQ type. |
IQ | public IQ(Element element)(Code) | | Constructs a new IQ using an existing Element. This is useful
for parsing incoming IQ Elements into IQ objects.
Parameters: element - the IQ Element. |
IQ | public IQ(Element element, boolean skipValidation)(Code) | | Constructs a new IQ using an existing Element. This is useful
for parsing incoming IQ Elements into IQ objects. Stringprep validation
on the TO address can be disabled. The FROM address will not be validated since the
server is the one that sets that value.
Parameters: element - the IQ Element. Parameters: skipValidation - true if stringprep should not be applied to the TO address. |
addExtension | public void addExtension(PacketExtension extension)(Code) | | Adds the element contained in the PacketExtension to the child element of the IQ
packet. IQ packets, unlike the other packet types, have a unique child element that
holds the packet extensions. If an extension is added to an IQ packet that does
not have a child element then an IllegalStateException will be thrown.
It is important that this is the first and last time the element contained in
PacketExtension is added to another Packet. Otherwise, a runtime error will be
thrown when trying to add the PacketExtension's element to the Packet's element.
Future modifications to the PacketExtension will be reflected in this Packet.
Note: packet extensions on IQ packets are only for use in specialized situations.
In most cases, you should only need to set the child element of the IQ.
Parameters: extension - the PacketExtension whose element will be added to this Packet's element. |
createCopy | public IQ createCopy()(Code) | | Returns a deep copy of this IQ.
a deep copy of this IQ. |
createResultIQ | public static IQ createResultIQ(IQ iq)(Code) | | Convenience method to create a new
Type.result IQ.Type.result IQ based
on a
Type.get IQ.Type.get or
Type.set IQ.Type.set IQ. The new
packet 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
Type.result IQ.Type.result .
- The id set to the id of the originating IQ.
Parameters: iq - the Type.get IQ.Type.get or Type.set IQ.Type.set IQ packet. throws: IllegalArgumentException - if the IQ packet does not have a type ofType.get IQ.Type.get or Type.set IQ.Type.set. a new Type.result IQ.Type.result IQ based on the originating IQ. |
deleteExtension | public boolean deleteExtension(String name, String namespace)(Code) | | Deletes the first element whose element name and namespace matches the specified
element name and namespace in this packet's child element. If the
IQ packet does not have a child element then this method does nothing and returns
false.
Notice that this method may remove any child element that matches the specified
element name and namespace even if that element was not added to the Packet using a
PacketExtension .
Note: packet extensions on IQ packets are only for use in specialized situations.
In most cases, you should only need to set the child element of the IQ.
Parameters: name - the child element name. Parameters: namespace - the child element namespace. true if a child element was removed. |
getChildElement | public Element getChildElement()(Code) | | Returns the child element of this IQ. IQ packets may have a single child
element in an extended namespace. This is a convenience method to
avoid manipulating the underlying packet's Element instance directly.
An IQ child element in extended namespaces is used to extend the features
of XMPP. Although any valid XML can be included in a child element
in an extended namespace, many common features have been standardized
as Jabber Enhancement Proposals
(JEPs).
the child element. |
getExtension | public PacketExtension getExtension(String name, String namespace)(Code) | | Returns a
PacketExtension on the first element found in this packet's
child element for the specified name and namespace or null if
none was found. If the IQ packet does not have a child element then null
will be returned.
Note: packet extensions on IQ packets are only for use in specialized situations.
In most cases, you should only need to set the child element of the IQ.
Parameters: name - the child element name. Parameters: namespace - the child element namespace. a PacketExtension on the first element found in this packet for the specifiedname and namespace or null if none was found. |
getType | public Type getType()(Code) | | Returns the type of this IQ.
the IQ type. See Also: Type |
isRequest | public boolean isRequest()(Code) | | Convenience routine to indicate if this is a request stanza. (get or set)
True or false if this is a request stanza |
isResponse | public boolean isResponse()(Code) | | Convenience routine to indicate if this is a response stanza. (result or error)
True or false if this is a response stanza |
setChildElement | public void setChildElement(Element childElement)(Code) | | Sets the child element of this IQ. IQ packets may have a single child
element in an extended namespace. This is a convenience method to
avoid manipulating this underlying packet's Element instance directly.
A sample use of this method might look like the following:
IQ iq = new IQ("time_1");
iq.setTo("mary@example.com");
iq.setType(IQ.Type.GET);
iq.setChildElement(docFactory.createElement("query", "jabber:iq:time"));
An IQ child element in extended namespaces is used to extend the features
of XMPP. Although any valid XML can be included in a child element
in an extended namespace, many common features have been standardized
as Jabber Enhancement Proposals
(JEPs).
Parameters: childElement - the child element. |
setChildElement | public Element setChildElement(String name, String namespace)(Code) | | Sets the child element of this IQ by constructing a new Element with the
given name and namespace. The newly created child element is returned.
IQ packets may have a single child element in an extended namespace.
This method is a convenience method to avoid manipulating the underlying
packet's Element instance directly.
In some cases, additional custom sub-elements must be added to an IQ child
element (called packet extensions). For example, when adding a data form to
an IQ response. See
IQ.addExtension(PacketExtension) .
A sample use of this method might look like the following:
IQ iq = new IQ("time_1");
iq.setTo("mary@example.com");
iq.setType(IQ.Type.GET);
iq.setChildElement("query", "jabber:iq:time");
Parameters: name - the child element name. Parameters: namespace - the child element namespace. the newly created child element. |
setType | public void setType(Type type)(Code) | | Sets the type of this IQ.
Parameters: type - the IQ type. See Also: Type |
|
|