PageRenderTime 105ms CodeModel.GetById 86ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 403 lines | 240 code | 32 blank | 131 comment | 64 complexity | 10cf5f4d015b11a0ba43ec3cbe8a4828 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.MAPExtensionContainer;
 35import org.mobicents.protocols.ss7.map.api.service.lsm.LCSQoS;
 36import org.mobicents.protocols.ss7.map.api.service.lsm.ResponseTime;
 37import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
 38import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
 39
 40/**
 41 * TODO introduce all params used by LCSQoS and test
 42 * 
 43 * @author amit bhayani
 44 * 
 45 */
 46public class LCSQoSImpl implements LCSQoS, MAPAsnPrimitive {
 47
 48	private static final int _TAG_HORIZONTAL_ACCURACY = 0;
 49	private static final int _TAG_VERTICAL_COORDINATE_REQUEST = 1;
 50	private static final int _TAG_VERTICAL_ACCURACY = 2;
 51	private static final int _TAG_RESPONSE_TIME = 3;
 52	private static final int _TAG_EXTENSION_CONTAINER = 4;
 53
 54	private Integer horizontalAccuracy = null;
 55	private Integer verticalAccuracy = null;
 56	private Boolean verticalCoordinateRequest = false;
 57	private ResponseTime responseTime = null;
 58	private MAPExtensionContainer extensionContainer = null;
 59
 60	/**
 61	 * 
 62	 */
 63	public LCSQoSImpl() {
 64		super();
 65	}
 66
 67	/**
 68	 * @param horizontalAccuracy
 69	 * @param verticalAccuracy
 70	 * @param verticalCoordinateRequest
 71	 * @param responseTime
 72	 * @param extensionContainer
 73	 */
 74	public LCSQoSImpl(Integer horizontalAccuracy, Integer verticalAccuracy, Boolean verticalCoordinateRequest, ResponseTime responseTime,
 75			MAPExtensionContainer extensionContainer) {
 76		super();
 77		this.horizontalAccuracy = horizontalAccuracy;
 78		this.verticalAccuracy = verticalAccuracy;
 79		this.verticalCoordinateRequest = verticalCoordinateRequest;
 80		this.responseTime = responseTime;
 81		this.extensionContainer = extensionContainer;
 82	}
 83
 84	/*
 85	 * (non-Javadoc)
 86	 * 
 87	 * @see
 88	 * org.mobicents.protocols.ss7.map.api.service.lsm.LCSQoS#getHorizontalAccuracy
 89	 * ()
 90	 */
 91	@Override
 92	public Integer getHorizontalAccuracy() {
 93		return this.horizontalAccuracy;
 94	}
 95
 96	/*
 97	 * (non-Javadoc)
 98	 * 
 99	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.LCSQoS#
100	 * getVerticalCoordinateRequest()
101	 */
102	@Override
103	public Boolean getVerticalCoordinateRequest() {
104		return this.verticalCoordinateRequest;
105	}
106
107	/*
108	 * (non-Javadoc)
109	 * 
110	 * @see
111	 * org.mobicents.protocols.ss7.map.api.service.lsm.LCSQoS#getVerticalAccuracy
112	 * ()
113	 */
114	@Override
115	public Integer getVerticalAccuracy() {
116		return this.verticalAccuracy;
117	}
118
119	/*
120	 * (non-Javadoc)
121	 * 
122	 * @see
123	 * org.mobicents.protocols.ss7.map.api.service.lsm.LCSQoS#getResponseTime()
124	 */
125	@Override
126	public ResponseTime getResponseTime() {
127		return this.responseTime;
128	}
129
130	/*
131	 * (non-Javadoc)
132	 * 
133	 * @see
134	 * org.mobicents.protocols.ss7.map.api.service.lsm.LCSQoS#getExtensionContainer
135	 * ()
136	 */
137	@Override
138	public MAPExtensionContainer getExtensionContainer() {
139		return this.extensionContainer;
140	}
141
142	/*
143	 * (non-Javadoc)
144	 * 
145	 * @see
146	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTag()
147	 */
148	@Override
149	public int getTag() throws MAPException {
150		return Tag.SEQUENCE;
151	}
152
153	/*
154	 * (non-Javadoc)
155	 * 
156	 * @see
157	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTagClass
158	 * ()
159	 */
160	@Override
161	public int getTagClass() {
162		return Tag.CLASS_CONTEXT_SPECIFIC;
163	}
164
165	/*
166	 * (non-Javadoc)
167	 * 
168	 * @see
169	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getIsPrimitive
170	 * ()
171	 */
172	@Override
173	public boolean getIsPrimitive() {
174		return false;
175	}
176
177	/*
178	 * (non-Javadoc)
179	 * 
180	 * @see
181	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeAll
182	 * (org.mobicents.protocols.asn.AsnInputStream)
183	 */
184	@Override
185	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
186		try {
187			int length = ansIS.readLength();
188			this._decode(ansIS, length);
189		} catch (IOException e) {
190			throw new MAPParsingComponentException("IOException when decoding MWStatus: " + e.getMessage(), e,
191					MAPParsingComponentExceptionReason.MistypedParameter);
192		} catch (AsnException e) {
193			throw new MAPParsingComponentException("AsnException when decoding MWStatus: " + e.getMessage(), e,
194					MAPParsingComponentExceptionReason.MistypedParameter);
195		}
196	}
197
198	/*
199	 * (non-Javadoc)
200	 * 
201	 * @see
202	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeData
203	 * (org.mobicents.protocols.asn.AsnInputStream, int)
204	 */
205	@Override
206	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
207		try {
208			this._decode(ansIS, length);
209		} catch (IOException e) {
210			throw new MAPParsingComponentException("IOException when decoding MWStatus: " + e.getMessage(), e,
211					MAPParsingComponentExceptionReason.MistypedParameter);
212		} catch (AsnException e) {
213			throw new MAPParsingComponentException("AsnException when decoding MWStatus: " + e.getMessage(), e,
214					MAPParsingComponentExceptionReason.MistypedParameter);
215		}
216	}
217
218	private void _decode(AsnInputStream asnIS, int length) throws MAPParsingComponentException, IOException, AsnException {
219		AsnInputStream ais = asnIS.readSequenceStreamData(length);
220
221		while (true) {
222			if (ais.available() == 0)
223				break;
224
225			switch (ais.readTag()) {
226			case _TAG_HORIZONTAL_ACCURACY:
227				// horizontal-accuracy [0] Horizontal-Accuracy OPTIONAL,
228				if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
229					throw new MAPParsingComponentException(
230							"Decoding LCSQoS failed. Error while decoding horizontal-accuracy [0] Horizontal-Accuracy: bad tag class or not primitive",
231							MAPParsingComponentExceptionReason.MistypedParameter);
232				}
233				int length1 = ais.readLength();
234				this.horizontalAccuracy = new Integer(ais.readOctetStringData(length1)[0]);
235				break;
236			case _TAG_VERTICAL_COORDINATE_REQUEST:
237				// verticalCoordinateRequest [1] NULL OPTIONAL,
238				length1 = ais.readLength();
239				this.verticalCoordinateRequest = true;
240				break;
241			case _TAG_VERTICAL_ACCURACY:
242				// vertical-accuracy [2] Vertical-Accuracy OPTIONAL,
243				if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
244					throw new MAPParsingComponentException(
245							"Decoding LCSQoS failed. Error while decoding vertical-accuracy [2] Vertical-Accuracy: bad tag class or not primitive",
246							MAPParsingComponentExceptionReason.MistypedParameter);
247				}
248				length1 = ais.readLength();
249				this.verticalAccuracy = new Integer(ais.readOctetStringData(length1)[0]);
250				break;
251			case _TAG_RESPONSE_TIME:
252				// responseTime [3] ResponseTime OPTIONAL,
253				if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || ais.isTagPrimitive()) {
254					throw new MAPParsingComponentException(
255							"Decoding LCSQoS failed. Error while decoding responseTime [3] ResponseTime: bad tag class, tag or not constructed",
256							MAPParsingComponentExceptionReason.MistypedParameter);
257				}
258				this.responseTime = new ResponseTimeImpl();
259				((ResponseTimeImpl)this.responseTime).decodeAll(ais);
260				break;
261			case _TAG_EXTENSION_CONTAINER:
262				// extensionContainer [4] ExtensionContainer OPTIONAL
263
264				this.extensionContainer = new MAPExtensionContainerImpl();
265				((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
266				break;
267			default:
268				// Do we care?
269				ais.advanceElement();
270				break;
271			}
272		}// while
273	}
274
275	/*
276	 * (non-Javadoc)
277	 * 
278	 * @see
279	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
280	 * (org.mobicents.protocols.asn.AsnOutputStream)
281	 */
282	@Override
283	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
284		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
285	}
286
287	/*
288	 * (non-Javadoc)
289	 * 
290	 * @see
291	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
292	 * (org.mobicents.protocols.asn.AsnOutputStream, int, int)
293	 */
294	@Override
295	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
296		try {
297			asnOs.writeTag(tagClass, false, tag);
298			int pos = asnOs.StartContentDefiniteLength();
299			this.encodeData(asnOs);
300			asnOs.FinalizeContent(pos);
301		} catch (AsnException e) {
302			throw new MAPException("AsnException when encoding InformServiceCentreRequest: " + e.getMessage(), e);
303		}
304	}
305
306	/*
307	 * (non-Javadoc)
308	 * 
309	 * @see
310	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeData
311	 * (org.mobicents.protocols.asn.AsnOutputStream)
312	 */
313	@Override
314	public void encodeData(AsnOutputStream asnOs) throws MAPException {
315		if (this.horizontalAccuracy != null) {
316			try {
317				asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_HORIZONTAL_ACCURACY, new byte[] { this.horizontalAccuracy.byteValue() });
318			} catch (IOException e) {
319				throw new MAPException("IOException when encoding parameter horizontalAccuracy: ", e);
320			} catch (AsnException e) {
321				throw new MAPException("AsnException when encoding parameter horizontalAccuracy: ", e);
322			}
323		}
324
325		if (this.verticalCoordinateRequest != null) {
326			try {
327				asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_VERTICAL_COORDINATE_REQUEST);
328			} catch (IOException e) {
329				throw new MAPException("IOException when encoding parameter verticalCoordinateRequest: ", e);
330			} catch (AsnException e) {
331				throw new MAPException("IOException when encoding parameter verticalCoordinateRequest: ", e);
332			}
333		}
334
335		if (this.verticalAccuracy != null) {
336			try {
337				asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_VERTICAL_ACCURACY, new byte[] { this.verticalAccuracy.byteValue() });
338			} catch (IOException e) {
339				throw new MAPException("IOException when encoding parameter verticalAccuracy: ", e);
340			} catch (AsnException e) {
341				throw new MAPException("AsnException when encoding parameter verticalAccuracy: ", e);
342			}
343		}
344
345		if (this.responseTime != null) {
346			((ResponseTimeImpl)this.responseTime).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_RESPONSE_TIME);
347		}
348
349		if (this.extensionContainer != null) {
350			((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_EXTENSION_CONTAINER);
351		}
352	}
353
354	@Override
355	public int hashCode() {
356		final int prime = 31;
357		int result = 1;
358		result = prime * result + ((extensionContainer == null) ? 0 : extensionContainer.hashCode());
359		result = prime * result + ((horizontalAccuracy == null) ? 0 : horizontalAccuracy.hashCode());
360		result = prime * result + ((responseTime == null) ? 0 : responseTime.hashCode());
361		result = prime * result + ((verticalAccuracy == null) ? 0 : verticalAccuracy.hashCode());
362		result = prime * result + ((verticalCoordinateRequest == null) ? 0 : verticalCoordinateRequest.hashCode());
363		return result;
364	}
365
366	@Override
367	public boolean equals(Object obj) {
368		if (this == obj)
369			return true;
370		if (obj == null)
371			return false;
372		if (getClass() != obj.getClass())
373			return false;
374		LCSQoSImpl other = (LCSQoSImpl) obj;
375		if (extensionContainer == null) {
376			if (other.extensionContainer != null)
377				return false;
378		} else if (!extensionContainer.equals(other.extensionContainer))
379			return false;
380		if (horizontalAccuracy == null) {
381			if (other.horizontalAccuracy != null)
382				return false;
383		} else if (!horizontalAccuracy.equals(other.horizontalAccuracy))
384			return false;
385		if (responseTime == null) {
386			if (other.responseTime != null)
387				return false;
388		} else if (!responseTime.equals(other.responseTime))
389			return false;
390		if (verticalAccuracy == null) {
391			if (other.verticalAccuracy != null)
392				return false;
393		} else if (!verticalAccuracy.equals(other.verticalAccuracy))
394			return false;
395		if (verticalCoordinateRequest == null) {
396			if (other.verticalCoordinateRequest != null)
397				return false;
398		} else if (!verticalCoordinateRequest.equals(other.verticalCoordinateRequest))
399			return false;
400		return true;
401	}
402
403}