diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-15 22:20:01 (GMT) |
---|---|---|
committer | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-16 19:16:43 (GMT) |
commit | 4addb6419080db814094ab501d69111adffeb5be (patch) | |
tree | d6259ab03817dd9fc0840a32a73aea9457ac4224 /src/com/isode/stroke/elements | |
parent | 88392c931a8987f21caa5fa2e0717b8ce2514948 (diff) | |
download | stroke-4addb6419080db814094ab501d69111adffeb5be.zip stroke-4addb6419080db814094ab501d69111adffeb5be.tar.bz2 |
Add IBB Element.
Adds IBB Element, its Parser and Serializer.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Tests added for both IBB Parser and Serializer, which passes.
Change-Id: I0f2657de89d5395652c62ee5d5a88fbe9acb25e9
Diffstat (limited to 'src/com/isode/stroke/elements')
-rw-r--r-- | src/com/isode/stroke/elements/IBB.java | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/src/com/isode/stroke/elements/IBB.java b/src/com/isode/stroke/elements/IBB.java new file mode 100644 index 0000000..93864da --- /dev/null +++ b/src/com/isode/stroke/elements/IBB.java @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.Payload; +import java.util.Vector; +import com.isode.stroke.base.NotNull; +import com.isode.stroke.base.ByteArray; + +public class IBB extends Payload { + + public enum Action { + Open, + Close, + Data + }; + + public enum StanzaType { + IQStanza, + MessageStanza + }; + + private Action action; + private String streamID = ""; + private ByteArray data = new ByteArray(); + private StanzaType stanzaType; + private int blockSize; + private int sequenceNumber; + + /** + * Default Constructor. + */ + public IBB() { + this(Action.Open, ""); + } + + /** + * Parameterized Constructor + * @param action, NotNull. + */ + public IBB(Action action) { + this(action, ""); + } + + /** + * Parameterized Constructor + * @param streamID, NotNull. + * @param action, NotNull. + */ + public IBB(Action action, String streamID) { + NotNull.exceptIfNull(action, "action"); + NotNull.exceptIfNull(streamID, "streamID"); + this.action = action; + this.streamID = streamID; + this.stanzaType = StanzaType.IQStanza; + this.blockSize = -1; + this.sequenceNumber = -1; + } + + /** + * @param streamID, NotNull. + * @param blockSize. + * @return IBB Object. + */ + public static IBB createIBBOpen(String streamID, int blockSize) { + NotNull.exceptIfNull(streamID, "streamID"); + IBB result = new IBB(Action.Open, streamID); + result.setBlockSize(blockSize); + return result; + } + + /** + * @param streamID, NotNull. + * @param sequenceNumber. + * @param data, NotNull. + * @return IBB Object. + */ + public static IBB createIBBData(String streamID, int sequenceNumber, ByteArray data) { + NotNull.exceptIfNull(streamID, "streamID"); + NotNull.exceptIfNull(data, "data"); + IBB result = new IBB(Action.Data, streamID); + result.setSequenceNumber(sequenceNumber); + result.setData(data); + return result; + } + + + /** + * @param streamID, NotNull. + * @return IBB Object. + */ + public static IBB createIBBClose(String streamID) { + return new IBB(Action.Close, streamID); + } + + /** + * @param action, Not Null. + */ + public void setAction(Action action) { + NotNull.exceptIfNull(action, "action"); + this.action = action; + } + + /** + * @return action, Not Null. + */ + public Action getAction() { + return action; + } + + /** + * @param stanzaType, Not Null. + */ + public void setStanzaType(StanzaType stanzaType) { + NotNull.exceptIfNull(stanzaType, "stanzaType"); + this.stanzaType = stanzaType; + } + + /** + * @return stanzaType, Not Null. + */ + public StanzaType getStanzaType() { + return stanzaType; + } + + /** + * @param id, Not Null. + */ + public void setStreamID(String id) { + NotNull.exceptIfNull(id, "id"); + streamID = id; + } + + /** + * @return id, Not Null. + */ + public String getStreamID() { + return streamID; + } + + /** + * @return data, Not Null. + */ + public ByteArray getData() { + return data; + } + + /** + * @param data, Not Null. + */ + public void setData(ByteArray data) { + NotNull.exceptIfNull(data, "data"); + this.data = data; + } + + /** + * @return blockSize. + */ + public int getBlockSize() { + return blockSize; + } + + /** + * @param blockSize. + */ + public void setBlockSize(int blockSize) { + this.blockSize = blockSize; + } + + /** + * @return sequenceNumber. + */ + public int getSequenceNumber() { + return sequenceNumber; + } + + /** + * @param sequenceNumber. + */ + public void setSequenceNumber(int i) { + sequenceNumber = i; + } +}
\ No newline at end of file |