diff options
author | Gurmeen Bindra <gurmeen.bindra@isode.com> | 2012-04-16 11:08:41 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-04-19 10:45:37 (GMT) |
commit | bae6e6298a617b801a15cbdba13d6759d8b44f31 (patch) | |
tree | 8508bd612b8ace3ba25311d2fad181ca5761662a /src/com/isode/stroke/elements | |
parent | 00b0f316b9125031f30151cacdf2dcf217b8fa01 (diff) | |
download | stroke-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')
-rw-r--r-- | src/com/isode/stroke/elements/Presence.java | 53 | ||||
-rw-r--r-- | src/com/isode/stroke/elements/Stanza.java | 70 |
2 files changed, 123 insertions, 0 deletions
diff --git a/src/com/isode/stroke/elements/Presence.java b/src/com/isode/stroke/elements/Presence.java index acf0a40..392573f 100644 --- a/src/com/isode/stroke/elements/Presence.java +++ b/src/com/isode/stroke/elements/Presence.java @@ -8,28 +8,61 @@ */ package com.isode.stroke.elements; +/** + * Class representing Presence stanza + * + */ public class Presence extends Stanza { private Type type_; + /** + * Presence Stanza Type + * + */ public enum Type { Available, Error, Probe, Subscribe, Subscribed, Unavailable, Unsubscribe, Unsubscribed }; + /** + * Create the Presence object + */ public Presence() { type_ = Type.Available; } + + /** + * Create a Presence object from the specified object by + * creating a copy + * @param copy presence object to be copied, not null + */ + public Presence(Presence copy) { + super(copy); + this.type_ = copy.type_; + } + /** + * Create the Presence object using the status string + * @param status status string, not null + */ public Presence(String status) { type_ = Type.Available; setStatus(status); } + /** + * Get the Presence Stanza type + * @return presence type, not null + */ public Type getType() { return type_; } + /** + * Set the Presence stanza type + * @param type stanza type, not null + */ public void setType(Type type) { type_ = type; } @@ -42,10 +75,18 @@ public class Presence extends Stanza { return type_ == Type.Available ? StatusShow.Type.Online : StatusShow.Type.None; } + /** + * Set the show status type + * @param show status type, not null + */ public void setShow(StatusShow.Type show) { updatePayload(new StatusShow(show)); } + /** + * Get the status message + * @return status message, not null but can be empty + */ public String getStatus() { Status status = getPayload(new Status()); if (status != null) { @@ -54,15 +95,27 @@ public class Presence extends Stanza { return ""; } + /** + * Set the status string + * @param status status string, not null + */ public void setStatus(String status) { updatePayload(new Status(status)); } + /** + * Get the priority of presence stanza + * @return priority of presence stanza + */ public int getPriority() { Priority priority = getPayload(new Priority()); return (priority != null ? priority.getPriority() : 0); } + /** + * Set the priority of presence message. + * @param priority priority value (allowed values -127 to 128) + */ public void setPriority(int priority) { updatePayload(new Priority(priority)); } 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; } |