| java.lang.Object org.xmpp.packet.Packet
All known Subclasses: org.xmpp.packet.IQ, org.jivesoftware.openfire.multiplex.Route, org.xmpp.packet.Message, org.xmpp.packet.Presence,
Packet | abstract public class Packet (Code) | | An XMPP packet (also referred to as a stanza). Each packet is backed by a
DOM4J Element. A set of convenience methods allows easy manipulation of
the Element, or the Element can be accessed directly and manipulated.
There are three core packet types:
-
Message -- used to send data between users.
-
Presence -- contains user presence information or is used
to manage presence subscriptions.
-
IQ -- exchange information and perform queries using a
request/response protocol.
author: Matt Tucker |
Constructor Summary | |
public | Packet(Element element) Constructs a new Packet. | public | Packet(Element element, boolean skipValidation) Constructs a new Packet. | protected | Packet() Constructs a new Packet with no element data. |
Method Summary | |
public void | addExtension(PacketExtension extension) Adds the element contained in the PacketExtension to the element of this packet.
It is important that this is the first and last time the element contained in
PacketExtension is added to another Packet. | abstract public Packet | createCopy() Creates a deep copy of this packet. | public boolean | deleteExtension(String name, String namespace) Deletes the first element whose element name and namespace matches the specified
element name and namespace.
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 .
Parameters: name - the child element name. Parameters: namespace - the child element namespace. | public Element | getElement() Returns the DOM4J Element that backs the packet. | public PacketError | getError() Returns the packet error, or null if there is no packet error. | public PacketExtension | getExtension(String name, String namespace) Returns a
PacketExtension on the first element found in this packet
for the specified name and namespace or null if
none was found.
Parameters: name - the child element name. Parameters: namespace - the child element namespace. | public JID | getFrom() Returns the XMPP address (JID) that the packet is from, or null
if the "from" attribute is not set. | public String | getID() Returns the packet ID, or null if the packet does not have an ID. | public JID | getTo() Returns the XMPP address (JID) that the packet is addressed to, or null
if the "to" attribute is not set. | public void | setError(PacketError error) Sets the packet error. | public void | setError(PacketError.Condition condition) Sets the packet error using the specified condition. | public void | setFrom(String from) Sets the XMPP address (JID) that the packet comes from. | public void | setFrom(JID from) Sets the XMPP address (JID) that the packet comes from. | public void | setID(String ID) Sets the packet ID. | public void | setTo(String to) Sets the XMPP address (JID) that the packet is addressed to. | public void | setTo(JID to) Sets the XMPP address (JID) that the packet is address to. | public String | toString() | public String | toXML() Returns the textual XML representation of this packet. |
docFactory | protected static DocumentFactory docFactory(Code) | | |
element | protected Element element(Code) | | |
Packet | public Packet(Element element)(Code) | | Constructs a new Packet. The TO address contained in the XML Element will only be
validated. In other words, stringprep operations will only be performed on the TO JID to
verify that it is well-formed. The FROM address is assigned by the server so there is no
need to verify it.
Parameters: element - the XML Element that contains the packet contents. |
Packet | public Packet(Element element, boolean skipValidation)(Code) | | Constructs a new Packet. The JID address contained in the XML Element may not be
validated. When validation can be skipped then stringprep operations will not be performed
on the JIDs to verify that addresses are well-formed. However, when validation cannot be
skipped then only the TO address will be verified. The FROM address is assigned by
the server so there is no need to verify it.
Parameters: element - the XML Element that contains the packet contents. Parameters: skipValidation - true if stringprep should not be applied to the TO address. |
Packet | protected Packet()(Code) | | Constructs a new Packet with no element data. This method is used by
extensions of this class that require a more optimized path for creating
new packets.
|
addExtension | public void addExtension(PacketExtension extension)(Code) | | Adds the element contained in the PacketExtension to the element of this packet.
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.
Parameters: extension - the PacketExtension whose element will be added to this Packet's element. |
createCopy | abstract public Packet createCopy()(Code) | | Creates a deep copy of this packet.
a deep copy of this packet. |
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.
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 .
Parameters: name - the child element name. Parameters: namespace - the child element namespace. true if a child element was removed. |
getElement | public Element getElement()(Code) | | Returns the DOM4J Element that backs the packet. The element is the definitive
representation of the packet and can be manipulated directly to change
packet contents.
the DOM4J Element that represents the packet. |
getError | public PacketError getError()(Code) | | Returns the packet error, or null if there is no packet error.
the packet error. |
getExtension | public PacketExtension getExtension(String name, String namespace)(Code) | | Returns a
PacketExtension on the first element found in this packet
for the specified name and namespace or null if
none was found.
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. |
getFrom | public JID getFrom()(Code) | | Returns the XMPP address (JID) that the packet is from, or null
if the "from" attribute is not set. The XMPP protocol often makes the "from"
attribute optional, so it does not always need to be set.
the XMPP address that the packet is from, or nullif not set. |
getID | public String getID()(Code) | | Returns the packet ID, or null if the packet does not have an ID.
Packet ID's are optional, except for IQ packets.
the packet ID. |
getTo | public JID getTo()(Code) | | Returns the XMPP address (JID) that the packet is addressed to, or null
if the "to" attribute is not set. The XMPP protocol often makes the "to"
attribute optional, so it does not always need to be set.
the XMPP address (JID) that the packet is addressed to, or nullif not set. |
setError | public void setError(PacketError error)(Code) | | Sets the packet error. Calling this method will automatically set
the packet "type" attribute to "error".
Parameters: error - the packet error. |
setError | public void setError(PacketError.Condition condition)(Code) | | Sets the packet error using the specified condition. Calling this
method will automatically set the packet "type" attribute to "error".
This is a convenience method equivalent to calling:
setError(new PacketError(condition));
Parameters: condition - the error condition. |
setFrom | public void setFrom(String from)(Code) | | Sets the XMPP address (JID) that the packet comes from. The XMPP protocol
often makes the "from" attribute optional, so it does not always need to be set.
Parameters: from - the XMPP address (JID) that the packet comes from. |
setFrom | public void setFrom(JID from)(Code) | | Sets the XMPP address (JID) that the packet comes from. The XMPP protocol
often makes the "from" attribute optional, so it does not always need to be set.
Parameters: from - the XMPP address (JID) that the packet comes from. |
setID | public void setID(String ID)(Code) | | Sets the packet ID. Packet ID's are optional, except for IQ packets.
Parameters: ID - the packet ID. |
setTo | public void setTo(String to)(Code) | | Sets the XMPP address (JID) that the packet is addressed to. The XMPP protocol
often makes the "to" attribute optional, so it does not always need to be set.
Parameters: to - the XMPP address (JID) that the packet is addressed to. |
setTo | public void setTo(JID to)(Code) | | Sets the XMPP address (JID) that the packet is address to. The XMPP protocol
often makes the "to" attribute optional, so it does not always need to be set.
Parameters: to - the XMPP address (JID) that the packet is addressed to. |
toXML | public String toXML()(Code) | | Returns the textual XML representation of this packet.
the textual XML representation of this packet. |
|
|