PageRenderTime 28ms CodeModel.GetById 1ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

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