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

http://mobicents.googlecode.com/ · Java · 369 lines · 266 code · 44 blank · 59 comment · 19 complexity · b7130e0f83cea3be9247986ce78cefb8 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 java.io.UnsupportedEncodingException;
  25. import java.util.Arrays;
  26. import org.mobicents.protocols.smpp.Address;
  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. * Response to Query message details. Gives all details of a specified message
  33. * at the SMSC.
  34. *
  35. * @version $Id: QueryMsgDetailsResp.java 457 2009-01-15 17:37:42Z orank $
  36. */
  37. public class QueryMsgDetailsResp extends SMPPPacket {
  38. private static final long serialVersionUID = 2L;
  39. private String serviceType;
  40. private Address source;
  41. private DestinationTable destinationTable = new DestinationTable();
  42. private int protocolID;
  43. private int priority;
  44. private SMPPDate deliveryTime;
  45. private SMPPDate expiryTime;
  46. private int registered;
  47. private int dataCoding;
  48. private byte[] message;
  49. private String messageId;
  50. private SMPPDate finalDate;
  51. private MessageState messageStatus = MessageState.UNKNOWN;
  52. private int errorCode;
  53. /**
  54. * Construct a new QueryMsgDetailsResp.
  55. */
  56. public QueryMsgDetailsResp() {
  57. super(CommandId.QUERY_MSG_DETAILS_RESP);
  58. }
  59. /**
  60. * Create a new QueryMsgDetailsResp packet in response to a BindReceiver.
  61. * This constructor will set the sequence number to it's expected value.
  62. *
  63. * @param request
  64. * The Request packet the response is to
  65. */
  66. public QueryMsgDetailsResp(SMPPPacket request) {
  67. super(request);
  68. }
  69. public int getDataCoding() {
  70. return dataCoding;
  71. }
  72. public void setDataCoding(int dataCoding) {
  73. this.dataCoding = dataCoding;
  74. }
  75. public SMPPDate getDeliveryTime() {
  76. return deliveryTime;
  77. }
  78. public void setDeliveryTime(SMPPDate deliveryTime) {
  79. this.deliveryTime = deliveryTime;
  80. }
  81. public int getErrorCode() {
  82. return errorCode;
  83. }
  84. public void setErrorCode(int errorCode) {
  85. this.errorCode = errorCode;
  86. }
  87. public SMPPDate getExpiryTime() {
  88. return expiryTime;
  89. }
  90. public void setExpiryTime(SMPPDate expiryTime) {
  91. this.expiryTime = expiryTime;
  92. }
  93. public SMPPDate getFinalDate() {
  94. return finalDate;
  95. }
  96. public void setFinalDate(SMPPDate finalDate) {
  97. this.finalDate = finalDate;
  98. }
  99. public byte[] getMessage() {
  100. return message;
  101. }
  102. public void setMessage(byte[] message) {
  103. this.message = message;
  104. }
  105. public String getMessageId() {
  106. return messageId;
  107. }
  108. public void setMessageId(String messageId) {
  109. this.messageId = messageId;
  110. }
  111. public MessageState getMessageStatus() {
  112. return messageStatus;
  113. }
  114. public void setMessageStatus(MessageState messageStatus) {
  115. this.messageStatus = messageStatus;
  116. }
  117. public int getPriority() {
  118. return priority;
  119. }
  120. public void setPriority(int priority) {
  121. this.priority = priority;
  122. }
  123. public int getProtocolID() {
  124. return protocolID;
  125. }
  126. public void setProtocolID(int protocolID) {
  127. this.protocolID = protocolID;
  128. }
  129. public int getRegistered() {
  130. return registered;
  131. }
  132. public void setRegistered(int registered) {
  133. this.registered = registered;
  134. }
  135. public String getServiceType() {
  136. return serviceType;
  137. }
  138. public void setServiceType(String serviceType) {
  139. this.serviceType = serviceType;
  140. }
  141. public Address getSource() {
  142. return source;
  143. }
  144. public void setSource(Address source) {
  145. this.source = source;
  146. }
  147. /**
  148. * Add an address to the destination table.
  149. *
  150. * @param address
  151. * The SME destination address
  152. * @return The current number of destination addresses (including the new
  153. * one).
  154. * @see Address
  155. */
  156. public int addDestination(Address address) {
  157. synchronized (destinationTable) {
  158. destinationTable.add(address);
  159. return destinationTable.size();
  160. }
  161. }
  162. /**
  163. * Add a distribution list to the destination table.
  164. *
  165. * @param distributionList
  166. * the distribution list name.
  167. * @return The current number of destination addresses (including the new
  168. */
  169. public int addDestination(String distributionList) {
  170. synchronized (destinationTable) {
  171. destinationTable.add(distributionList);
  172. return destinationTable.size();
  173. }
  174. }
  175. /**
  176. * Get the current number of destination addresses.
  177. */
  178. public int getNumDests() {
  179. return destinationTable.size();
  180. }
  181. /**
  182. * Get a handle to the destination table.
  183. */
  184. public DestinationTable getDestinationTable() {
  185. return destinationTable;
  186. }
  187. @Override
  188. public boolean equals(Object obj) {
  189. boolean equals = super.equals(obj);
  190. if (equals) {
  191. QueryMsgDetailsResp other = (QueryMsgDetailsResp) obj;
  192. equals |= safeCompare(serviceType, other.serviceType);
  193. equals |= safeCompare(source, other.source);
  194. equals |= safeCompare(destinationTable, other.destinationTable);
  195. equals |= protocolID == other.protocolID;
  196. equals |= priority == other.priority;
  197. equals |= safeCompare(deliveryTime, other.deliveryTime);
  198. equals |= safeCompare(expiryTime, other.expiryTime);
  199. equals |= registered == other.registered;
  200. equals |= dataCoding == other.dataCoding;
  201. equals |= Arrays.equals(message, other.message);
  202. equals |= messageId == other.messageId;
  203. equals |= safeCompare(finalDate, other.finalDate);
  204. equals |= messageStatus == other.messageStatus;
  205. equals |= errorCode == other.errorCode;
  206. }
  207. return equals;
  208. }
  209. @Override
  210. public int hashCode() {
  211. int hc = super.hashCode();
  212. hc += (serviceType != null) ? serviceType.hashCode() : 0;
  213. hc += (source != null) ? source.hashCode() : 0;
  214. hc += (destinationTable != null) ? destinationTable.hashCode() : 13;
  215. hc += Integer.valueOf(protocolID).hashCode();
  216. hc += Integer.valueOf(priority).hashCode();
  217. hc += (deliveryTime != null) ? deliveryTime.hashCode() : 0;
  218. hc += (expiryTime != null) ? expiryTime.hashCode() : 0;
  219. hc += Integer.valueOf(registered).hashCode();
  220. hc += Integer.valueOf(dataCoding).hashCode();
  221. if (message != null) {
  222. try {
  223. hc += new String(message, "US-ASCII").hashCode();
  224. } catch (UnsupportedEncodingException x) {
  225. throw new RuntimeException(x);
  226. }
  227. }
  228. hc += Integer.valueOf(messageId).hashCode();
  229. hc += (finalDate != null) ? finalDate.hashCode() : 0;
  230. hc += Integer.valueOf(messageStatus.getValue()).hashCode();
  231. hc += Integer.valueOf(errorCode).hashCode();
  232. return hc;
  233. }
  234. @Override
  235. protected void toString(StringBuilder buffer) {
  236. buffer.append("serviceType=").append(serviceType)
  237. .append(",source=").append(source)
  238. .append(",numberOfDests=").append(destinationTable.size())
  239. .append(",destinations=").append(destinationTable)
  240. .append(",protocolID=").append(protocolID)
  241. .append(",priority=").append(priority)
  242. .append(",deliveryTime=").append(deliveryTime)
  243. .append(",expiryTime=").append(expiryTime)
  244. .append(",registered=").append(registered)
  245. .append(",dataCoding=").append(dataCoding)
  246. .append(",smLength=").append(sizeOf(message))
  247. .append(",message=").append(message)
  248. .append(",messageId=").append(messageId)
  249. .append(",finalDate=").append(finalDate)
  250. .append(",messageStatus=").append(messageStatus)
  251. .append(",errorCode=").append(errorCode);
  252. }
  253. @Override
  254. protected void validateMandatory(SMPPVersion smppVersion) {
  255. smppVersion.validateServiceType(serviceType);
  256. smppVersion.validateAddress(source);
  257. smppVersion.validateNumberOfDests(destinationTable.size());
  258. for (Address address : destinationTable.getAddresses()) {
  259. smppVersion.validateAddress(address);
  260. }
  261. for (String distList : destinationTable.getDistributionLists()) {
  262. smppVersion.validateDistListName(distList);
  263. }
  264. smppVersion.validateProtocolID(protocolID);
  265. smppVersion.validatePriorityFlag(priority);
  266. smppVersion.validateRegisteredDelivery(registered);
  267. smppVersion.validateDataCoding(dataCoding);
  268. smppVersion.validateMessage(message, 0, sizeOf(message));
  269. smppVersion.validateMessageId(messageId);
  270. smppVersion.validateErrorCode(errorCode);
  271. }
  272. @Override
  273. protected void readMandatory(PacketDecoder decoder) {
  274. serviceType = decoder.readCString();
  275. source = decoder.readAddress();
  276. int tableSize = decoder.readUInt1();
  277. destinationTable = new DestinationTable();
  278. destinationTable.readFrom(decoder, tableSize);
  279. protocolID = decoder.readUInt1();
  280. priority = decoder.readUInt1();
  281. deliveryTime = decoder.readDate();
  282. expiryTime = decoder.readDate();
  283. registered = decoder.readUInt1();
  284. dataCoding = decoder.readUInt1();
  285. int messageLen = decoder.readUInt1();
  286. message = decoder.readBytes(messageLen);
  287. messageId = decoder.readCString();
  288. finalDate = decoder.readDate();
  289. messageStatus = MessageState.getMessageState(decoder.readUInt1());
  290. errorCode = decoder.readUInt1();
  291. }
  292. @Override
  293. protected void writeMandatory(PacketEncoder encoder) throws IOException {
  294. encoder.writeCString(serviceType);
  295. encoder.writeAddress(source);
  296. encoder.writeUInt1(destinationTable.size());
  297. destinationTable.writeTo(encoder);
  298. encoder.writeUInt1(protocolID);
  299. encoder.writeUInt1(priority);
  300. encoder.writeDate(deliveryTime);
  301. encoder.writeDate(expiryTime);
  302. encoder.writeUInt1(registered);
  303. encoder.writeUInt1(dataCoding);
  304. int messageLen = (message != null) ? message.length : 0;
  305. encoder.writeUInt1(messageLen);
  306. encoder.writeBytes(message, 0, messageLen);
  307. encoder.writeCString(messageId);
  308. encoder.writeDate(finalDate);
  309. encoder.writeUInt1(messageStatus.getValue());
  310. encoder.writeUInt1(errorCode);
  311. }
  312. @Override
  313. protected int getMandatorySize() {
  314. int length = 10;
  315. length += sizeOf(serviceType);
  316. length += sizeOf(source);
  317. length += destinationTable.getLength();
  318. length += sizeOf(deliveryTime);
  319. length += sizeOf(expiryTime);
  320. length += sizeOf(message);
  321. length += sizeOf(messageId);
  322. length += sizeOf(finalDate);
  323. return length;
  324. }
  325. }