PageRenderTime 29ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/supplementary/USSDMessageImpl.java

http://mobicents.googlecode.com/
Java | 115 lines | 62 code | 22 blank | 31 comment | 2 complexity | fadd0cf07976a58d84fd65729274f37c 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.service.supplementary;
  23. import javolution.xml.XMLFormat;
  24. import javolution.xml.stream.XMLStreamException;
  25. import org.mobicents.protocols.ss7.map.MessageImpl;
  26. import org.mobicents.protocols.ss7.map.api.primitives.USSDString;
  27. import org.mobicents.protocols.ss7.map.api.service.supplementary.MAPDialogSupplementary;
  28. import org.mobicents.protocols.ss7.map.api.service.supplementary.USSDMessage;
  29. import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
  30. import org.mobicents.protocols.ss7.map.primitives.USSDStringImpl;
  31. /**
  32. * @author amit bhayani
  33. *
  34. */
  35. public abstract class USSDMessageImpl extends MessageImpl implements USSDMessage, MAPAsnPrimitive {
  36. private static final String DATA_CODING_SCHEME = "dataCodingScheme";
  37. private static final String STRING = "string";
  38. private static final byte DEFAULT_DATA_CODING_SCHEME = 0x0f;
  39. private static final String DEFAULT_USSD_STRING = "";
  40. protected byte ussdDataCodingSch;
  41. protected USSDString ussdString;
  42. /**
  43. *
  44. */
  45. public USSDMessageImpl() {
  46. super();
  47. }
  48. public USSDMessageImpl(byte ussdDataCodingSch, USSDString ussdString) {
  49. this.ussdDataCodingSch = ussdDataCodingSch;
  50. this.ussdString = ussdString;
  51. }
  52. public MAPDialogSupplementary getMAPDialog() {
  53. return (MAPDialogSupplementary) super.getMAPDialog();
  54. }
  55. public byte getUSSDDataCodingScheme() {
  56. return ussdDataCodingSch;
  57. }
  58. public USSDString getUSSDString() {
  59. return this.ussdString;
  60. }
  61. @Override
  62. public String toString() {
  63. StringBuilder sb = new StringBuilder();
  64. sb.append("ussdDataCodingSch=");
  65. sb.append(ussdDataCodingSch);
  66. if (ussdString != null) {
  67. sb.append(", ussdString=");
  68. sb.append(ussdString.getString());
  69. }
  70. sb.append("]");
  71. return sb.toString();
  72. }
  73. /**
  74. * XML Serialization/Deserialization
  75. */
  76. protected static final XMLFormat<USSDMessageImpl> USSD_MESSAGE_XML = new XMLFormat<USSDMessageImpl>(
  77. USSDMessageImpl.class) {
  78. @Override
  79. public void read(javolution.xml.XMLFormat.InputElement xml, USSDMessageImpl ussdMessage)
  80. throws XMLStreamException {
  81. MAP_MESSAGE_XML.read(xml, ussdMessage);
  82. ussdMessage.ussdDataCodingSch = xml.getAttribute(DATA_CODING_SCHEME, DEFAULT_DATA_CODING_SCHEME);
  83. ussdMessage.ussdString = new USSDStringImpl(xml.getAttribute(STRING, DEFAULT_USSD_STRING), null);
  84. }
  85. @Override
  86. public void write(USSDMessageImpl ussdMessage, javolution.xml.XMLFormat.OutputElement xml)
  87. throws XMLStreamException {
  88. MAP_MESSAGE_XML.write(ussdMessage, xml);
  89. xml.setAttribute(DATA_CODING_SCHEME, ussdMessage.ussdDataCodingSch);
  90. xml.setAttribute(STRING, ussdMessage.getUSSDString().getString());
  91. }
  92. };
  93. }