PageRenderTime 26ms CodeModel.GetById 1ms app.highlight 18ms RepoModel.GetById 1ms 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
  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
 23package org.mobicents.protocols.ss7.map.service.supplementary;
 24
 25import javolution.xml.XMLFormat;
 26import javolution.xml.stream.XMLStreamException;
 27
 28import org.mobicents.protocols.ss7.map.MessageImpl;
 29import org.mobicents.protocols.ss7.map.api.primitives.USSDString;
 30import org.mobicents.protocols.ss7.map.api.service.supplementary.MAPDialogSupplementary;
 31import org.mobicents.protocols.ss7.map.api.service.supplementary.USSDMessage;
 32import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
 33import org.mobicents.protocols.ss7.map.primitives.USSDStringImpl;
 34
 35/**
 36 * @author amit bhayani
 37 * 
 38 */
 39public abstract class USSDMessageImpl extends MessageImpl implements USSDMessage, MAPAsnPrimitive {
 40
 41	private static final String DATA_CODING_SCHEME = "dataCodingScheme";
 42	private static final String STRING = "string";
 43
 44	private static final byte DEFAULT_DATA_CODING_SCHEME = 0x0f;
 45	private static final String DEFAULT_USSD_STRING = "";
 46
 47	protected byte ussdDataCodingSch;
 48
 49	protected USSDString ussdString;
 50
 51	/**
 52	 * 
 53	 */
 54	public USSDMessageImpl() {
 55		super();
 56	}
 57
 58	public USSDMessageImpl(byte ussdDataCodingSch, USSDString ussdString) {
 59		this.ussdDataCodingSch = ussdDataCodingSch;
 60		this.ussdString = ussdString;
 61	}
 62
 63	public MAPDialogSupplementary getMAPDialog() {
 64		return (MAPDialogSupplementary) super.getMAPDialog();
 65	}
 66
 67	public byte getUSSDDataCodingScheme() {
 68		return ussdDataCodingSch;
 69	}
 70
 71	public USSDString getUSSDString() {
 72		return this.ussdString;
 73	}
 74
 75	@Override
 76	public String toString() {
 77		StringBuilder sb = new StringBuilder();
 78		
 79		sb.append("ussdDataCodingSch=");
 80		sb.append(ussdDataCodingSch);
 81		if (ussdString != null) {
 82			sb.append(", ussdString=");
 83			sb.append(ussdString.getString());
 84		}
 85
 86		sb.append("]");
 87
 88		return sb.toString();
 89	}
 90
 91	/**
 92	 * XML Serialization/Deserialization
 93	 */
 94	protected static final XMLFormat<USSDMessageImpl> USSD_MESSAGE_XML = new XMLFormat<USSDMessageImpl>(
 95			USSDMessageImpl.class) {
 96
 97		@Override
 98		public void read(javolution.xml.XMLFormat.InputElement xml, USSDMessageImpl ussdMessage)
 99				throws XMLStreamException {
100			MAP_MESSAGE_XML.read(xml, ussdMessage);
101			ussdMessage.ussdDataCodingSch = xml.getAttribute(DATA_CODING_SCHEME, DEFAULT_DATA_CODING_SCHEME);
102			ussdMessage.ussdString = new USSDStringImpl(xml.getAttribute(STRING, DEFAULT_USSD_STRING), null);
103
104		}
105
106		@Override
107		public void write(USSDMessageImpl ussdMessage, javolution.xml.XMLFormat.OutputElement xml)
108				throws XMLStreamException {
109			MAP_MESSAGE_XML.write(ussdMessage, xml);
110			xml.setAttribute(DATA_CODING_SCHEME, ussdMessage.ussdDataCodingSch);
111			xml.setAttribute(STRING, ussdMessage.getUSSDString().getString());
112		}
113	};
114
115}