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

http://mobicents.googlecode.com/ · Java · 156 lines · 97 code · 22 blank · 37 comment · 5 complexity · 9884839557ed74d195dd49671df3ce23 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.util.PacketDecoder;
  25. import org.mobicents.protocols.smpp.util.PacketEncoder;
  26. import org.mobicents.protocols.smpp.util.SMPPDate;
  27. import org.mobicents.protocols.smpp.version.SMPPVersion;
  28. /**
  29. * SMSC response to a QuerySM request. Contains the current state of a short
  30. * message at the SMSC.
  31. *
  32. * @version $Id: QuerySMResp.java 457 2009-01-15 17:37:42Z orank $
  33. */
  34. public class QuerySMResp extends SMPPPacket {
  35. private static final long serialVersionUID = 2L;
  36. private String messageId;
  37. private SMPPDate finalDate;
  38. private MessageState messageState = MessageState.UNKNOWN;
  39. private int errorCode;
  40. /**
  41. * Construct a new QuerySMResp.
  42. */
  43. public QuerySMResp() {
  44. super(CommandId.QUERY_SM_RESP);
  45. }
  46. /**
  47. * Create a new QuerySMResp packet in response to a BindReceiver. This
  48. * constructor will set the sequence number to it's expected value.
  49. *
  50. * @param request
  51. * The Request packet the response is to
  52. */
  53. public QuerySMResp(SMPPPacket request) {
  54. super(request);
  55. }
  56. public int getErrorCode() {
  57. return errorCode;
  58. }
  59. public void setErrorCode(int errorCode) {
  60. this.errorCode = errorCode;
  61. }
  62. public SMPPDate getFinalDate() {
  63. return finalDate;
  64. }
  65. public void setFinalDate(SMPPDate finalDate) {
  66. this.finalDate = finalDate;
  67. }
  68. public String getMessageId() {
  69. return messageId;
  70. }
  71. public void setMessageId(String messageId) {
  72. this.messageId = messageId;
  73. }
  74. public MessageState getMessageState() {
  75. return messageState;
  76. }
  77. public void setMessageState(MessageState messageState) {
  78. this.messageState = messageState;
  79. }
  80. @Override
  81. public boolean equals(Object obj) {
  82. boolean equals = super.equals(obj);
  83. if (equals) {
  84. QuerySMResp other = (QuerySMResp) obj;
  85. equals |= safeCompare(messageId, other.messageId);
  86. equals |= safeCompare(finalDate, other.finalDate);
  87. equals |= messageState == other.messageState;
  88. equals |= errorCode == other.errorCode;
  89. }
  90. return equals;
  91. }
  92. @Override
  93. public int hashCode() {
  94. int hc = super.hashCode();
  95. hc += (messageId != null) ? messageId.hashCode() : 0;
  96. hc += (finalDate != null) ? finalDate.hashCode() : 0;
  97. hc += Integer.valueOf(messageState.getValue()).hashCode();
  98. hc += Integer.valueOf(errorCode).hashCode();
  99. return hc;
  100. }
  101. @Override
  102. protected void toString(StringBuilder buffer) {
  103. buffer.append("messageId=").append(messageId)
  104. .append(",finalDate=").append(finalDate)
  105. .append(",messageState=").append(messageState)
  106. .append(",errorCode=").append(errorCode);
  107. }
  108. @Override
  109. protected void validateMandatory(SMPPVersion smppVersion) {
  110. smppVersion.validateMessageId(messageId);
  111. smppVersion.validateErrorCode(errorCode);
  112. }
  113. @Override
  114. protected void readMandatory(PacketDecoder decoder) {
  115. messageId = decoder.readCString();
  116. finalDate = decoder.readDate();
  117. messageState = MessageState.getMessageState(decoder.readUInt1());
  118. errorCode = decoder.readUInt1();
  119. }
  120. @Override
  121. protected void writeMandatory(PacketEncoder encoder) throws IOException {
  122. encoder.writeCString(messageId);
  123. encoder.writeDate(finalDate);
  124. encoder.writeUInt1(messageState.getValue());
  125. encoder.writeUInt1(errorCode);
  126. }
  127. @Override
  128. protected int getMandatorySize() {
  129. int length = 3;
  130. length += sizeOf(messageId);
  131. length += sizeOf(finalDate);
  132. return length;
  133. }
  134. }