PageRenderTime 2842ms CodeModel.GetById 2825ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/map/map-api/src/main/java/org/mobicents/protocols/ss7/map/api/MAPApplicationContext.java

http://mobicents.googlecode.com/
Java | 169 lines | 101 code | 27 blank | 41 comment | 34 complexity | a14d8151b632c52fddc62d73581eacf9 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.ss7.map.api;
  23. import java.util.Arrays;
  24. /**
  25. *
  26. * @author amit bhayani
  27. * @author sergey vetyutnev
  28. *
  29. */
  30. public class MAPApplicationContext {
  31. private static long[] oidTemplate = new long[] { 0, 4, 0, 0, 1, 0, 0, 0 };
  32. private MAPApplicationContextName contextName;
  33. private MAPApplicationContextVersion contextVersion;
  34. private MAPApplicationContext(MAPApplicationContextName contextName, MAPApplicationContextVersion contextVersion) {
  35. this.contextName = contextName;
  36. this.contextVersion = contextVersion;
  37. }
  38. public long[] getOID() {
  39. long[] res = Arrays.copyOf(oidTemplate, oidTemplate.length);
  40. res[6] = this.contextName.getApplicationContextCode();
  41. res[7] = this.contextVersion.getVersion();
  42. return res;
  43. }
  44. public MAPApplicationContextName getApplicationContextName() {
  45. return this.contextName;
  46. }
  47. public MAPApplicationContextVersion getApplicationContextVersion() {
  48. return this.contextVersion;
  49. }
  50. public static MAPApplicationContext getInstance(MAPApplicationContextName contextName, MAPApplicationContextVersion contextVersion) {
  51. if (MAPApplicationContext.availableApplicationContextVersion(contextName, contextVersion.getVersion()))
  52. return new MAPApplicationContext(contextName, contextVersion);
  53. else
  54. return null;
  55. }
  56. public static MAPApplicationContext getInstance(long[] oid) {
  57. if (oid == null || oid.length != oidTemplate.length)
  58. return null;
  59. for (int i1 = 0; i1 < oidTemplate.length - 2; i1++) {
  60. if (oid[i1] != oidTemplate[i1])
  61. return null;
  62. }
  63. MAPApplicationContextName contextName = MAPApplicationContextName.getInstance(oid[6]);
  64. MAPApplicationContextVersion contextVersion = MAPApplicationContextVersion.getInstance(oid[7]);
  65. if (contextName == null || contextVersion == null)
  66. return null;
  67. if (!MAPApplicationContext.availableApplicationContextVersion(contextName, (int) oid[7]))
  68. return null;
  69. return new MAPApplicationContext(contextName, contextVersion);
  70. }
  71. /**
  72. * Return if the contextVersion is available for the contextName
  73. *
  74. * @param contextName
  75. * @param version
  76. * @return
  77. */
  78. public static boolean availableApplicationContextVersion(MAPApplicationContextName contextName, int contextVersion) {
  79. switch (contextName) {
  80. case networkUnstructuredSsContext:
  81. case shortMsgAlertContext:
  82. if (contextVersion >= 1 && contextVersion <= 2)
  83. return true;
  84. else
  85. return false;
  86. case shortMsgMORelayContext:
  87. case shortMsgMTRelayContext:
  88. case shortMsgGatewayContext:
  89. if (contextVersion >= 1 && contextVersion <= 3)
  90. return true;
  91. else
  92. return false;
  93. case locationSvcEnquiryContext:
  94. //for locationSvcEnquiryContext only version 3 is supported
  95. if (contextVersion == 3)
  96. return true;
  97. else
  98. return false;
  99. case anyTimeEnquiryContext:
  100. if (contextVersion == 3){
  101. return true;
  102. }
  103. }
  104. return false;
  105. }
  106. /**
  107. * Get ApplicationContext version. If oid is bad 0 will be received
  108. *
  109. * @param oid
  110. * @return
  111. */
  112. public static int getProtocolVersion(long[] oid) {
  113. if (oid == null || oid.length != 8)
  114. return 0;
  115. else
  116. return (int) oid[7];
  117. }
  118. @Override
  119. public boolean equals(Object obj) {
  120. if (obj == null || !(obj instanceof MAPApplicationContext))
  121. return false;
  122. MAPApplicationContext x = (MAPApplicationContext)obj;
  123. if (this.contextName == x.contextName && this.contextVersion == x.contextVersion)
  124. return true;
  125. else
  126. return false;
  127. }
  128. @Override
  129. public String toString() {
  130. StringBuffer s = new StringBuffer();
  131. s.append("MAPApplicationContext [Name=");
  132. s.append(this.contextName.toString());
  133. s.append(", Version=");
  134. s.append(this.contextVersion.toString());
  135. s.append(", Oid=");
  136. for (long l : this.getOID()) {
  137. s.append(l).append(", ");
  138. }
  139. s.append("]");
  140. return s.toString();
  141. }
  142. }