PageRenderTime 41ms CodeModel.GetById 10ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/subscriberInformation/LocationInformationImpl.java

http://mobicents.googlecode.com/
Java | 414 lines | 307 code | 58 blank | 49 comment | 27 complexity | a1e969c427f8233e4dd3814c4623b2ed 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.subscriberInformation;
 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.CellGlobalIdOrServiceAreaIdOrLAI;
 35import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
 36import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
 37import org.mobicents.protocols.ss7.map.api.service.subscriberInformation.GeodeticInformation;
 38import org.mobicents.protocols.ss7.map.api.service.subscriberInformation.GeographicalInformation;
 39import org.mobicents.protocols.ss7.map.api.service.subscriberInformation.LSAIdentity;
 40import org.mobicents.protocols.ss7.map.api.service.subscriberInformation.LocationInformation;
 41import org.mobicents.protocols.ss7.map.api.service.subscriberInformation.LocationInformationEPS;
 42import org.mobicents.protocols.ss7.map.api.service.subscriberInformation.LocationNumberMap;
 43import org.mobicents.protocols.ss7.map.api.service.subscriberInformation.UserCSGInformation;
 44import org.mobicents.protocols.ss7.map.primitives.CellGlobalIdOrServiceAreaIdOrLAIImpl;
 45import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
 46import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
 47
 48/**
 49 * 
 50 * @author sergey vetyutnev
 51 * 
 52 */
 53public class LocationInformationImpl implements LocationInformation, MAPAsnPrimitive {
 54
 55	public static final int _ID_geographicalInformation = 0;
 56	public static final int _ID_vlr_number = 1;
 57	public static final int _ID_locationNumber = 2;
 58	public static final int _ID_cellGlobalIdOrServiceAreaIdOrLAI = 3;
 59	public static final int _ID_extensionContainer = 4;
 60	public static final int _ID_selectedLSA_Id = 5;
 61	public static final int _ID_msc_Number = 6;
 62	public static final int _ID_geodeticInformation = 7;
 63	public static final int _ID_currentLocationRetrieved = 8;
 64	public static final int _ID_sai_Present = 9;
 65	public static final int _ID_locationInformationEPS = 10;
 66	public static final int _ID_userCSGInformation = 11;	
 67
 68	public static final String _PrimitiveName = "LocationInformation";
 69	
 70	private Integer ageOfLocationInformation;
 71	private GeographicalInformation geographicalInformation;
 72	private ISDNAddressString vlrNumber;
 73	private LocationNumberMap locationNumber;
 74	private CellGlobalIdOrServiceAreaIdOrLAI cellGlobalIdOrServiceAreaIdOrLAI;
 75	private MAPExtensionContainer extensionContainer;
 76	private LSAIdentity selectedLSAId;
 77	private ISDNAddressString mscNumber;
 78	private GeodeticInformation geodeticInformation;
 79	private boolean currentLocationRetrieved;
 80	private boolean saiPresent;
 81	private LocationInformationEPS locationInformationEPS;
 82	private UserCSGInformation userCSGInformation;
 83
 84	
 85	public LocationInformationImpl() {
 86	}
 87
 88	public LocationInformationImpl(Integer ageOfLocationInformation, GeographicalInformation geographicalInformation, ISDNAddressString vlrNumber,
 89			LocationNumberMap locationNumber, CellGlobalIdOrServiceAreaIdOrLAI cellGlobalIdOrServiceAreaIdOrLAI, MAPExtensionContainer extensionContainer,
 90			LSAIdentity selectedLSAId, ISDNAddressString mscNumber, GeodeticInformation geodeticInformation, boolean currentLocationRetrieved,
 91			boolean saiPresent, LocationInformationEPS locationInformationEPS, UserCSGInformation userCSGInformation) {
 92		this.ageOfLocationInformation = ageOfLocationInformation;
 93		this.geographicalInformation = geographicalInformation;
 94		this.vlrNumber = vlrNumber;
 95		this.locationNumber = locationNumber;
 96		this.cellGlobalIdOrServiceAreaIdOrLAI = cellGlobalIdOrServiceAreaIdOrLAI;
 97		this.extensionContainer = extensionContainer;
 98		this.selectedLSAId = selectedLSAId;
 99		this.mscNumber = mscNumber;
100		this.geodeticInformation = geodeticInformation;
101		this.currentLocationRetrieved = currentLocationRetrieved;
102		this.saiPresent = saiPresent;
103		this.locationInformationEPS = locationInformationEPS;
104		this.userCSGInformation = userCSGInformation;
105	}
106	
107	@Override
108	public Integer getAgeOfLocationInformation() {
109		return this.ageOfLocationInformation;
110	}
111
112	@Override
113	public GeographicalInformation getGeographicalInformation() {
114		return this.geographicalInformation;
115	}
116
117	@Override
118	public ISDNAddressString getVlrNumber() {
119		return this.vlrNumber;
120	}
121
122	@Override
123	public LocationNumberMap getLocationNumber() {
124		return locationNumber;
125	}
126
127	@Override
128	public CellGlobalIdOrServiceAreaIdOrLAI getCellGlobalIdOrServiceAreaIdOrLAI() {
129		return cellGlobalIdOrServiceAreaIdOrLAI;
130	}
131
132	@Override
133	public MAPExtensionContainer getExtensionContainer() {
134		return extensionContainer;
135	}
136
137	@Override
138	public LSAIdentity getSelectedLSAId() {
139		return selectedLSAId;
140	}
141
142	@Override
143	public ISDNAddressString getMscNumber() {
144		return mscNumber;
145	}
146
147	@Override
148	public GeodeticInformation getGeodeticInformation() {
149		return geodeticInformation;
150	}
151
152	@Override
153	public boolean getCurrentLocationRetrieved() {
154		return currentLocationRetrieved;
155	}
156
157	@Override
158	public boolean getSaiPresent() {
159		return saiPresent;
160	}
161
162	@Override
163	public LocationInformationEPS getLocationInformationEPS() {
164		return locationInformationEPS;
165	}
166
167	@Override
168	public UserCSGInformation getUserCSGInformation() {
169		return userCSGInformation;
170	}
171
172	
173	@Override
174	public int getTag() throws MAPException {
175		return Tag.SEQUENCE;
176	}
177
178	@Override
179	public int getTagClass() {
180		return Tag.CLASS_UNIVERSAL;
181	}
182
183	@Override
184	public boolean getIsPrimitive() {
185		return false;
186	}
187
188	@Override
189	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
190
191		try {
192			int length = ansIS.readLength();
193			this._decode(ansIS, length);
194		} catch (IOException e) {
195			throw new MAPParsingComponentException("IOException when decoding " + _PrimitiveName + ": " + e.getMessage(), e,
196					MAPParsingComponentExceptionReason.MistypedParameter);
197		} catch (AsnException e) {
198			throw new MAPParsingComponentException("AsnException when decoding " + _PrimitiveName + ": " + e.getMessage(), e,
199					MAPParsingComponentExceptionReason.MistypedParameter);
200		}
201	}
202
203	@Override
204	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
205
206		try {
207			this._decode(ansIS, length);
208		} catch (IOException e) {
209			throw new MAPParsingComponentException("IOException when decoding " + _PrimitiveName + ": " + e.getMessage(), e,
210					MAPParsingComponentExceptionReason.MistypedParameter);
211		} catch (AsnException e) {
212			throw new MAPParsingComponentException("AsnException when decoding " + _PrimitiveName + ": " + e.getMessage(), e,
213					MAPParsingComponentExceptionReason.MistypedParameter);
214		}
215	}
216
217	private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
218		
219		this.ageOfLocationInformation = null;
220		this.geographicalInformation = null;
221		this.vlrNumber = null;
222		this.locationNumber = null;
223		this.cellGlobalIdOrServiceAreaIdOrLAI = null;
224		this.extensionContainer = null;
225		this.selectedLSAId = null;
226		this.mscNumber = null;
227		this.geodeticInformation = null;
228		this.currentLocationRetrieved = false;
229		this.saiPresent = false;
230		this.locationInformationEPS = null;
231		this.userCSGInformation = null;
232		
233		AsnInputStream ais = ansIS.readSequenceStreamData(length);
234		
235		while( true ) {
236			if( ais.available()==0 )
237				break;
238			
239			int tag = ais.readTag();
240			
241			// optional parameters
242			if (ais.getTagClass() == Tag.CLASS_UNIVERSAL) {
243
244				switch (tag) {
245				case Tag.INTEGER: // AgeOfLocationInformation
246					this.ageOfLocationInformation = (int) ais.readInteger();
247					break;
248
249				default:
250					ais.advanceElement();
251					break;
252				}
253			} else if (ais.getTagClass() == Tag.CLASS_CONTEXT_SPECIFIC) {
254
255				switch (tag) {
256				case _ID_geographicalInformation:
257					ais.advanceElement(); // TODO: implement it
258					break;
259				case _ID_vlr_number:
260					this.vlrNumber = new ISDNAddressStringImpl();
261					((ISDNAddressStringImpl) this.vlrNumber).decodeAll(ais);
262					break;
263				case _ID_locationNumber:
264					this.locationNumber = new LocationNumberMapImpl();
265					((LocationNumberMapImpl) this.locationNumber).decodeAll(ais);
266					break;
267				case _ID_cellGlobalIdOrServiceAreaIdOrLAI:
268					this.cellGlobalIdOrServiceAreaIdOrLAI = new CellGlobalIdOrServiceAreaIdOrLAIImpl();
269					AsnInputStream ais2 = ais.readSequenceStream();
270					ais2.readTag();
271					((CellGlobalIdOrServiceAreaIdOrLAIImpl) this.cellGlobalIdOrServiceAreaIdOrLAI).decodeAll(ais2);
272					break;
273				case _ID_extensionContainer:
274					ais.advanceElement(); // TODO: implement it
275					break;
276				case _ID_selectedLSA_Id:
277					ais.advanceElement(); // TODO: implement it
278					break;
279				case _ID_msc_Number:
280					ais.advanceElement(); // TODO: implement it
281					break;
282				case _ID_geodeticInformation:
283					ais.advanceElement(); // TODO: implement it
284					break;
285				case _ID_currentLocationRetrieved:
286					ais.advanceElement(); // TODO: implement it
287					break;
288				case _ID_sai_Present:
289					ais.advanceElement(); // TODO: implement it
290					break;
291				case _ID_locationInformationEPS:
292					ais.advanceElement(); // TODO: implement it
293					break;
294				case _ID_userCSGInformation:
295					ais.advanceElement(); // TODO: implement it
296					break;
297					
298				default:
299					ais.advanceElement();
300					break;
301				}
302			} else {
303				ais.advanceElement();
304			}
305		}
306	}
307
308	@Override
309	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
310
311		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, this.getTag());
312	}
313
314	@Override
315	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
316		
317		try {
318			asnOs.writeTag(tagClass, true, tag);
319			int pos = asnOs.StartContentDefiniteLength();
320			this.encodeData(asnOs);
321			asnOs.FinalizeContent(pos);
322		} catch (AsnException e) {
323			throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
324		}
325	}
326
327	@Override
328	public void encodeData(AsnOutputStream asnOs) throws MAPException {
329
330		try {
331			if (ageOfLocationInformation != null)
332				asnOs.writeInteger((int) ageOfLocationInformation);
333
334			// TODO: implement unimplemented members
335			// private GeographicalInformation geographicalInformation;
336			
337			if (vlrNumber != null)
338				((ISDNAddressStringImpl) vlrNumber).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_vlr_number);
339			if (locationNumber != null)
340				((LocationNumberMapImpl) locationNumber).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_locationNumber);
341			if (cellGlobalIdOrServiceAreaIdOrLAI != null) {
342				try {
343					asnOs.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false, _ID_cellGlobalIdOrServiceAreaIdOrLAI);
344					int pos = asnOs.StartContentDefiniteLength();
345					((CellGlobalIdOrServiceAreaIdOrLAIImpl) this.cellGlobalIdOrServiceAreaIdOrLAI).encodeAll(asnOs);
346					asnOs.FinalizeContent(pos);
347				} catch (AsnException e) {
348					throw new MAPException("AsnException while encoding parameter cellGlobalIdOrServiceAreaIdOrLAI", e);
349				}
350			}
351
352			// TODO: implement unimplemented members
353			// private MAPExtensionContainer extensionContainer;
354			// private LSAIdentity selectedLSAId;
355			// private ISDNAddressString mscNumber;
356			// private GeodeticInformation geodeticInformation;
357			// private boolean currentLocationRetrieved;
358			// private boolean saiPresent;
359			// private LocationInformationEPS locationInformationEPS;
360			// private UserCSGInformation userCSGInformation;
361			
362		} catch (IOException e) {
363			throw new MAPException("IOException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
364		} catch (AsnException e) {
365			throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
366		}
367	}
368	
369	@Override
370	public String toString() {
371		StringBuilder sb = new StringBuilder();
372		sb.append("LocationInformation [");
373
374		if (this.ageOfLocationInformation != null) {
375			sb.append("ageOfLocationInformation=");
376			sb.append(this.ageOfLocationInformation);
377		}
378
379		// TODO: implement unimplemented members
380		// private GeographicalInformation geographicalInformation;
381
382		if (this.vlrNumber != null) {
383			sb.append(", vlrNumber=");
384			sb.append(this.vlrNumber.toString());
385		}
386		if (this.locationNumber != null) {
387			sb.append(", locationNumber=");
388			sb.append(this.locationNumber.toString());
389		}
390		if (this.cellGlobalIdOrServiceAreaIdOrLAI != null) {
391			sb.append(", cellGlobalIdOrServiceAreaIdOrLAI=[");
392			sb.append(this.cellGlobalIdOrServiceAreaIdOrLAI.toString());
393			sb.append("]");
394		}
395		if (this.extensionContainer != null) {
396			sb.append(", extensionContainer=");
397			sb.append(this.extensionContainer.toString());
398		}
399
400		// TODO: implement unimplemented members
401		// private MAPExtensionContainer extensionContainer;
402		// private LSAIdentity selectedLSAId;
403		// private ISDNAddressString mscNumber;
404		// private GeodeticInformation geodeticInformation;
405		// private boolean currentLocationRetrieved;
406		// private boolean saiPresent;
407		// private LocationInformationEPS locationInformationEPS;
408		// private UserCSGInformation userCSGInformation;
409
410		sb.append("]");
411
412		return sb.toString();
413	}
414}