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

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

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