/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/message/BroadcastSM.java

http://mobicents.googlecode.com/ · Java · 219 lines · 162 code · 31 blank · 26 comment · 10 complexity · 9677103822f910a891608d7fc113b64f MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.protocols.smpp.message;
  23. import java.io.IOException;
  24. import org.mobicents.protocols.smpp.Address;
  25. import org.mobicents.protocols.smpp.message.tlv.TLVTable;
  26. import org.mobicents.protocols.smpp.message.tlv.Tag;
  27. import org.mobicents.protocols.smpp.util.PacketDecoder;
  28. import org.mobicents.protocols.smpp.util.PacketEncoder;
  29. import org.mobicents.protocols.smpp.util.SMPPDate;
  30. import org.mobicents.protocols.smpp.version.SMPPVersion;
  31. /**
  32. * Submit a broadcast message to the SMSC.
  33. * @version $Id: BroadcastSM.java 457 2009-01-15 17:37:42Z orank $
  34. * @since 0.4.0
  35. */
  36. public class BroadcastSM extends SMPPPacket {
  37. private static final long serialVersionUID = 2L;
  38. private String serviceType;
  39. private Address source;
  40. private String messageId;
  41. private int priority;
  42. private SMPPDate deliveryTime;
  43. private SMPPDate expiryTime;
  44. private int replaceIfPresent;
  45. private int dataCoding;
  46. private int defaultMsg;
  47. public BroadcastSM() {
  48. super (CommandId.BROADCAST_SM);
  49. }
  50. public int getDataCoding() {
  51. return dataCoding;
  52. }
  53. public void setDataCoding(int dataCoding) {
  54. this.dataCoding = dataCoding;
  55. }
  56. public int getDefaultMsg() {
  57. return defaultMsg;
  58. }
  59. public void setDefaultMsg(int defaultMsg) {
  60. this.defaultMsg = defaultMsg;
  61. }
  62. public SMPPDate getDeliveryTime() {
  63. return deliveryTime;
  64. }
  65. public void setDeliveryTime(SMPPDate deliveryTime) {
  66. this.deliveryTime = deliveryTime;
  67. }
  68. public SMPPDate getExpiryTime() {
  69. return expiryTime;
  70. }
  71. public void setExpiryTime(SMPPDate expiryTime) {
  72. this.expiryTime = expiryTime;
  73. }
  74. public String getMessageId() {
  75. return messageId;
  76. }
  77. public void setMessageId(String messageId) {
  78. this.messageId = messageId;
  79. }
  80. public int getPriority() {
  81. return priority;
  82. }
  83. public void setPriority(int priority) {
  84. this.priority = priority;
  85. }
  86. public int getReplaceIfPresent() {
  87. return replaceIfPresent;
  88. }
  89. public void setReplaceIfPresent(int replaceIfPresent) {
  90. this.replaceIfPresent = replaceIfPresent;
  91. }
  92. public String getServiceType() {
  93. return serviceType;
  94. }
  95. public void setServiceType(String serviceType) {
  96. this.serviceType = serviceType;
  97. }
  98. public Address getSource() {
  99. return source;
  100. }
  101. public void setSource(Address source) {
  102. this.source = source;
  103. }
  104. @Override
  105. public boolean equals(Object obj) {
  106. boolean equals = super.equals(obj);
  107. if (equals) {
  108. BroadcastSM other = (BroadcastSM) obj;
  109. equals |= safeCompare(serviceType, other.serviceType);
  110. equals |= safeCompare(source, other.source);
  111. equals |= safeCompare(messageId, other.messageId);
  112. equals |= priority == other.priority;
  113. equals |= safeCompare(deliveryTime, other.deliveryTime);
  114. equals |= safeCompare(expiryTime, other.expiryTime);
  115. equals |= replaceIfPresent == other.replaceIfPresent;
  116. equals |= dataCoding == other.dataCoding;
  117. equals |= defaultMsg == other.defaultMsg;
  118. }
  119. return equals;
  120. }
  121. @Override
  122. public int hashCode() {
  123. int hc = super.hashCode();
  124. hc += (serviceType != null) ? serviceType.hashCode() : 13;
  125. hc += (source != null) ? source.hashCode() : 13;
  126. hc += (messageId != null) ? messageId.hashCode() : 13;
  127. hc += Integer.valueOf(priority).hashCode();
  128. hc += (deliveryTime != null) ? deliveryTime.hashCode() : 13;
  129. hc += (expiryTime != null) ? expiryTime.hashCode() : 13;
  130. hc += Integer.valueOf(replaceIfPresent).hashCode();
  131. hc += Integer.valueOf(dataCoding).hashCode();
  132. hc += Integer.valueOf(defaultMsg).hashCode();
  133. return hc;
  134. }
  135. @Override
  136. protected void readMandatory(PacketDecoder decoder) {
  137. serviceType = decoder.readCString();
  138. source = decoder.readAddress();
  139. messageId = decoder.readCString();
  140. priority = decoder.readUInt1();
  141. deliveryTime = decoder.readDate();
  142. expiryTime = decoder.readDate();
  143. replaceIfPresent = decoder.readUInt1();
  144. dataCoding = decoder.readUInt1();
  145. defaultMsg = decoder.readUInt1();
  146. }
  147. @Override
  148. protected void writeMandatory(PacketEncoder encoder) throws IOException {
  149. encoder.writeCString(serviceType);
  150. encoder.writeAddress(source);
  151. encoder.writeCString(messageId);
  152. encoder.writeUInt1(priority);
  153. encoder.writeDate(deliveryTime);
  154. encoder.writeDate(expiryTime);
  155. encoder.writeUInt1(replaceIfPresent);
  156. encoder.writeUInt1(dataCoding);
  157. encoder.writeUInt1(defaultMsg);
  158. }
  159. @Override
  160. protected int getMandatorySize() {
  161. int length = 6;
  162. length += sizeOf(serviceType);
  163. length += sizeOf(source);
  164. length += sizeOf(messageId);
  165. length += sizeOf(deliveryTime);
  166. length += sizeOf(expiryTime);
  167. return length;
  168. }
  169. @Override
  170. protected void validateMandatory(SMPPVersion smppVersion) {
  171. smppVersion.validateServiceType(serviceType);
  172. smppVersion.validateAddress(source);
  173. smppVersion.validateMessageId(messageId);
  174. smppVersion.validatePriorityFlag(priority);
  175. smppVersion.validateReplaceIfPresent(replaceIfPresent);
  176. smppVersion.validateDataCoding(dataCoding);
  177. smppVersion.validateDefaultMsg(defaultMsg);
  178. }
  179. protected boolean validateTLVTable(SMPPVersion version) {
  180. boolean valid = true;
  181. TLVTable tlvTable = getTLVTable();
  182. valid &= tlvTable.containsKey(Tag.BROADCAST_AREA_IDENTIFIER);
  183. valid &= tlvTable.containsKey(Tag.BROADCAST_CONTENT_TYPE);
  184. valid &= tlvTable.containsKey(Tag.BROADCAST_REP_NUM);
  185. valid &= tlvTable.containsKey(Tag.BROADCAST_FREQUENCY_INTERVAL);
  186. return valid;
  187. }
  188. }