PageRenderTime 55ms CodeModel.GetById 10ms app.highlight 39ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 324 lines | 173 code | 38 blank | 113 comment | 23 complexity | f0aacf6989cefe3f86e1d20f604a3e9b 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.ISDNAddressString;
 37import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
 38import org.mobicents.protocols.ss7.map.api.primitives.SubscriberIdentity;
 39import org.mobicents.protocols.ss7.map.api.service.lsm.SendRoutingInfoForLCSRequestIndication;
 40import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
 41import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
 42import org.mobicents.protocols.ss7.map.primitives.SubscriberIdentityImpl;
 43
 44/**
 45 * @author amit bhayani
 46 * 
 47 */
 48public class SendRoutingInfoForLCSRequestIndicationImpl extends LsmMessageImpl implements SendRoutingInfoForLCSRequestIndication {
 49
 50	private static final int _TAG_MLC_NUMBER = 0;
 51	private static final int _TAG_TARGET_MS = 1;
 52	private static final int _TAG_EXTENSION_CONTAINER = 2;
 53
 54	private MAPExtensionContainer extensionContainer = null;
 55	private SubscriberIdentity targetMS = null;
 56	private ISDNAddressString mlcNumber = null;
 57
 58	/**
 59	 * 
 60	 */
 61	public SendRoutingInfoForLCSRequestIndicationImpl() {
 62		super();
 63	}
 64
 65	/**
 66	 * @param targetMS
 67	 * @param mlcNumber
 68	 */
 69	public SendRoutingInfoForLCSRequestIndicationImpl(ISDNAddressString mlcNumber, SubscriberIdentity targetMS) {
 70		super();
 71		this.targetMS = targetMS;
 72		this.mlcNumber = mlcNumber;
 73	}
 74
 75	/**
 76	 * @param extensionContainer
 77	 * @param targetMS
 78	 * @param mlcNumber
 79	 */
 80	public SendRoutingInfoForLCSRequestIndicationImpl(ISDNAddressString mlcNumber, SubscriberIdentity targetMS, MAPExtensionContainer extensionContainer) {
 81		this(mlcNumber, targetMS);
 82		this.extensionContainer = extensionContainer;
 83	}
 84
 85	@Override
 86	public MAPMessageType getMessageType() {
 87		return MAPMessageType.sendRoutingInfoForLCS_Request;
 88	}
 89
 90	@Override
 91	public int getOperationCode() {
 92		return MAPOperationCode.sendRoutingInfoForLCS;
 93	}
 94
 95	/*
 96	 * (non-Javadoc)
 97	 * 
 98	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.
 99	 * SendRoutingInforForLCSRequestIndication#getMLCNumber()
100	 */
101	@Override
102	public ISDNAddressString getMLCNumber() {
103		return this.mlcNumber;
104	}
105
106	/*
107	 * (non-Javadoc)
108	 * 
109	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.
110	 * SendRoutingInforForLCSRequestIndication#getTargetMS()
111	 */
112	@Override
113	public SubscriberIdentity getTargetMS() {
114		return this.targetMS;
115	}
116
117	/*
118	 * (non-Javadoc)
119	 * 
120	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.
121	 * SendRoutingInforForLCSRequestIndication#getExtensionContainer()
122	 */
123	@Override
124	public MAPExtensionContainer getExtensionContainer() {
125		return this.extensionContainer;
126	}
127
128	/*
129	 * (non-Javadoc)
130	 * 
131	 * @see
132	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTag()
133	 */
134	@Override
135	public int getTag() throws MAPException {
136		return Tag.SEQUENCE;
137	}
138
139	/*
140	 * (non-Javadoc)
141	 * 
142	 * @see
143	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTagClass
144	 * ()
145	 */
146	@Override
147	public int getTagClass() {
148		return Tag.CLASS_UNIVERSAL;
149	}
150
151	/*
152	 * (non-Javadoc)
153	 * 
154	 * @see
155	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getIsPrimitive
156	 * ()
157	 */
158	@Override
159	public boolean getIsPrimitive() {
160		return false;
161	}
162
163	/*
164	 * (non-Javadoc)
165	 * 
166	 * @see
167	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeAll
168	 * (org.mobicents.protocols.asn.AsnInputStream)
169	 */
170	@Override
171	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
172		try {
173			int length = ansIS.readLength();
174			this._decode(ansIS, length);
175		} catch (IOException e) {
176			throw new MAPParsingComponentException("IOException when decoding ProvideSubscriberLocationRequestIndication: ", e,
177					MAPParsingComponentExceptionReason.MistypedParameter);
178		} catch (AsnException e) {
179			throw new MAPParsingComponentException("AsnException when decoding ProvideSubscriberLocationRequestIndication: ", e,
180					MAPParsingComponentExceptionReason.MistypedParameter);
181		}
182	}
183
184	/*
185	 * (non-Javadoc)
186	 * 
187	 * @see
188	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeData
189	 * (org.mobicents.protocols.asn.AsnInputStream, int)
190	 */
191	@Override
192	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
193		try {
194			this._decode(ansIS, length);
195		} catch (IOException e) {
196			throw new MAPParsingComponentException("IOException when decoding ProvideSubscriberLocationRequestIndication: ", e,
197					MAPParsingComponentExceptionReason.MistypedParameter);
198		} catch (AsnException e) {
199			throw new MAPParsingComponentException("AsnException when decoding ProvideSubscriberLocationRequestIndication: ", e,
200					MAPParsingComponentExceptionReason.MistypedParameter);
201		}
202	}
203
204	private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
205
206		AsnInputStream ais = ansIS.readSequenceStreamData(length);
207
208		// mlcNumber [0] ISDN-AddressString,
209		int tag = ais.readTag();
210
211		if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive() || tag != _TAG_MLC_NUMBER) {
212			throw new MAPParsingComponentException(
213					"Error while decoding SendRoutingInforForLCSRequestIndication: Parameter [mlcNumber [0] ISDN-AddressString] bad tag class or not primitive or not Sequence",
214					MAPParsingComponentExceptionReason.MistypedParameter);
215		}
216		this.mlcNumber = new ISDNAddressStringImpl();
217		((ISDNAddressStringImpl)this.mlcNumber).decodeAll(ais);
218
219		// targetMS [1] SubscriberIdentity
220		tag = ais.readTag();
221		if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || ais.isTagPrimitive() || tag != _TAG_TARGET_MS) {
222			throw new MAPParsingComponentException(
223					"Error while decoding SendRoutingInforForLCSRequestIndication: Parameter [targetMS [1] SubscriberIdentity] bad tag class or not primitive or not Sequence",
224					MAPParsingComponentExceptionReason.MistypedParameter);
225		}
226
227		int length1 = ais.readLength();
228		tag = ais.readTag();
229
230		this.targetMS = new SubscriberIdentityImpl();
231		((SubscriberIdentityImpl)this.targetMS).decodeAll(ais);
232
233		while (true) {
234			if (ais.available() == 0)
235				break;
236
237			tag = ais.readTag();
238
239			switch (tag) {
240			case _TAG_EXTENSION_CONTAINER:
241				if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
242					throw new MAPParsingComponentException(
243							"Error while decoding SendRoutingInforForLCSRequestIndication: Parameter [extensionContainer [2] ExtensionContainer] bad tag class or not primitive or not Sequence",
244							MAPParsingComponentExceptionReason.MistypedParameter);
245				}
246				this.extensionContainer = new MAPExtensionContainerImpl();
247				((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
248				break;
249			default:
250				// DO we care?
251				ais.advanceElement();
252				break;
253			}
254		}
255	}
256
257	/*
258	 * (non-Javadoc)
259	 * 
260	 * @see
261	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
262	 * (org.mobicents.protocols.asn.AsnOutputStream)
263	 */
264	@Override
265	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
266		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
267	}
268
269	/*
270	 * (non-Javadoc)
271	 * 
272	 * @see
273	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
274	 * (org.mobicents.protocols.asn.AsnOutputStream, int, int)
275	 */
276	@Override
277	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
278		try {
279			asnOs.writeTag(tagClass, false, tag);
280			int pos = asnOs.StartContentDefiniteLength();
281			this.encodeData(asnOs);
282			asnOs.FinalizeContent(pos);
283		} catch (AsnException e) {
284			throw new MAPException("AsnException when encoding MWStatus: " + e.getMessage(), e);
285		}
286	}
287
288	/*
289	 * (non-Javadoc)
290	 * 
291	 * @see
292	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeData
293	 * (org.mobicents.protocols.asn.AsnOutputStream)
294	 */
295	@Override
296	public void encodeData(AsnOutputStream asnOs) throws MAPException {
297		if (this.mlcNumber == null) {
298			throw new MAPException(
299					"Encoding of SendRoutingInforForLCSRequestIndication failed. Manadatory parameter mlcNumber [0] ISDN-AddressString is not set");
300		}
301
302		if (this.targetMS == null) {
303			throw new MAPException(
304					"Encoding of SendRoutingInforForLCSRequestIndication failed. Manadatory parameter targetMS [1] SubscriberIdentity is not set");
305		}
306
307		((ISDNAddressStringImpl)this.mlcNumber).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_MLC_NUMBER);
308
309		try {
310			asnOs.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false, _TAG_TARGET_MS);
311		} catch (AsnException e) {
312			throw new MAPException("AsnException while encoding parameter targetMS [1] SubscriberIdentity");
313		}
314
315		int pos = asnOs.StartContentDefiniteLength();
316		((SubscriberIdentityImpl)this.targetMS).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, ((SubscriberIdentityImpl)this.targetMS).getTag());
317		asnOs.FinalizeContent(pos);
318
319		if (this.extensionContainer != null) {
320			((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_EXTENSION_CONTAINER);
321		}
322	}
323
324}