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

http://mobicents.googlecode.com/ · Java · 156 lines · 98 code · 21 blank · 37 comment · 5 complexity · f5a6b1c868fcb56da288e349b589d165 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. * Cancal message. This SMPP message is used to cancel a previously submitted
  30. * but yet undelivered short message at the SMSC. Relevant inherited fields from
  31. * SMPPPacket: <br>
  32. * <ul>
  33. * serviceType <br>
  34. * messageId <br>
  35. * source <br>
  36. * destination <br>
  37. * </ul>
  38. *
  39. * @version $Id: CancelSM.java 457 2009-01-15 17:37:42Z orank $
  40. */
  41. public class CancelSM extends SMPPPacket {
  42. private static final long serialVersionUID = 2L;
  43. private String serviceType;
  44. private String messageId;
  45. private Address source;
  46. private Address destination;
  47. /**
  48. * Construct a new CancelSM.
  49. */
  50. public CancelSM() {
  51. super(CommandId.CANCEL_SM);
  52. }
  53. public Address getDestination() {
  54. return destination;
  55. }
  56. public void setDestination(Address destination) {
  57. this.destination = destination;
  58. }
  59. public String getMessageId() {
  60. return messageId;
  61. }
  62. public void setMessageId(String messageId) {
  63. this.messageId = messageId;
  64. }
  65. public String getServiceType() {
  66. return serviceType;
  67. }
  68. public void setServiceType(String serviceType) {
  69. this.serviceType = serviceType;
  70. }
  71. public Address getSource() {
  72. return source;
  73. }
  74. public void setSource(Address source) {
  75. this.source = source;
  76. }
  77. @Override
  78. public boolean equals(Object obj) {
  79. boolean equals = super.equals(obj);
  80. if (equals) {
  81. CancelSM other = (CancelSM) obj;
  82. equals |= safeCompare(serviceType, other.serviceType);
  83. equals |= safeCompare(messageId, other.messageId);
  84. equals |= safeCompare(source, other.source);
  85. equals |= safeCompare(destination, other.destination);
  86. }
  87. return equals;
  88. }
  89. @Override
  90. public int hashCode() {
  91. int hc = super.hashCode();
  92. hc += (serviceType != null) ? serviceType.hashCode() : 0;
  93. hc += (messageId != null) ? messageId.hashCode() : 0;
  94. hc += (source != null) ? source.hashCode() : 0;
  95. hc += (destination != null) ? destination.hashCode() : 0;
  96. return hc;
  97. }
  98. @Override
  99. protected void toString(StringBuilder buffer) {
  100. buffer.append("serviceType=").append(serviceType)
  101. .append(",messageId=").append(messageId)
  102. .append(",source=").append(source)
  103. .append(",destination=").append(destination);
  104. }
  105. @Override
  106. protected void validateMandatory(SMPPVersion smppVersion) {
  107. smppVersion.validateServiceType(serviceType);
  108. smppVersion.validateMessageId(messageId);
  109. smppVersion.validateAddress(source);
  110. smppVersion.validateAddress(destination);
  111. }
  112. @Override
  113. protected void readMandatory(PacketDecoder decoder) {
  114. serviceType = decoder.readCString();
  115. messageId = decoder.readCString();
  116. source = decoder.readAddress();
  117. destination = decoder.readAddress();
  118. }
  119. @Override
  120. protected void writeMandatory(PacketEncoder encoder) throws IOException {
  121. encoder.writeCString(serviceType);
  122. encoder.writeCString(messageId);
  123. encoder.writeAddress(source);
  124. encoder.writeAddress(destination);
  125. }
  126. @Override
  127. protected int getMandatorySize() {
  128. int length = 2;
  129. length += sizeOf(serviceType);
  130. length += sizeOf(messageId);
  131. length += sizeOf(source);
  132. length += sizeOf(destination);
  133. return length;
  134. }
  135. }