PageRenderTime 29ms CodeModel.GetById 10ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

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