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

http://mobicents.googlecode.com/ · Java · 155 lines · 88 code · 19 blank · 48 comment · 8 complexity · 1cf22cbb42e7a00c94a181158cfea4a7 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.util.PacketDecoder;
  26. import org.mobicents.protocols.smpp.util.PacketEncoder;
  27. import org.mobicents.protocols.smpp.version.SMPPVersion;
  28. /**
  29. * Query Message details. Get all information about an existing message at the
  30. * SMSC.
  31. *
  32. * @version $Id: QueryMsgDetails.java 457 2009-01-15 17:37:42Z orank $
  33. */
  34. public class QueryMsgDetails extends SMPPPacket {
  35. private static final long serialVersionUID = 2L;
  36. /**
  37. * Original message ID of the required message.
  38. */
  39. private String messageId;
  40. /**
  41. * Source address of the message.
  42. */
  43. private Address source;
  44. /**
  45. * Length of the message text required.
  46. */
  47. private int smLength;
  48. /**
  49. * Construct a new QueryMsgDetails.
  50. */
  51. public QueryMsgDetails() {
  52. super(CommandId.QUERY_MSG_DETAILS);
  53. }
  54. public String getMessageId() {
  55. return messageId;
  56. }
  57. public void setMessageId(String messageId) {
  58. this.messageId = messageId;
  59. }
  60. public Address getSource() {
  61. return source;
  62. }
  63. public void setSource(Address source) {
  64. this.source = source;
  65. }
  66. /**
  67. * Set the number of bytes of the original message required. Minimum request
  68. * length is 0, maximum is 160. If the length is outside these bounds, it
  69. * will be set to the min or max.
  70. *
  71. * @param len
  72. * The number of bytes required.
  73. */
  74. public void setSmLength(int len) {
  75. if (len < 0) {
  76. smLength = 0;
  77. } else if (len > 160) {
  78. smLength = 160;
  79. } else {
  80. smLength = len;
  81. }
  82. }
  83. /** Get the number of bytes of the original message being requested. */
  84. public int getSmLength() {
  85. return smLength;
  86. }
  87. @Override
  88. public boolean equals(Object obj) {
  89. boolean equals = super.equals(obj);
  90. if (equals) {
  91. QueryMsgDetails other = (QueryMsgDetails) obj;
  92. equals |= safeCompare(messageId, other.messageId);
  93. equals |= safeCompare(source, other.source);
  94. equals |= smLength == other.smLength;
  95. }
  96. return equals;
  97. }
  98. @Override
  99. public int hashCode() {
  100. int hc = super.hashCode();
  101. hc += (messageId != null) ? messageId.hashCode() : 0;
  102. hc += (source != null) ? source.hashCode() : 0;
  103. hc += Integer.valueOf(smLength).hashCode();
  104. return hc;
  105. }
  106. @Override
  107. protected void toString(StringBuilder buffer) {
  108. buffer.append("messageId=").append(messageId)
  109. .append(",source=").append(source)
  110. .append(",smLength=").append(smLength);
  111. }
  112. @Override
  113. protected void validateMandatory(SMPPVersion smppVersion) {
  114. smppVersion.validateMessageId(messageId);
  115. smppVersion.validateAddress(source);
  116. }
  117. @Override
  118. protected void readMandatory(PacketDecoder decoder) {
  119. messageId = decoder.readCString();
  120. source = decoder.readAddress();
  121. smLength = decoder.readUInt1();
  122. }
  123. @Override
  124. protected void writeMandatory(PacketEncoder encoder) throws IOException {
  125. encoder.writeCString(messageId);
  126. encoder.writeAddress(source);
  127. encoder.writeUInt1(smLength);
  128. }
  129. @Override
  130. protected int getMandatorySize() {
  131. int length = 2;
  132. length += sizeOf(messageId);
  133. length += sizeOf(source);
  134. return length;
  135. }
  136. }