PageRenderTime 35ms CodeModel.GetById 13ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 1ms

/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/lsm/SendRoutingInfoForLCSResponseIndicationImpl.java

http://mobicents.googlecode.com/
Java | 458 lines | 270 code | 45 blank | 143 comment | 43 complexity | 279f014eb17c7458b9e481383bfe1dce 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.lsm;
 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.MAPMessageType;
 33import org.mobicents.protocols.ss7.map.api.MAPOperationCode;
 34import org.mobicents.protocols.ss7.map.api.MAPParsingComponentException;
 35import org.mobicents.protocols.ss7.map.api.MAPParsingComponentExceptionReason;
 36import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
 37import org.mobicents.protocols.ss7.map.api.primitives.SubscriberIdentity;
 38import org.mobicents.protocols.ss7.map.api.service.lsm.LCSLocationInfo;
 39import org.mobicents.protocols.ss7.map.api.service.lsm.SendRoutingInfoForLCSResponseIndication;
 40import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
 41import org.mobicents.protocols.ss7.map.primitives.SubscriberIdentityImpl;
 42
 43/**
 44 * @author amit bhayani
 45 * 
 46 */
 47public class SendRoutingInfoForLCSResponseIndicationImpl extends LsmMessageImpl implements SendRoutingInfoForLCSResponseIndication {
 48
 49	private static final int _TAG_TARGET_MS = 0;
 50	private static final int _TAG_LCS_LOCATION_INFO = 1;
 51	private static final int _TAG_EXTENSION_CONTAINER = 2;
 52	private static final int _TAG_V_GMLC_ADDRESS = 3;
 53	private static final int _TAG_H_GMLC_ADDRESS = 4;
 54	private static final int _TAG_PPR_ADDRESS = 5;
 55	private static final int _TAG_ADDITIONAL_V_GMLC_ADDRESS = 6;
 56
 57	private SubscriberIdentity targetMS = null;
 58	private LCSLocationInfo lcsLocationInfo = null;
 59	private MAPExtensionContainer extensionContainer = null;
 60	private byte[] vgmlcAddress = null;
 61	private byte[] hGmlcAddress = null;
 62	private byte[] pprAddress = null;
 63	private byte[] additionalVGmlcAddress = null;
 64
 65	/**
 66	 * 
 67	 */
 68	public SendRoutingInfoForLCSResponseIndicationImpl() {
 69		super();
 70	}
 71
 72	/**
 73	 * @param targetMS
 74	 * @param lcsLocationInfo
 75	 * @param extensionContainer
 76	 * @param vgmlcAddress
 77	 * @param hGmlcAddress
 78	 * @param pprAddress
 79	 * @param additionalVGmlcAddress
 80	 */
 81	public SendRoutingInfoForLCSResponseIndicationImpl(SubscriberIdentity targetMS, LCSLocationInfo lcsLocationInfo, MAPExtensionContainer extensionContainer,
 82			byte[] vgmlcAddress, byte[] hGmlcAddress, byte[] pprAddress, byte[] additionalVGmlcAddress) {
 83		super();
 84		this.targetMS = targetMS;
 85		this.lcsLocationInfo = lcsLocationInfo;
 86		this.extensionContainer = extensionContainer;
 87		this.vgmlcAddress = vgmlcAddress;
 88		this.hGmlcAddress = hGmlcAddress;
 89		this.pprAddress = pprAddress;
 90		this.additionalVGmlcAddress = additionalVGmlcAddress;
 91	}
 92
 93	@Override
 94	public MAPMessageType getMessageType() {
 95		return MAPMessageType.sendRoutingInfoForLCS_Response;
 96	}
 97
 98	@Override
 99	public int getOperationCode() {
100		return MAPOperationCode.sendRoutingInfoForLCS;
101	}
102
103	/*
104	 * (non-Javadoc)
105	 * 
106	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.
107	 * SendRoutingInforForLCSResponseIndication#getTargetMS()
108	 */
109	@Override
110	public SubscriberIdentity getTargetMS() {
111		return this.targetMS;
112	}
113
114	/*
115	 * (non-Javadoc)
116	 * 
117	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.
118	 * SendRoutingInforForLCSResponseIndication#getLCSLocationInfo()
119	 */
120	@Override
121	public LCSLocationInfo getLCSLocationInfo() {
122		return this.lcsLocationInfo;
123	}
124
125	/*
126	 * (non-Javadoc)
127	 * 
128	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.
129	 * SendRoutingInforForLCSResponseIndication#getExtensionContainer()
130	 */
131	@Override
132	public MAPExtensionContainer getExtensionContainer() {
133		return this.extensionContainer;
134	}
135
136	/*
137	 * (non-Javadoc)
138	 * 
139	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.
140	 * SendRoutingInforForLCSResponseIndication#getVgmlcAddress()
141	 */
142	@Override
143	public byte[] getVgmlcAddress() {
144		return this.vgmlcAddress;
145	}
146
147	/*
148	 * (non-Javadoc)
149	 * 
150	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.
151	 * SendRoutingInforForLCSResponseIndication#getHGmlcAddress()
152	 */
153	@Override
154	public byte[] getHGmlcAddress() {
155		return this.hGmlcAddress;
156	}
157
158	/*
159	 * (non-Javadoc)
160	 * 
161	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.
162	 * SendRoutingInforForLCSResponseIndication#getPprAddress()
163	 */
164	@Override
165	public byte[] getPprAddress() {
166		return this.pprAddress;
167	}
168
169	/*
170	 * (non-Javadoc)
171	 * 
172	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.
173	 * SendRoutingInforForLCSResponseIndication#getAdditionalVGmlcAddress()
174	 */
175	@Override
176	public byte[] getAdditionalVGmlcAddress() {
177		return this.additionalVGmlcAddress;
178	}
179
180	/*
181	 * (non-Javadoc)
182	 * 
183	 * @see
184	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTag()
185	 */
186	@Override
187	public int getTag() throws MAPException {
188		return Tag.SEQUENCE;
189	}
190
191	/*
192	 * (non-Javadoc)
193	 * 
194	 * @see
195	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTagClass
196	 * ()
197	 */
198	@Override
199	public int getTagClass() {
200		return Tag.CLASS_UNIVERSAL;
201	}
202
203	/*
204	 * (non-Javadoc)
205	 * 
206	 * @see
207	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getIsPrimitive
208	 * ()
209	 */
210	@Override
211	public boolean getIsPrimitive() {
212		return false;
213	}
214
215	/*
216	 * (non-Javadoc)
217	 * 
218	 * @see
219	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeAll
220	 * (org.mobicents.protocols.asn.AsnInputStream)
221	 */
222	@Override
223	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
224		try {
225			int length = ansIS.readLength();
226			this._decode(ansIS, length);
227		} catch (IOException e) {
228			throw new MAPParsingComponentException("IOException when decoding ProvideSubscriberLocationRequestIndication: ", e,
229					MAPParsingComponentExceptionReason.MistypedParameter);
230		} catch (AsnException e) {
231			throw new MAPParsingComponentException("AsnException when decoding ProvideSubscriberLocationRequestIndication: ", e,
232					MAPParsingComponentExceptionReason.MistypedParameter);
233		}
234	}
235
236	/*
237	 * (non-Javadoc)
238	 * 
239	 * @see
240	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeData
241	 * (org.mobicents.protocols.asn.AsnInputStream, int)
242	 */
243	@Override
244	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
245		try {
246			this._decode(ansIS, length);
247		} catch (IOException e) {
248			throw new MAPParsingComponentException("IOException when decoding ProvideSubscriberLocationRequestIndication: ", e,
249					MAPParsingComponentExceptionReason.MistypedParameter);
250		} catch (AsnException e) {
251			throw new MAPParsingComponentException("AsnException when decoding ProvideSubscriberLocationRequestIndication: ", e,
252					MAPParsingComponentExceptionReason.MistypedParameter);
253		}
254	}
255
256	private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
257
258		AsnInputStream ais = ansIS.readSequenceStreamData(length);
259
260		// targetMS [0] SubscriberIdentity
261		int tag = ais.readTag();
262
263		if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || ais.isTagPrimitive() || tag != _TAG_TARGET_MS) {
264			throw new MAPParsingComponentException(
265					"Error while decoding SendRoutingInforForLCSResponseIndication: Parameter [targetMS [0] SubscriberIdentity] bad tag class or not primitive or not Sequence",
266					MAPParsingComponentExceptionReason.MistypedParameter);
267		}
268		int length1 = ais.readLength();
269		tag = ais.readTag();
270
271		this.targetMS = new SubscriberIdentityImpl();
272		((SubscriberIdentityImpl)this.targetMS).decodeAll(ais);
273
274		// lcsLocationInfo [1] LCSLocationInfo,
275		tag = ais.readTag();
276		if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || ais.isTagPrimitive() || tag != _TAG_LCS_LOCATION_INFO) {
277			throw new MAPParsingComponentException(
278					"Error while decoding SendRoutingInforForLCSResponseIndication: Parameter [lcsLocationInfo [1] LCSLocationInfo] bad tag class or not primitive or not Sequence",
279					MAPParsingComponentExceptionReason.MistypedParameter);
280		}
281		this.lcsLocationInfo = new LCSLocationInfoImpl();
282		((LCSLocationInfoImpl)this.lcsLocationInfo).decodeAll(ais);
283
284		while (true) {
285			if (ais.available() == 0)
286				break;
287
288			tag = ais.readTag();
289
290			switch (tag) {
291			case _TAG_EXTENSION_CONTAINER:
292				if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
293					throw new MAPParsingComponentException(
294							"Error while decoding SendRoutingInforForLCSResponseIndication: Parameter [extensionContainer [2] ExtensionContainer] bad tag class or not primitive or not Sequence",
295							MAPParsingComponentExceptionReason.MistypedParameter);
296				}
297				this.extensionContainer = new MAPExtensionContainerImpl();
298				((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
299				break;
300			case _TAG_V_GMLC_ADDRESS:
301				if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
302					throw new MAPParsingComponentException(
303							"Error while decoding SendRoutingInforForLCSResponseIndication: Parameter [v-gmlc-Address [3] GSN-Address] bad tag class or not primitive or not Sequence",
304							MAPParsingComponentExceptionReason.MistypedParameter);
305				}
306				length1 = ais.readLength();
307				this.vgmlcAddress = ais.readOctetStringData(length1);
308				break;
309			case _TAG_H_GMLC_ADDRESS:
310				// h-gmlc-Address [4] GSN-Address OPTIONAL,
311				if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
312					throw new MAPParsingComponentException(
313							"Error while decoding SendRoutingInforForLCSResponseIndication: Parameter [h-gmlc-Address [4] GSN-Address] bad tag class or not primitive or not Sequence",
314							MAPParsingComponentExceptionReason.MistypedParameter);
315				}
316				length1 = ais.readLength();
317				this.hGmlcAddress = ais.readOctetStringData(length1);
318				break;
319			case _TAG_PPR_ADDRESS:
320				if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
321					throw new MAPParsingComponentException(
322							"Error while decoding SendRoutingInforForLCSResponseIndication: Parameter [ppr-Address [5] GSN-Address] bad tag class or not primitive or not Sequence",
323							MAPParsingComponentExceptionReason.MistypedParameter);
324				}
325				length1 = ais.readLength();
326				this.pprAddress = ais.readOctetStringData(length1);
327				break;
328			case _TAG_ADDITIONAL_V_GMLC_ADDRESS:
329				// additional-v-gmlc-Address [6] GSN-Address OPTIONAL
330				if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
331					throw new MAPParsingComponentException(
332							"Error while decoding SendRoutingInforForLCSResponseIndication: Parameter [additional-v-gmlc-Address [6] GSN-Address] bad tag class or not primitive or not Sequence",
333							MAPParsingComponentExceptionReason.MistypedParameter);
334				}
335				length1 = ais.readLength();
336				this.additionalVGmlcAddress = ais.readOctetStringData(length1);
337				break;
338			default:
339				ais.advanceElement();
340				break;
341			}
342		}// while
343
344	}
345
346	/*
347	 * (non-Javadoc)
348	 * 
349	 * @see
350	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
351	 * (org.mobicents.protocols.asn.AsnOutputStream)
352	 */
353	@Override
354	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
355		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
356	}
357
358	/*
359	 * (non-Javadoc)
360	 * 
361	 * @see
362	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
363	 * (org.mobicents.protocols.asn.AsnOutputStream, int, int)
364	 */
365	@Override
366	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
367		try {
368			asnOs.writeTag(tagClass, false, tag);
369			int pos = asnOs.StartContentDefiniteLength();
370			this.encodeData(asnOs);
371			asnOs.FinalizeContent(pos);
372		} catch (AsnException e) {
373			throw new MAPException("AsnException when encoding MWStatus: " + e.getMessage(), e);
374		}
375	}
376
377	/*
378	 * (non-Javadoc)
379	 * 
380	 * @see
381	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeData
382	 * (org.mobicents.protocols.asn.AsnOutputStream)
383	 */
384	@Override
385	public void encodeData(AsnOutputStream asnOs) throws MAPException {
386		if (this.targetMS == null) {
387			throw new MAPException(
388					"Encoding of SendRoutingInforForLCSResponseIndication failed. Manadatory parameter targetMS [0] SubscriberIdentity is not set");
389		}
390
391		if (this.lcsLocationInfo == null) {
392			throw new MAPException(
393					"Encoding of SendRoutingInforForLCSResponseIndication failed. Manadatory parameter lcsLocationInfo [1] LCSLocationInfo is not set");
394		}
395
396		try {
397			asnOs.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false, _TAG_TARGET_MS);
398		} catch (AsnException e) {
399			throw new MAPException("AsnException while encoding parameter targetMS [0] SubscriberIdentity");
400		}
401
402		int pos = asnOs.StartContentDefiniteLength();
403		((SubscriberIdentityImpl)this.targetMS).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, ((SubscriberIdentityImpl)this.targetMS).getTag());
404		asnOs.FinalizeContent(pos);
405
406		((LCSLocationInfoImpl)this.lcsLocationInfo).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LCS_LOCATION_INFO);
407
408		if (this.extensionContainer != null) {
409			// extensionContainer [2] ExtensionContainer OPTIONAL,
410			((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_EXTENSION_CONTAINER);
411		}
412
413		if (this.vgmlcAddress != null) {
414			// v-gmlc-Address [3] GSN-Address OPTIONAL,
415			try {
416				asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_V_GMLC_ADDRESS, this.vgmlcAddress);
417			} catch (IOException e) {
418				throw new MAPException("IOException while encoding parameter v-gmlc-Address");
419			} catch (AsnException e) {
420				throw new MAPException("AsnException while encoding parameter v-gmlc-Address");
421			}
422		}
423
424		if (this.hGmlcAddress != null) {
425			// h-gmlc-Address [4] GSN-Address OPTIONAL,
426			try {
427				asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_H_GMLC_ADDRESS, this.hGmlcAddress);
428			} catch (IOException e) {
429				throw new MAPException("IOException while encoding parameter hGmlcAddress");
430			} catch (AsnException e) {
431				throw new MAPException("AsnException while encoding parameter hGmlcAddress");
432			}
433		}
434
435		if (this.pprAddress != null) {
436			// ppr-Address [5] GSN-Address OPTIONAL,
437			try {
438				asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_PPR_ADDRESS, this.pprAddress);
439			} catch (IOException e) {
440				throw new MAPException("IOException while encoding parameter pprAddress");
441			} catch (AsnException e) {
442				throw new MAPException("AsnException while encoding parameter pprAddress");
443			}
444		}
445
446		if (this.additionalVGmlcAddress != null) {
447			// additional-v-gmlc-Address [6] GSN-Address OPTIONAL,
448			try {
449				asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_ADDITIONAL_V_GMLC_ADDRESS, this.additionalVGmlcAddress);
450			} catch (IOException e) {
451				throw new MAPException("IOException while encoding parameter additionalVGmlcAddress");
452			} catch (AsnException e) {
453				throw new MAPException("AsnException while encoding parameter additionalVGmlcAddress");
454			}
455		}
456	}
457
458}