1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Long packet ID, more efficient properties handling.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1833 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2003-02-04 17:14:14 +00:00 committed by mtucker
parent 5311d5ad17
commit 2015674c78

View file

@ -74,7 +74,7 @@ public abstract class Packet {
/** /**
* A prefix helps to make sure that ID's are unique across mutliple instances. * A prefix helps to make sure that ID's are unique across mutliple instances.
*/ */
private static String prefix = StringUtils.randomString(3); private static String prefix = StringUtils.randomString(5);
/** /**
* Keeps track of the current increment, which is appended to the prefix to * Keeps track of the current increment, which is appended to the prefix to
@ -95,7 +95,7 @@ public abstract class Packet {
private String packetID = nextID(); private String packetID = nextID();
private String to = null; private String to = null;
private String from = null; private String from = null;
private Map properties = new HashMap(); private Map properties = null;
private Error error = null; private Error error = null;
/** /**
@ -190,6 +190,9 @@ public abstract class Packet {
* @return the property, or <tt>null</tt> if the property doesn't exist. * @return the property, or <tt>null</tt> if the property doesn't exist.
*/ */
public synchronized Object getProperty(String name) { public synchronized Object getProperty(String name) {
if (properties == null) {
return null;
}
return properties.get(name); return properties.get(name);
} }
@ -254,6 +257,9 @@ public abstract class Packet {
if (!(value instanceof Serializable)) { if (!(value instanceof Serializable)) {
throw new IllegalArgumentException("Value must be serialiazble"); throw new IllegalArgumentException("Value must be serialiazble");
} }
if (properties == null) {
properties = new HashMap();
}
properties.put(name, value); properties.put(name, value);
} }
@ -263,6 +269,9 @@ public abstract class Packet {
* @param name the name of the property to delete. * @param name the name of the property to delete.
*/ */
public synchronized void deleteProperty(String name) { public synchronized void deleteProperty(String name) {
if (properties == null) {
return;
}
properties.remove(name); properties.remove(name);
} }
@ -272,6 +281,9 @@ public abstract class Packet {
* @return an Iterator for all property names. * @return an Iterator for all property names.
*/ */
public synchronized Iterator getPropertyNames() { public synchronized Iterator getPropertyNames() {
if (properties == null) {
return Collections.EMPTY_LIST.iterator();
}
return properties.keySet().iterator(); return properties.keySet().iterator();
} }
@ -292,7 +304,7 @@ public abstract class Packet {
*/ */
protected synchronized String getPropertiesXML() { protected synchronized String getPropertiesXML() {
// Return null if there are no properties. // Return null if there are no properties.
if (properties.isEmpty()) { if (properties == null || properties.isEmpty()) {
return null; return null;
} }
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();