summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGurmeen Bindra <gurmeen.bindra@isode.com>2012-04-16 11:08:41 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-04-19 10:45:37 (GMT)
commitbae6e6298a617b801a15cbdba13d6759d8b44f31 (patch)
tree8508bd612b8ace3ba25311d2fad181ca5761662a /src/com/isode/stroke/elements/Stanza.java
parent00b0f316b9125031f30151cacdf2dcf217b8fa01 (diff)
downloadstroke-bae6e6298a617b801a15cbdba13d6759d8b44f31.zip
stroke-bae6e6298a617b801a15cbdba13d6759d8b44f31.tar.bz2
Add a copy constructor to Presence and Stanza + compare method in JID
This patch adds a copy constructor to the Presence class(and hence base class Staza as well). It also ports the compare method to JID class. Also added javadocs to Presence and Stanza classes. Test-information: tested using the Work In Progress code that ports MUC Admin to stroke Reviewer: Kevin Smith <kevin.smith@isode.com>
Diffstat (limited to 'src/com/isode/stroke/elements/Stanza.java')
-rw-r--r--src/com/isode/stroke/elements/Stanza.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/com/isode/stroke/elements/Stanza.java b/src/com/isode/stroke/elements/Stanza.java
index 036ec8b..c542e8b 100644
--- a/src/com/isode/stroke/elements/Stanza.java
+++ b/src/com/isode/stroke/elements/Stanza.java
@@ -21,7 +21,33 @@ public abstract class Stanza implements Element {
private JID to_;
private Vector<Payload> payloads_ = new Vector<Payload>();
+ /**
+ * Create a stanza object
+ */
+ public Stanza() {
+ }
+
+ /**
+ * Create a stanza object copy from another
+ * @param other object to be copied, not null
+ */
+ public Stanza(Stanza other) {
+ this.id_ = other.id_;
+ if(other.from_ != null) {
+ this.from_ = JID.fromString(other.from_.toString());
+ }
+ if(other.to_!= null) {
+ this.to_ = JID.fromString(other.to_.toString());
+ }
+ payloads_ = new Vector<Payload>(other.payloads_);
+ }
+ /**
+ * Get the payload of the given type from the stanza
+ * @param <T> payload type
+ * @param type payload type object instance, not null
+ * @return payload of given type, can be null
+ */
public <T extends Payload> T getPayload(T type) {
for (Payload payload : payloads_) {
if (payload.getClass().isAssignableFrom(type.getClass())) {
@@ -31,6 +57,12 @@ public abstract class Stanza implements Element {
return null;
}
+ /**
+ * Get the payloads of the given type from the stanza
+ * @param <T> payload type
+ * @param type payload type object instance, not null
+ * @return list of payloads of given type, not null but can be empty
+ */
public <T extends Payload> Vector<T> getPayloads(T type) {
Vector<T> results = new Vector<T>();
for (Payload payload : payloads_) {
@@ -41,14 +73,27 @@ public abstract class Stanza implements Element {
return results;
}
+ /**
+ * Get the list of payloads from this stanza
+ * @return list of payloads, not null but can be empty
+ */
public Vector<Payload> getPayloads() {
return payloads_;
}
+ /**
+ * Add a payload to the stanza
+ * @param payload payload to be added, not null
+ */
public void addPayload(Payload payload) {
payloads_.add(payload);
}
+ /**
+ * Update payload to the staza object. It will replace the payload of
+ * given type if it exists or add it the list if it does not exist
+ * @param payload payload to be updated, not null
+ */
public void updatePayload(Payload payload) {
for (int i = 0; i < payloads_.size(); i++) {
if (payloads_.get(i).getClass() == payload.getClass()) {
@@ -59,26 +104,51 @@ public abstract class Stanza implements Element {
payloads_.add(payload);
}
+ /**
+ * Get the jabber ID of the sender
+ * @return jabber id, can be null
+ */
public JID getFrom() {
return from_;
}
+ /**
+ * Set the jabber ID of the sender
+ * @param from jabber id, can be null
+ */
public void setFrom(JID from) {
from_ = from;
}
+ /**
+ * Get the jabber ID of the recipient user of the stanza
+ * @return jabber id, can be null
+ */
public JID getTo() {
return to_;
}
+ /**
+ * Set the jabber ID of the recipient user of the stanza
+ * @param to jabber id, can be null
+ */
public void setTo(JID to) {
to_ = to;
}
+ /**
+ * Get the identification string of the stanza
+ * @return ID string, can be null if its not an IQ stanza
+ */
public String getID() {
return id_;
}
+ /**
+ * Set the identification string of the stanza
+ * @param id ID string, not null for IQ stanza but can be null for
+ * Message or Presence stanza
+ */
public void setID(String id) {
id_ = id;
}