PageRenderTime 72ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/protocols/ss7/isup/isup-impl/src/main/java/org/mobicents/protocols/ss7/isup/impl/message/InformationMessageImpl.java

http://mobicents.googlecode.com/
Java | 261 lines | 142 code | 39 blank | 80 comment | 4 complexity | 0677de15050b2856cb48a065cb22a47b 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. /**
  23. * Start time:23:59:59 2009-09-06<br>
  24. * Project: mobicents-isup-stack<br>
  25. *
  26. * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a>
  27. */
  28. package org.mobicents.protocols.ss7.isup.impl.message;
  29. import java.util.Map;
  30. import java.util.Set;
  31. import org.mobicents.protocols.ss7.isup.ISUPParameterFactory;
  32. import org.mobicents.protocols.ss7.isup.ParameterException;
  33. import org.mobicents.protocols.ss7.isup.impl.message.parameter.AbstractISUPParameter;
  34. import org.mobicents.protocols.ss7.isup.impl.message.parameter.MessageTypeImpl;
  35. import org.mobicents.protocols.ss7.isup.message.InformationMessage;
  36. import org.mobicents.protocols.ss7.isup.message.parameter.CallReference;
  37. import org.mobicents.protocols.ss7.isup.message.parameter.CallingPartyCategory;
  38. import org.mobicents.protocols.ss7.isup.message.parameter.CallingPartyNumber;
  39. import org.mobicents.protocols.ss7.isup.message.parameter.ConnectionRequest;
  40. import org.mobicents.protocols.ss7.isup.message.parameter.InformationIndicators;
  41. import org.mobicents.protocols.ss7.isup.message.parameter.InformationRequestIndicators;
  42. import org.mobicents.protocols.ss7.isup.message.parameter.MessageType;
  43. import org.mobicents.protocols.ss7.isup.message.parameter.NetworkSpecificFacility;
  44. import org.mobicents.protocols.ss7.isup.message.parameter.ParameterCompatibilityInformation;
  45. /**
  46. * Start time:23:59:59 2009-09-06<br>
  47. * Project: mobicents-isup-stack<br>
  48. *
  49. * @author <a href="mailto:baranowb@gmail.com">Bartosz Baranowski </a>
  50. */
  51. public class InformationMessageImpl extends ISUPMessageImpl implements InformationMessage {
  52. public static final MessageTypeImpl _MESSAGE_TYPE = new MessageTypeImpl(MESSAGE_CODE);
  53. static final int _INDEX_F_MessageType = 0;
  54. static final int _INDEX_F_InformationIndicators = 1;
  55. static final int _INDEX_O_CallingPartyCategory = 0;
  56. static final int _INDEX_O_CallingPartyNumber = 1;
  57. static final int _INDEX_O_CallReference = 2;
  58. static final int _INDEX_O_ConnectionRequest = 3;
  59. static final int _INDEX_O_ParameterCompatibilityInformation = 4;
  60. static final int _INDEX_O_NetworkSpecificFacility = 5;
  61. static final int _INDEX_O_EndOfOptionalParameters = 6;
  62. /**
  63. *
  64. * @param source
  65. * @throws ParameterException
  66. */
  67. public InformationMessageImpl(Set<Integer> mandatoryCodes, Set<Integer> mandatoryVariableCodes, Set<Integer> optionalCodes,
  68. Map<Integer, Integer> mandatoryCode2Index, Map<Integer, Integer> mandatoryVariableCode2Index, Map<Integer, Integer> optionalCode2Index) {
  69. super(mandatoryCodes, mandatoryVariableCodes, optionalCodes, mandatoryCode2Index, mandatoryVariableCode2Index, optionalCode2Index);
  70. super.f_Parameters.put(_INDEX_F_MessageType, this.getMessageType());
  71. super.o_Parameters.put(_INDEX_O_EndOfOptionalParameters, _END_OF_OPTIONAL_PARAMETERS);
  72. }
  73. public InformationIndicators getInformationIndicators() {
  74. return (InformationIndicators) super.f_Parameters.get(_INDEX_F_InformationIndicators);
  75. }
  76. public void setInformationIndicators(InformationIndicators v) {
  77. super.f_Parameters.put(_INDEX_F_InformationIndicators, v);
  78. }
  79. public CallingPartyCategory getCallingPartyCategory() {
  80. return (CallingPartyCategory) super.o_Parameters.get(_INDEX_O_CallingPartyCategory);
  81. }
  82. public void setCallingPartyCategory(CallingPartyCategory v) {
  83. super.o_Parameters.put(_INDEX_O_CallingPartyCategory, v);
  84. }
  85. public CallingPartyNumber getCallingPartyNumber() {
  86. return (CallingPartyNumber) super.o_Parameters.get(_INDEX_O_CallingPartyNumber);
  87. }
  88. public void setCallingPartyNumber(CallingPartyNumber v) {
  89. super.o_Parameters.put(_INDEX_O_CallingPartyNumber, v);
  90. }
  91. public CallReference getCallReference() {
  92. return (CallReference) super.o_Parameters.get(_INDEX_O_CallReference);
  93. }
  94. public void setCallReference(CallReference v) {
  95. super.o_Parameters.put(_INDEX_O_CallReference, v);
  96. }
  97. public ParameterCompatibilityInformation getParameterCompatibilityInformation() {
  98. return (ParameterCompatibilityInformation) super.o_Parameters.get(_INDEX_O_ParameterCompatibilityInformation);
  99. }
  100. public void setParameterCompatibilityInformation(ParameterCompatibilityInformation v) {
  101. super.o_Parameters.put(_INDEX_O_ParameterCompatibilityInformation, v);
  102. }
  103. public ConnectionRequest getConnectionRequest() {
  104. return (ConnectionRequest) super.o_Parameters.get(_INDEX_O_ConnectionRequest);
  105. }
  106. public void setConnectionRequest(ConnectionRequest v) {
  107. super.o_Parameters.put(_INDEX_O_ConnectionRequest, v);
  108. }
  109. public NetworkSpecificFacility getNetworkSpecificFacility() {
  110. return (NetworkSpecificFacility) super.o_Parameters.get(_INDEX_O_NetworkSpecificFacility);
  111. }
  112. public void setNetworkSpecificFacility(NetworkSpecificFacility v) {
  113. super.o_Parameters.put(_INDEX_O_NetworkSpecificFacility, v);
  114. }
  115. /*
  116. * (non-Javadoc)
  117. *
  118. * @see
  119. * org.mobicents.protocols.ss7.isup.ISUPMessageImpl#decodeMandatoryParameters
  120. * (byte[], int)
  121. */
  122. protected int decodeMandatoryParameters(ISUPParameterFactory parameterFactory, byte[] b, int index) throws ParameterException {
  123. int localIndex = index;
  124. index += super.decodeMandatoryParameters(parameterFactory, b, index);
  125. if (b.length - index > 1) {
  126. try {
  127. byte[] informationInd = new byte[2];
  128. informationInd[0] = b[index++];
  129. informationInd[1] = b[index++];
  130. InformationIndicators bci = parameterFactory.createInformationIndicators();
  131. ((AbstractISUPParameter) bci).decode(informationInd);
  132. this.setInformationIndicators(bci);
  133. } catch (Exception e) {
  134. // AIOOBE or IllegalArg
  135. throw new ParameterException("Failed to parse BackwardCallIndicators due to: ", e);
  136. }
  137. // return 3;
  138. return index - localIndex;
  139. } else {
  140. throw new IllegalArgumentException("byte[] must have atleast 2 octets");
  141. }
  142. }
  143. /*
  144. * (non-Javadoc)
  145. *
  146. * @see
  147. * org.mobicents.protocols.ss7.isup.ISUPMessageImpl#decodeMandatoryVariableBody
  148. * (byte[], int)
  149. */
  150. protected void decodeMandatoryVariableBody(ISUPParameterFactory parameterFactory, byte[] parameterBody, int parameterIndex) throws ParameterException {
  151. throw new UnsupportedOperationException();
  152. }
  153. /*
  154. * (non-Javadoc)
  155. *
  156. * @see
  157. * org.mobicents.protocols.ss7.isup.ISUPMessageImpl#decodeOptionalBody(byte
  158. * [], byte)
  159. */
  160. protected void decodeOptionalBody(ISUPParameterFactory parameterFactory, byte[] parameterBody, byte parameterCode) throws ParameterException {
  161. switch ((int) parameterCode) {
  162. case CallingPartyCategory._PARAMETER_CODE:
  163. CallingPartyCategory RS = parameterFactory.createCallingPartyCategory();
  164. ((AbstractISUPParameter) RS).decode(parameterBody);
  165. this.setCallingPartyCategory(RS);
  166. break;
  167. case CallingPartyNumber._PARAMETER_CODE:
  168. CallingPartyNumber x = parameterFactory.createCallingPartyNumber();
  169. ((AbstractISUPParameter) x).decode(parameterBody);
  170. this.setCallingPartyNumber(x);
  171. break;
  172. case ConnectionRequest._PARAMETER_CODE:
  173. ConnectionRequest z = parameterFactory.createConnectionRequest();
  174. ((AbstractISUPParameter) z).decode(parameterBody);
  175. this.setConnectionRequest(z);
  176. break;
  177. case ParameterCompatibilityInformation._PARAMETER_CODE:
  178. ParameterCompatibilityInformation cc = parameterFactory.createParameterCompatibilityInformation();
  179. ((AbstractISUPParameter) cc).decode(parameterBody);
  180. this.setParameterCompatibilityInformation(cc);
  181. break;
  182. case NetworkSpecificFacility._PARAMETER_CODE:
  183. NetworkSpecificFacility v = parameterFactory.createNetworkSpecificFacility();
  184. ((AbstractISUPParameter) v).decode(parameterBody);
  185. this.setNetworkSpecificFacility(v);
  186. break;
  187. default:
  188. throw new ParameterException("Unrecognized parameter code for optional part: " + parameterCode);
  189. }
  190. }
  191. /*
  192. * (non-Javadoc)
  193. *
  194. * @see org.mobicents.protocols.ss7.isup.ISUPMessageImpl#getMessageType()
  195. */
  196. public MessageType getMessageType() {
  197. return _MESSAGE_TYPE;
  198. }
  199. /*
  200. * (non-Javadoc)
  201. *
  202. * @see org.mobicents.protocols.ss7.isup.ISUPMessageImpl#
  203. * getNumberOfMandatoryVariableLengthParameters()
  204. */
  205. protected int getNumberOfMandatoryVariableLengthParameters() {
  206. // TODO Auto-generated method stub
  207. return 0;
  208. }
  209. /*
  210. * (non-Javadoc)
  211. *
  212. * @see
  213. * org.mobicents.protocols.ss7.isup.ISUPMessageImpl#hasAllMandatoryParameters
  214. * ()
  215. */
  216. public boolean hasAllMandatoryParameters() {
  217. return getInformationIndicators() != null;
  218. }
  219. protected boolean optionalPartIsPossible() {
  220. return true;
  221. }
  222. }