PageRenderTime 19ms CodeModel.GetById 1ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/dialog/MAPOpenInfoImpl.java

http://mobicents.googlecode.com/
Java | 319 lines | 207 code | 55 blank | 57 comment | 27 complexity | 7184c80f85bd73b4df9010557660bc03 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.dialog;
 24
 25import java.io.IOException;
 26
 27import org.mobicents.protocols.asn.AsnException;
 28import org.mobicents.protocols.asn.AsnInputStream;
 29import org.mobicents.protocols.asn.AsnOutputStream;
 30import org.mobicents.protocols.asn.Tag;
 31import org.mobicents.protocols.ss7.map.api.MAPException;
 32import org.mobicents.protocols.ss7.map.api.MAPParsingComponentException;
 33import org.mobicents.protocols.ss7.map.api.MAPParsingComponentExceptionReason;
 34import org.mobicents.protocols.ss7.map.api.primitives.AddressString;
 35import org.mobicents.protocols.ss7.map.api.primitives.IMSI;
 36import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
 37import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
 38import org.mobicents.protocols.ss7.map.primitives.IMSIImpl;
 39import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
 40import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
 41
 42/**
 43 * Below is Ericsson MAP-OpenInfo
 44 * 
 45 * MAP−OpenInfo ::= SEQUENCE (
 46 *		imsi					(0)	IMSI OPTIONAL,
 47 *		originationReference 	(1)	AddressString OPTIONAL,
 48 *		msisdn					(2)	AddressString,
 49 *		...
 50 *		vlrNo					(3)	AddressString OPTIONAL
 51 *	)
 52 * 
 53 * @author amit bhayani
 54 * @author sergey vetyutnev
 55 * 
 56 */
 57public class MAPOpenInfoImpl implements MAPAsnPrimitive {
 58
 59	public static final int MAP_OPEN_INFO_TAG = 0x00;
 60
 61	protected static final int DESTINATION_REF_TAG = 0x00;
 62	protected static final int ORIGINATION_REF_TAG = 0x01;
 63	protected static final int ERI_MSISDN_TAG = 0x02;
 64	protected static final int ERI_NLR_NO_TAG = 0x03;
 65
 66	protected static final int OPEN_INFO_TAG_CLASS = Tag.CLASS_CONTEXT_SPECIFIC;
 67	protected static final boolean OPEN_INFO_TAG_PC_PRIMITIVE = true;
 68	protected static final boolean OPEN_INFO_TAG_PC_CONSTRUCTED = false;
 69
 70	private AddressString destReference;
 71	private AddressString origReference;
 72	private MAPExtensionContainer extensionContainer;
 73
 74	private boolean eriStyle;
 75	private IMSI eriImsi;
 76	private AddressString eriVlrNo;
 77
 78	public AddressString getDestReference() {
 79		return this.destReference;
 80	}
 81
 82	public AddressString getOrigReference() {
 83		return this.origReference;
 84	}
 85
 86	public MAPExtensionContainer getExtensionContainer() {
 87		return extensionContainer;
 88	}
 89
 90	public boolean getEriStyle() {
 91		return this.eriStyle;
 92	}
 93
 94	public IMSI getEriImsi() {
 95		return eriImsi;
 96	}
 97
 98	public AddressString getEriVlrNo() {
 99		return eriVlrNo;
100	}
101
102	public void setDestReference(AddressString destReference) {
103		this.destReference = destReference;
104	}
105
106	public void setOrigReference(AddressString origReference) {
107		this.origReference = origReference;
108	}
109
110	public void setExtensionContainer(MAPExtensionContainer extensionContainer) {
111		this.extensionContainer = extensionContainer;
112	}
113
114	public void setEriStyle(boolean eriStyle) {
115		this.eriStyle = eriStyle;
116	}
117
118	public void setEriImsi(IMSI eriImsi) {
119		this.eriImsi = eriImsi;
120	}
121
122	public void setEriVlrNo(AddressString eriVlrNo) {
123		this.eriVlrNo = eriVlrNo;
124	}
125
126	
127	@Override
128	public int getTag() throws MAPException {
129		return MAP_OPEN_INFO_TAG;
130	}
131
132	@Override
133	public int getTagClass() {
134		return Tag.CLASS_CONTEXT_SPECIFIC;
135	}
136
137	@Override
138	public boolean getIsPrimitive() {
139		return false;
140	}
141
142	@Override
143	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
144
145		try {
146			int length = ansIS.readLength();
147			this._decode(ansIS, length);
148		} catch (IOException e) {
149			throw new MAPParsingComponentException("IOException when decoding MAPOpenInfo: " + e.getMessage(), e,
150					MAPParsingComponentExceptionReason.MistypedParameter);
151		} catch (AsnException e) {
152			throw new MAPParsingComponentException("AsnException when decoding MAPOpenInfo: " + e.getMessage(), e,
153					MAPParsingComponentExceptionReason.MistypedParameter);
154		}
155	}
156
157	@Override
158	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
159
160		try {
161			this._decode(ansIS, length);
162		} catch (IOException e) {
163			throw new MAPParsingComponentException("IOException when decoding MAPOpenInfo: " + e.getMessage(), e,
164					MAPParsingComponentExceptionReason.MistypedParameter);
165		} catch (AsnException e) {
166			throw new MAPParsingComponentException("AsnException when decoding MAPOpenInfo: " + e.getMessage(), e,
167					MAPParsingComponentExceptionReason.MistypedParameter);
168		}
169	}
170
171	private void _decode(AsnInputStream ais, int length) throws MAPParsingComponentException, IOException, AsnException {
172
173		// Definitioon from GSM 09.02 version 5.15.1 Page 690
174		// map-open [0] IMPLICIT SEQUENCE {
175		// destinationReference [0] IMPLICIT OCTET STRING ( SIZE( 1 .. 20 ) )
176		// OPTIONAL,
177		// originationReference [1] IMPLICIT OCTET STRING ( SIZE( 1 .. 20 ) )
178		// OPTIONAL,
179		// ... ,
180		// extensionContainer SEQUENCE {
181		// privateExtensionList [0] IMPLICIT SEQUENCE ( SIZE( 1 .. 10 ) ) OF
182		// SEQUENCE {
183		// extId MAP-EXTENSION .&extensionId ( {
184		// ,
185		// ...} ) ,
186		// extType MAP-EXTENSION .&ExtensionType ( {
187		// ,
188		// ...} { @extId } ) OPTIONAL} OPTIONAL,
189		// pcs-Extensions [1] IMPLICIT SEQUENCE {
190		// ... } OPTIONAL,
191		// ... } OPTIONAL},
192
193		this.destReference = null;
194		this.origReference = null;
195		this.extensionContainer = null;
196		this.eriStyle = false;
197		this.eriImsi = null;
198		this.eriVlrNo = null;
199
200		AsnInputStream localAis = ais.readSequenceStreamData(length);
201
202		// checking for Ericsson-style
203		int startPos = localAis.position();
204		while (localAis.available() > 0) {
205			int tag = localAis.readTag();
206			if (localAis.getTagClass() == Tag.CLASS_CONTEXT_SPECIFIC && tag == ERI_MSISDN_TAG) {
207				this.eriStyle = true;
208				break;
209			}
210			localAis.advanceElement();
211		}
212
213		// parsing
214		localAis.position(startPos);
215		while (localAis.available() > 0) {
216			int tag = localAis.readTag();
217
218			switch (localAis.getTagClass()) {
219			case Tag.CLASS_CONTEXT_SPECIFIC:
220				switch (tag) {
221				case DESTINATION_REF_TAG:
222					if (this.eriStyle) {
223						this.eriImsi = new IMSIImpl();
224						((IMSIImpl) this.eriImsi).decodeAll(localAis);
225					} else {
226						this.destReference = new AddressStringImpl();
227						((AddressStringImpl) this.destReference).decodeAll(localAis);
228					}
229					break;
230
231				case ORIGINATION_REF_TAG:
232					this.origReference = new AddressStringImpl();
233					((AddressStringImpl)this.origReference).decodeAll(localAis);
234					break;
235
236				case ERI_MSISDN_TAG:
237					this.destReference = new AddressStringImpl();
238					((AddressStringImpl) this.destReference).decodeAll(localAis);
239					break;
240
241				case ERI_NLR_NO_TAG:
242					this.eriVlrNo = new AddressStringImpl();
243					((AddressStringImpl)this.eriVlrNo).decodeAll(localAis);
244					break;
245
246				default:
247					localAis.advanceElement();
248					break;
249				}
250				break;
251
252			case Tag.CLASS_UNIVERSAL:
253				switch (tag) {
254				case Tag.SEQUENCE:
255					this.extensionContainer = new MAPExtensionContainerImpl();
256					((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(localAis);
257					break;
258
259				default:
260					localAis.advanceElement();
261					break;
262				}
263				break;
264
265			default:
266				localAis.advanceElement();
267				break;
268			}
269		}
270	}
271
272	@Override
273	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
274
275		this.encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, MAP_OPEN_INFO_TAG);
276	}
277
278	@Override
279	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
280		
281		try {
282			asnOs.writeTag(tagClass, false, tag);
283			int pos = asnOs.StartContentDefiniteLength();
284			this.encodeData(asnOs);
285			asnOs.FinalizeContent(pos);
286		} catch (AsnException e) {
287			throw new MAPException("AsnException when encoding MAPOpenInfo: " + e.getMessage(), e);
288		}
289	}
290
291	@Override
292	public void encodeData(AsnOutputStream asnOS) throws MAPException {
293
294		if (this.eriStyle) {
295
296			if (this.destReference == null)
297				throw new MAPException("Error when encoding MAPOpenInf Ericsson style: destReference parameter must not be null");
298
299			if (this.eriImsi != null)
300				((IMSIImpl) this.eriImsi).encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, DESTINATION_REF_TAG);
301			if (this.origReference != null)
302				((AddressStringImpl) this.origReference).encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, ORIGINATION_REF_TAG);
303			((AddressStringImpl) this.destReference).encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, ERI_MSISDN_TAG);
304			if (this.eriVlrNo != null)
305				((AddressStringImpl) this.eriVlrNo).encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, ERI_NLR_NO_TAG);
306		} else {
307			
308			if (this.destReference != null)
309				((AddressStringImpl) this.destReference).encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, DESTINATION_REF_TAG);
310
311			if (this.origReference != null)
312				((AddressStringImpl) this.origReference).encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, ORIGINATION_REF_TAG);
313
314			if (this.extensionContainer != null)
315				((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOS);
316		}
317	}
318}
319