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

http://mobicents.googlecode.com/ · Java · 140 lines · 74 code · 18 blank · 48 comment · 7 complexity · b73b48d1670161294a22fb0330ef88b6 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 the last number of messages sent from a certain ESME. Relevant
  30. * inherited fields from SMPPPacket: <br>
  31. * <ul>
  32. * source <br>
  33. * </ul>
  34. *
  35. * @version $Id: QueryLastMsgs.java 457 2009-01-15 17:37:42Z orank $
  36. */
  37. public class QueryLastMsgs extends SMPPPacket {
  38. private static final long serialVersionUID = 2L;
  39. /**
  40. * The source address for which to query messages. The last <code>
  41. * msgCount</code> messages originating from this source address will
  42. * be retrieved.
  43. */
  44. private Address source;
  45. /**
  46. * Number of messages to look up.
  47. */
  48. private int msgCount;
  49. /**
  50. * Construct a new QueryLastMsgs.
  51. */
  52. public QueryLastMsgs() {
  53. super(CommandId.QUERY_LAST_MSGS);
  54. }
  55. public Address getSource() {
  56. return source;
  57. }
  58. public void setSource(Address source) {
  59. this.source = source;
  60. }
  61. public int getMsgCount() {
  62. return msgCount;
  63. }
  64. /**
  65. * Set the number of messages to query. <code>msgCount</code> must be
  66. * between 1 and 100 inclusive. Attempts to set a value less than 1 will
  67. * force the value to 1. Attempts to set a value greater than 100 will
  68. * force the value to 100.
  69. * @param msgCount The number of messages to query from the SMSC.
  70. */
  71. public void setMsgCount(int msgCount) {
  72. if (msgCount < 1) {
  73. this.msgCount = 1;
  74. } else if (msgCount > 100) {
  75. this.msgCount = 100;
  76. } else {
  77. this.msgCount = msgCount;
  78. }
  79. }
  80. @Override
  81. public boolean equals(Object obj) {
  82. boolean equals = super.equals(obj);
  83. if (equals) {
  84. QueryLastMsgs other = (QueryLastMsgs) obj;
  85. equals |= safeCompare(source, other.source);
  86. equals |= msgCount == other.msgCount;
  87. }
  88. return equals;
  89. }
  90. @Override
  91. public int hashCode() {
  92. int hc = super.hashCode();
  93. hc += (source != null) ? source.hashCode() : 0;
  94. hc += Integer.valueOf(msgCount).hashCode();
  95. return hc;
  96. }
  97. @Override
  98. protected void toString(StringBuilder buffer) {
  99. buffer.append("source=").append(source)
  100. .append("msgCount=").append(msgCount);
  101. }
  102. @Override
  103. protected void validateMandatory(SMPPVersion smppVersion) {
  104. smppVersion.validateAddress(source);
  105. }
  106. @Override
  107. protected void readMandatory(PacketDecoder decoder) {
  108. source = decoder.readAddress();
  109. msgCount = decoder.readUInt1();
  110. }
  111. @Override
  112. protected void writeMandatory(PacketEncoder encoder) throws IOException {
  113. encoder.writeAddress(source);
  114. encoder.writeUInt1(msgCount);
  115. }
  116. @Override
  117. protected int getMandatorySize() {
  118. int length = 1;
  119. length += sizeOf(source);
  120. return length;
  121. }
  122. }