PageRenderTime 74ms CodeModel.GetById 45ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 215 lines | 140 code | 41 blank | 34 comment | 8 complexity | 4dfa688e0ac03353d421343a832a9eb0 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 java.io.IOException;
 26
 27import javolution.xml.XMLFormat;
 28import javolution.xml.stream.XMLStreamException;
 29
 30import org.mobicents.protocols.asn.AsnException;
 31import org.mobicents.protocols.asn.AsnInputStream;
 32import org.mobicents.protocols.asn.AsnOutputStream;
 33import org.mobicents.protocols.asn.Tag;
 34import org.mobicents.protocols.ss7.map.api.MAPException;
 35import org.mobicents.protocols.ss7.map.api.MAPMessageType;
 36import org.mobicents.protocols.ss7.map.api.MAPOperationCode;
 37import org.mobicents.protocols.ss7.map.api.MAPParsingComponentException;
 38import org.mobicents.protocols.ss7.map.api.MAPParsingComponentExceptionReason;
 39import org.mobicents.protocols.ss7.map.api.primitives.USSDString;
 40import org.mobicents.protocols.ss7.map.api.service.supplementary.ProcessUnstructuredSSResponseIndication;
 41import org.mobicents.protocols.ss7.map.primitives.USSDStringImpl;
 42
 43/**
 44 * 
 45 * @author amit bhayani
 46 * 
 47 */
 48public class ProcessUnstructuredSSResponseIndicationImpl extends USSDMessageImpl implements
 49		ProcessUnstructuredSSResponseIndication {
 50
 51	/**
 52	 * 
 53	 */
 54	public ProcessUnstructuredSSResponseIndicationImpl() {
 55		super();
 56	}
 57
 58	public ProcessUnstructuredSSResponseIndicationImpl(byte ussdDataCodingSch, USSDString ussdString) {
 59		super(ussdDataCodingSch, ussdString);
 60	}
 61
 62	@Override
 63	public MAPMessageType getMessageType() {
 64		return MAPMessageType.processUnstructuredSSRequest_Response;
 65	}
 66
 67	@Override
 68	public int getOperationCode() {
 69		return MAPOperationCode.processUnstructuredSS_Request;
 70	}
 71
 72	@Override
 73	public int getTag() throws MAPException {
 74		return Tag.SEQUENCE;
 75	}
 76
 77	@Override
 78	public int getTagClass() {
 79		return Tag.CLASS_UNIVERSAL;
 80	}
 81
 82	@Override
 83	public boolean getIsPrimitive() {
 84		return false;
 85	}
 86
 87	@Override
 88	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
 89
 90		try {
 91			int length = ansIS.readLength();
 92			this._decode(ansIS, length);
 93		} catch (IOException e) {
 94			throw new MAPParsingComponentException(
 95					"IOException when decoding ProcessUnstructuredSSResponseIndication: " + e.getMessage(), e,
 96					MAPParsingComponentExceptionReason.MistypedParameter);
 97		} catch (AsnException e) {
 98			throw new MAPParsingComponentException(
 99					"AsnException when decoding ProcessUnstructuredSSResponseIndication: " + e.getMessage(), e,
100					MAPParsingComponentExceptionReason.MistypedParameter);
101		}
102	}
103
104	@Override
105	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
106
107		try {
108			this._decode(ansIS, length);
109		} catch (IOException e) {
110			throw new MAPParsingComponentException(
111					"IOException when decoding ProcessUnstructuredSSResponseIndication: " + e.getMessage(), e,
112					MAPParsingComponentExceptionReason.MistypedParameter);
113		} catch (AsnException e) {
114			throw new MAPParsingComponentException(
115					"AsnException when decoding ProcessUnstructuredSSResponseIndication: " + e.getMessage(), e,
116					MAPParsingComponentExceptionReason.MistypedParameter);
117		}
118	}
119
120	private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException,
121			AsnException {
122
123		AsnInputStream ais = ansIS.readSequenceStreamData(length);
124
125		int tag = ais.readTag();
126
127		// ussd-DataCodingScheme USSD-DataCodingScheme
128		if (ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive())
129			throw new MAPParsingComponentException(
130					"Error while decoding ProcessUnstructuredSSResponseIndication: Parameter ussd-DataCodingScheme bad tag class or not primitive",
131					MAPParsingComponentExceptionReason.MistypedParameter);
132
133		int length1 = ais.readLength();
134		this.ussdDataCodingSch = ais.readOctetStringData(length1)[0];
135
136		tag = ais.readTag();
137
138		// ussd-String USSD-String
139		if (ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive())
140			throw new MAPParsingComponentException(
141					"Error while decoding ProcessUnstructuredSSResponseIndication: Parameter ussd-String bad tag class or not primitive",
142					MAPParsingComponentExceptionReason.MistypedParameter);
143
144		this.ussdString = new USSDStringImpl();
145		((USSDStringImpl) this.ussdString).decodeAll(ais);
146
147	}
148
149	@Override
150	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
151
152		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
153	}
154
155	@Override
156	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
157
158		try {
159			asnOs.writeTag(tagClass, false, tag);
160			int pos = asnOs.StartContentDefiniteLength();
161			this.encodeData(asnOs);
162			asnOs.FinalizeContent(pos);
163		} catch (AsnException e) {
164			throw new MAPException("AsnException when encoding ProcessUnstructuredSSResponseIndication", e);
165		}
166	}
167
168	@Override
169	public void encodeData(AsnOutputStream asnOs) throws MAPException {
170
171		if (this.ussdString == null)
172			throw new MAPException("ussdString must not be null");
173
174		try {
175			asnOs.writeOctetString(new byte[] { this.ussdDataCodingSch });
176
177			((USSDStringImpl) this.ussdString).encodeAll(asnOs);
178
179		} catch (IOException e) {
180			throw new MAPException("IOException when encoding ProcessUnstructuredSSResponseIndication", e);
181		} catch (AsnException e) {
182			throw new MAPException("AsnException when encoding ProcessUnstructuredSSResponseIndication", e);
183		}
184	}
185
186	@Override
187	public String toString() {
188		StringBuilder sb = new StringBuilder();
189		sb.append("ProcessUnstructuredSSResponse [");
190		sb.append("]");
191
192		return sb.toString();
193	}
194
195	/**
196	 * XML Serialization/Deserialization
197	 */
198	protected static final XMLFormat<ProcessUnstructuredSSResponseIndicationImpl> PROCESS_UNSTRUCTURED_SS_RESPONSE_XML = new XMLFormat<ProcessUnstructuredSSResponseIndicationImpl>(
199			ProcessUnstructuredSSResponseIndicationImpl.class) {
200
201		@Override
202		public void read(javolution.xml.XMLFormat.InputElement xml,
203				ProcessUnstructuredSSResponseIndicationImpl ussdMessage) throws XMLStreamException {
204			USSD_MESSAGE_XML.read(xml, ussdMessage);
205
206		}
207
208		@Override
209		public void write(ProcessUnstructuredSSResponseIndicationImpl ussdMessage,
210				javolution.xml.XMLFormat.OutputElement xml) throws XMLStreamException {
211			USSD_MESSAGE_XML.write(ussdMessage, xml);
212		}
213	};
214
215}