PageRenderTime 101ms CodeModel.GetById 83ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/version/AbstractSMPPVersion.java

http://mobicents.googlecode.com/
Java | 216 lines | 141 code | 32 blank | 43 comment | 51 complexity | 1c86619708593a56b263042891d2dc23 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  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.version;
  23. import org.mobicents.protocols.smpp.Address;
  24. /**
  25. * Class representing an SMPP protocol version. Instances of this object are
  26. * used by the rest of the API to determine is an SMPP message is supported by a
  27. * certain version of the protocol.
  28. * @version $Id: AbstractSMPPVersion.java 452 2009-01-15 16:56:36Z orank $
  29. */
  30. public abstract class AbstractSMPPVersion implements SMPPVersion {
  31. private static final long serialVersionUID = 2L;
  32. /**
  33. * Integer representing this version number. The SMPP specification states
  34. * integer values that represent protocol revisions. These values are used
  35. * mainly in the bind_* and bind response messages. Integer value 0x33
  36. * represents version 3.3 of the protocol, integer value 0x34 represents
  37. * version 3.4...it's assumed further major and minor revisions of the SMPP
  38. * specification will continue this numbering scheme.
  39. */
  40. private int versionID;
  41. /**
  42. * Descriptive text for this protocol version. This value is used only to
  43. * return a representative string from toString.
  44. */
  45. private String versionString;
  46. /**
  47. * Create a new SMPPVersion object.
  48. */
  49. protected AbstractSMPPVersion(int versionID, String versionString) {
  50. this.versionID = versionID;
  51. this.versionString = versionString;
  52. }
  53. public int getVersionID() {
  54. return versionID;
  55. }
  56. public boolean isOlderThan(SMPPVersion otherVersion) {
  57. return versionID < otherVersion.getVersionID();
  58. }
  59. public boolean isNewerThan(SMPPVersion otherVersion) {
  60. return versionID > otherVersion.getVersionID();
  61. }
  62. public boolean equals(Object obj) {
  63. if (this == obj) {
  64. return true;
  65. }
  66. if (obj == null || !(obj instanceof SMPPVersion)) {
  67. return false;
  68. } else {
  69. return ((SMPPVersion) obj).getVersionID() == versionID;
  70. }
  71. }
  72. public int hashCode() {
  73. return new Integer(versionID).hashCode();
  74. }
  75. public boolean equals(int versionID) {
  76. return versionID == this.versionID;
  77. }
  78. public String toString() {
  79. return versionString;
  80. }
  81. public void validateTon(int ton) {
  82. if (ton < 0 || ton > 0xff) {
  83. throw new VersionException("Invalid TON: " + ton);
  84. }
  85. }
  86. public void validateNpi(int npi) {
  87. if (npi < 0 || npi > 0xff) {
  88. throw new VersionException("Invalid NPI: " + npi);
  89. }
  90. }
  91. public void validateAddress(Address address) {
  92. if (address != null) {
  93. validateTon(address.getTON());
  94. validateNpi(address.getNPI());
  95. String addr = address.getAddress();
  96. if (addr != null && addr.length() > 20) {
  97. throw new VersionException("Address is too long, 20 max: " + addr);
  98. }
  99. }
  100. }
  101. public void validateEsmClass(int esmClass) {
  102. if (esmClass < 0 || esmClass > 0xff) {
  103. throw new VersionException("Invalid ESM class: " + esmClass);
  104. }
  105. }
  106. public void validateProtocolID(int protocolId) {
  107. if (protocolId < 0 || protocolId > 0xff) {
  108. throw new VersionException("Invalid protocol ID: " + protocolId);
  109. }
  110. }
  111. public void validateDataCoding(int dataCoding) {
  112. if (dataCoding < 0 || dataCoding > 0xff) {
  113. throw new VersionException("Invalid data coding: " + dataCoding);
  114. }
  115. }
  116. public void validateDefaultMsg(int defaultMsgId) {
  117. if (defaultMsgId < 0 || defaultMsgId > 0xff) {
  118. throw new VersionException(
  119. "Invalid default message ID: " + defaultMsgId);
  120. }
  121. }
  122. public void validateServiceType(String serviceType) {
  123. if (serviceType != null && serviceType.length() > 5) {
  124. throw new VersionException("Invalid service type: " + serviceType);
  125. }
  126. }
  127. public void validateMessageState(int messageState) {
  128. if (messageState < 0 || messageState > 0xff) {
  129. throw new VersionException(
  130. "Invalid message state: " + messageState);
  131. }
  132. }
  133. public void validateErrorCode(int code) {
  134. if (code < 0 || code > 0xff) {
  135. throw new VersionException("Invalid error code: " + code);
  136. }
  137. }
  138. public void validateReplaceIfPresent(int flag) {
  139. if (flag < 0 || flag > 1) {
  140. throw new VersionException(
  141. "Replace-if-present flag must be 0 or 1: " + flag);
  142. }
  143. }
  144. public void validateNumUnsuccessful(int num) {
  145. if (num < 0 || num > 0xff) {
  146. throw new VersionException(
  147. "Invalid number of unsuccessful destinations: " + num);
  148. }
  149. }
  150. public void validateDistListName(String name) {
  151. if (name != null && name.length() > 20) {
  152. throw new VersionException(
  153. "Distribution list name too long: " + name);
  154. }
  155. }
  156. public void validateSystemId(String sysId) {
  157. if (sysId != null && sysId.length() > 15) {
  158. throw new VersionException("System ID too long: " + sysId);
  159. }
  160. }
  161. public void validatePassword(String password) {
  162. if (password != null && password.length() > 8) {
  163. throw new VersionException("Password too long");
  164. }
  165. }
  166. public void validateSystemType(String sysType) {
  167. if (sysType != null && sysType.length() > 12) {
  168. throw new VersionException("System type too long: " + sysType);
  169. }
  170. }
  171. public void validateAddressRange(String addressRange) {
  172. // Possibly add some checks for allowed characters??
  173. if (addressRange != null && addressRange.length() > 40) {
  174. throw new VersionException(
  175. "Address range too long: " + addressRange);
  176. }
  177. }
  178. public void validateParamName(String paramName) {
  179. throw new VersionException("Parameter retrieval is not supported.");
  180. }
  181. public void validateParamValue(String paramValue) {
  182. throw new VersionException("Parameter retrieval is not supported.");
  183. }
  184. }