From 627b38fe5b6c93ae3a1e7ad9f19c2f9830d0adb9 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Tue, 10 Feb 2004 15:36:57 +0000 Subject: [PATCH] Handles packets with no (explicit) id git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2223 b35dd754-fafc-0310-a699-88a17e54d16e --- .../org/jivesoftware/smack/packet/Packet.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/source/org/jivesoftware/smack/packet/Packet.java b/source/org/jivesoftware/smack/packet/Packet.java index 35ef94ad4..347bd8784 100644 --- a/source/org/jivesoftware/smack/packet/Packet.java +++ b/source/org/jivesoftware/smack/packet/Packet.java @@ -71,6 +71,13 @@ import java.io.*; */ public abstract class Packet { + /** + * Constant used as packetID to indicate that a packet has no id. To indicate that a packet + * has no id set this constant as the packet's id. When the packet is asked for its id the + * answer will be null. + */ + public static final String ID_NOT_AVAILABLE = "ID_NOT_AVAILABLE"; + /** * A prefix helps to make sure that ID's are unique across mutliple instances. */ @@ -100,11 +107,16 @@ public abstract class Packet { private XMPPError error = null; /** - * Returns the unique ID of the packet. + * Returns the unique ID of the packet. The returned value could be null when + * ID_NOT_AVAILABLE was set as the packet's id. * - * @return the packet's unique ID. + * @return the packet's unique ID or null if the packet's id is not available. */ public String getPacketID() { + if (ID_NOT_AVAILABLE.equals(packetID)) { + return null; + } + if (packetID == null) { packetID = nextID(); } @@ -112,7 +124,8 @@ public abstract class Packet { } /** - * Sets the unique ID of the packet. + * Sets the unique ID of the packet. To indicate that a packet has no id + * pass the constant ID_NOT_AVAILABLE as the packet's id value. * * @param packetID the unique ID for the packet. */