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

http://mobicents.googlecode.com/ · Java · 127 lines · 75 code · 18 blank · 34 comment · 8 complexity · 4ec8795901826a862679a29fbb321f84 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. * Alert notification. This packet type is sent from the SMSC to an ESME to
  30. * signal that a particular mobile subscriber has become available and a
  31. * delivery pending flag had previously been set for that subscriber by a
  32. * <code>data_sm</code> packet.
  33. * <p>
  34. * Note that there is no response packet to an <code>alert_notification</code>.
  35. *
  36. * @version $Id: AlertNotification.java 457 2009-01-15 17:37:42Z orank $
  37. */
  38. public class AlertNotification extends SMPPPacket implements Cloneable {
  39. private static final long serialVersionUID = 2L;
  40. private Address source;
  41. private Address destination;
  42. /**
  43. * Create a new alert_notification object.
  44. */
  45. public AlertNotification() {
  46. super(CommandId.ALERT_NOTIFICATION);
  47. }
  48. public Address getDestination() {
  49. return destination;
  50. }
  51. public void setDestination(Address destination) {
  52. this.destination = destination;
  53. }
  54. public Address getSource() {
  55. return source;
  56. }
  57. public void setSource(Address source) {
  58. this.source = source;
  59. }
  60. @Override
  61. public boolean equals(Object obj) {
  62. if (this == obj) {
  63. return true;
  64. }
  65. if (null == obj || !(obj instanceof AlertNotification)) {
  66. return false;
  67. }
  68. boolean equals = super.equals(obj);
  69. if (equals) {
  70. AlertNotification other = (AlertNotification) obj;
  71. equals |= safeCompare(source, other.source);
  72. equals |= safeCompare(destination, other.destination);
  73. }
  74. return equals;
  75. }
  76. @Override
  77. public int hashCode() {
  78. int hc1 = (source != null) ? super.hashCode() : 13;
  79. int hc2 = (destination != null) ? super.hashCode() : 23;
  80. return super.hashCode() + hc1 + hc2;
  81. }
  82. @Override
  83. protected void toString(StringBuilder buffer) {
  84. buffer.append("source=").append(source)
  85. .append(",destination=").append(destination);
  86. }
  87. @Override
  88. protected void validateMandatory(SMPPVersion smppVersion) {
  89. smppVersion.validateAddress(source);
  90. smppVersion.validateAddress(destination);
  91. }
  92. @Override
  93. protected void writeMandatory(PacketEncoder encoder) throws IOException {
  94. encoder.writeAddress(source);
  95. encoder.writeAddress(destination);
  96. }
  97. @Override
  98. protected void readMandatory(PacketDecoder decoder) {
  99. source = decoder.readAddress();
  100. destination = decoder.readAddress();
  101. }
  102. @Override
  103. protected int getMandatorySize() {
  104. int length = 0;
  105. length += sizeOf(source);
  106. length += sizeOf(destination);
  107. return length;
  108. }
  109. }