PageRenderTime 101ms CodeModel.GetById 89ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 314 lines | 161 code | 26 blank | 127 comment | 23 complexity | 9ebdf560f4ed7c59fe8f434c11d947f5 MD5 | raw file
  1/*
  2 * JBoss, Home of Professional Open Source
  3 * Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
  4 * contributors as indicated by the @authors tag. All rights reserved.
  5 * See the copyright.txt in the distribution for a full listing
  6 * of individual contributors.
  7 * 
  8 * This copyrighted material is made available to anyone wishing to use,
  9 * modify, copy, or redistribute it subject to the terms and conditions
 10 * of the GNU General Public License, v. 2.0.
 11 * 
 12 * This program 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 * General Public License for more details.
 16 * 
 17 * You should have received a copy of the GNU General Public License,
 18 * v. 2.0 along with this distribution; if not, write to the Free 
 19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 20 * MA 02110-1301, USA.
 21 */
 22package org.mobicents.protocols.ss7.map.service.lsm;
 23
 24import java.io.IOException;
 25
 26import org.mobicents.protocols.asn.AsnException;
 27import org.mobicents.protocols.asn.AsnInputStream;
 28import org.mobicents.protocols.asn.AsnOutputStream;
 29import org.mobicents.protocols.asn.BitSetStrictLength;
 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.service.lsm.SupportedGADShapes;
 35import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
 36
 37/**
 38 * @author amit bhayani
 39 * 
 40 */
 41public class SupportedGADShapesImpl implements SupportedGADShapes, MAPAsnPrimitive {
 42	private static final int _INDEX_ELLIPSOID_POINT = 0;
 43	private static final int _INDEX_ELLIPSOID_POINT_WITH_UNCERTAINTY_CIRCLE = 1;
 44	private static final int _INDEX_ELLIPSOID_POINT_WITH_UNCERTAINTY_ELLIPSE = 2;
 45	private static final int _INDEX_POLYGON = 3;
 46	private static final int _INDEX_ELLIPSOID_POINT_WITH_ALTITUDE = 4;
 47	private static final int _INDEX_ELLIPSOID_WITH_ALTITUDE_AND_UNCERTAINTY_ELIPSOID = 5;
 48	private static final int _INDEX_ELLIPSOID_ARC = 6;
 49
 50	// TODO : Is this correct?
 51	private BitSetStrictLength bitString = new BitSetStrictLength(7);
 52
 53	/**
 54	 * 
 55	 */
 56	public SupportedGADShapesImpl() {
 57		super();
 58	}
 59
 60	public SupportedGADShapesImpl(boolean ellipsoidPoint, boolean ellipsoidPointWithUncertaintyCircle, boolean ellipsoidPointWithUncertaintyEllipse,
 61			boolean polygon, boolean ellipsoidPointWithAltitude, boolean ellipsoidPointWithAltitudeAndUncertaintyElipsoid, boolean ellipsoidArc) {
 62		if (ellipsoidPoint)
 63			this.bitString.set(_INDEX_ELLIPSOID_POINT);
 64		if (ellipsoidPointWithUncertaintyCircle)
 65			this.bitString.set(_INDEX_ELLIPSOID_POINT_WITH_UNCERTAINTY_CIRCLE);
 66		if (ellipsoidPointWithUncertaintyEllipse)
 67			this.bitString.set(_INDEX_ELLIPSOID_POINT_WITH_UNCERTAINTY_ELLIPSE);
 68		if (polygon)
 69			this.bitString.set(_INDEX_POLYGON);
 70		if (ellipsoidPointWithAltitude)
 71			this.bitString.set(_INDEX_ELLIPSOID_POINT_WITH_ALTITUDE);
 72		if (ellipsoidPointWithAltitudeAndUncertaintyElipsoid)
 73			this.bitString.set(_INDEX_ELLIPSOID_WITH_ALTITUDE_AND_UNCERTAINTY_ELIPSOID);
 74		if (ellipsoidArc)
 75			this.bitString.set(_INDEX_ELLIPSOID_ARC);
 76	}
 77
 78	/*
 79	 * (non-Javadoc)
 80	 * 
 81	 * @see
 82	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTag()
 83	 */
 84	@Override
 85	public int getTag() throws MAPException {
 86		return Tag.STRING_BIT;
 87	}
 88
 89	/*
 90	 * (non-Javadoc)
 91	 * 
 92	 * @see
 93	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTagClass
 94	 * ()
 95	 */
 96	@Override
 97	public int getTagClass() {
 98		return Tag.CLASS_UNIVERSAL;
 99	}
100
101	/*
102	 * (non-Javadoc)
103	 * 
104	 * @see
105	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getIsPrimitive
106	 * ()
107	 */
108	@Override
109	public boolean getIsPrimitive() {
110		return true;
111	}
112
113	/*
114	 * (non-Javadoc)
115	 * 
116	 * @see
117	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeAll
118	 * (org.mobicents.protocols.asn.AsnInputStream)
119	 */
120	@Override
121	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
122		try {
123			int length = ansIS.readLength();
124			this._decode(ansIS, length);
125		} catch (IOException e) {
126			throw new MAPParsingComponentException("IOException when decoding MWStatus: " + e.getMessage(), e,
127					MAPParsingComponentExceptionReason.MistypedParameter);
128		} catch (AsnException e) {
129			throw new MAPParsingComponentException("AsnException when decoding MWStatus: " + e.getMessage(), e,
130					MAPParsingComponentExceptionReason.MistypedParameter);
131		}
132	}
133
134	/*
135	 * (non-Javadoc)
136	 * 
137	 * @see
138	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeData
139	 * (org.mobicents.protocols.asn.AsnInputStream, int)
140	 */
141	@Override
142	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
143		try {
144			this._decode(ansIS, length);
145		} catch (IOException e) {
146			throw new MAPParsingComponentException("IOException when decoding MWStatus: " + e.getMessage(), e,
147					MAPParsingComponentExceptionReason.MistypedParameter);
148		} catch (AsnException e) {
149			throw new MAPParsingComponentException("AsnException when decoding MWStatus: " + e.getMessage(), e,
150					MAPParsingComponentExceptionReason.MistypedParameter);
151		}
152	}
153
154	private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
155		if (length == 0 || length > 7)
156			throw new MAPParsingComponentException("Error decoding SupportedGADShapes: the SupportedGADShapes field must contain from 7 octets. Contains: "
157					+ length, MAPParsingComponentExceptionReason.MistypedParameter);
158
159		this.bitString = ansIS.readBitStringData(length);
160	}
161
162	/*
163	 * (non-Javadoc)
164	 * 
165	 * @see
166	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
167	 * (org.mobicents.protocols.asn.AsnOutputStream)
168	 */
169	@Override
170	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
171		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.STRING_BIT);
172	}
173
174	/*
175	 * (non-Javadoc)
176	 * 
177	 * @see
178	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
179	 * (org.mobicents.protocols.asn.AsnOutputStream, int, int)
180	 */
181	@Override
182	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
183		try {
184			asnOs.writeTag(tagClass, true, tag);
185			int pos = asnOs.StartContentDefiniteLength();
186			this.encodeData(asnOs);
187			asnOs.FinalizeContent(pos);
188		} catch (AsnException e) {
189			throw new MAPException("AsnException when encoding MWStatus: " + e.getMessage(), e);
190		}
191	}
192
193	/*
194	 * (non-Javadoc)
195	 * 
196	 * @see
197	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeData
198	 * (org.mobicents.protocols.asn.AsnOutputStream)
199	 */
200	@Override
201	public void encodeData(AsnOutputStream asnOs) throws MAPException {
202		try {
203			asnOs.writeBitStringData(this.bitString);
204		} catch (IOException e) {
205			throw new MAPException("IOException when encoding MWStatus: " + e.getMessage(), e);
206		} catch (AsnException e) {
207			throw new MAPException("AsnException when encoding MWStatus: " + e.getMessage(), e);
208		}
209	}
210
211	/*
212	 * (non-Javadoc)
213	 * 
214	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes#
215	 * getEllipsoidPoint()
216	 */
217	@Override
218	public boolean getEllipsoidPoint() {
219		return this.bitString.get(_INDEX_ELLIPSOID_POINT);
220	}
221
222	/*
223	 * (non-Javadoc)
224	 * 
225	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes#
226	 * getEllipsoidPointWithUncertaintyCircle()
227	 */
228	@Override
229	public boolean getEllipsoidPointWithUncertaintyCircle() {
230		return this.bitString.get(_INDEX_ELLIPSOID_POINT_WITH_UNCERTAINTY_CIRCLE);
231	}
232
233	/*
234	 * (non-Javadoc)
235	 * 
236	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes#
237	 * getEllipsoidPointWithUncertaintyEllipse()
238	 */
239	@Override
240	public boolean getEllipsoidPointWithUncertaintyEllipse() {
241		return this.bitString.get(_INDEX_ELLIPSOID_POINT_WITH_UNCERTAINTY_ELLIPSE);
242	}
243
244	/*
245	 * (non-Javadoc)
246	 * 
247	 * @see
248	 * org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes#getPolygon
249	 * ()
250	 */
251	@Override
252	public boolean getPolygon() {
253		return this.bitString.get(_INDEX_POLYGON);
254	}
255
256	/*
257	 * (non-Javadoc)
258	 * 
259	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes#
260	 * getEllipsoidPointWithAltitude()
261	 */
262	@Override
263	public boolean getEllipsoidPointWithAltitude() {
264		return this.bitString.get(_INDEX_ELLIPSOID_POINT_WITH_ALTITUDE);
265	}
266
267	/*
268	 * (non-Javadoc)
269	 * 
270	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes#
271	 * getEllipsoidPointWithAltitudeAndUncertaintyElipsoid()
272	 */
273	@Override
274	public boolean getEllipsoidPointWithAltitudeAndUncertaintyElipsoid() {
275		return this.bitString.get(_INDEX_ELLIPSOID_WITH_ALTITUDE_AND_UNCERTAINTY_ELIPSOID);
276	}
277
278	/*
279	 * (non-Javadoc)
280	 * 
281	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes#
282	 * getEllipsoidArc()
283	 */
284	@Override
285	public boolean getEllipsoidArc() {
286		return this.bitString.get(_INDEX_ELLIPSOID_ARC);
287	}
288
289	@Override
290	public int hashCode() {
291		final int prime = 31;
292		int result = 1;
293		result = prime * result + ((bitString == null) ? 0 : bitString.hashCode());
294		return result;
295	}
296
297	@Override
298	public boolean equals(Object obj) {
299		if (this == obj)
300			return true;
301		if (obj == null)
302			return false;
303		if (getClass() != obj.getClass())
304			return false;
305		SupportedGADShapesImpl other = (SupportedGADShapesImpl) obj;
306		if (bitString == null) {
307			if (other.bitString != null)
308				return false;
309		} else if (!bitString.equals(other.bitString))
310			return false;
311		return true;
312	}
313
314}