PageRenderTime 36ms CodeModel.GetById 12ms app.highlight 18ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 228 lines | 139 code | 24 blank | 65 comment | 20 complexity | 8a9c3b1976a29fee57d350c3f95128c6 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.DeferredLocationEventType;
 35import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
 36
 37/**
 38 * @author amit bhayani
 39 *
 40 */
 41public class DeferredLocationEventTypeImpl implements DeferredLocationEventType, MAPAsnPrimitive {
 42	
 43	private static final int _INDEX_MS_AVAILABLE = 0;
 44	private static final int _INDEX__ENTERING_INTO_AREA = 1;
 45	private static final int _INDEX_LEAVING_FROM_AREA = 2;
 46	private static final int _INDEX_BEING_INSIDE_AREA = 3;
 47	
 48	//TODO : Is this correct?
 49	private BitSetStrictLength bitString = new BitSetStrictLength(4);
 50	
 51	/**
 52	 * 
 53	 */
 54	public DeferredLocationEventTypeImpl() {
 55		super();
 56	}
 57	
 58	public DeferredLocationEventTypeImpl(boolean msAvailable, boolean enteringIntoArea, boolean leavingFromArea, boolean beingInsideArea) {
 59		if (msAvailable)
 60			this.bitString.set(_INDEX_MS_AVAILABLE);
 61		if (enteringIntoArea)
 62			this.bitString.set(_INDEX__ENTERING_INTO_AREA);
 63		if (leavingFromArea)
 64			this.bitString.set(_INDEX_LEAVING_FROM_AREA);
 65		if (beingInsideArea)
 66			this.bitString.set(_INDEX_BEING_INSIDE_AREA);	
 67		}
 68
 69	/* (non-Javadoc)
 70	 * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTag()
 71	 */
 72	@Override
 73	public int getTag() throws MAPException {
 74		return Tag.STRING_BIT;
 75	}
 76
 77	/* (non-Javadoc)
 78	 * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTagClass()
 79	 */
 80	@Override
 81	public int getTagClass() {
 82		return Tag.CLASS_UNIVERSAL;
 83	}
 84
 85	/* (non-Javadoc)
 86	 * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getIsPrimitive()
 87	 */
 88	@Override
 89	public boolean getIsPrimitive() {
 90		return true;
 91	}
 92
 93	/* (non-Javadoc)
 94	 * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeAll(org.mobicents.protocols.asn.AsnInputStream)
 95	 */
 96	@Override
 97	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
 98		try {
 99			int length = ansIS.readLength();
100			this._decode(ansIS, length);
101		} catch (IOException e) {
102			throw new MAPParsingComponentException("IOException when decoding MWStatus: " + e.getMessage(), e,
103					MAPParsingComponentExceptionReason.MistypedParameter);
104		} catch (AsnException e) {
105			throw new MAPParsingComponentException("AsnException when decoding MWStatus: " + e.getMessage(), e,
106					MAPParsingComponentExceptionReason.MistypedParameter);
107		}
108	}
109
110	/* (non-Javadoc)
111	 * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeData(org.mobicents.protocols.asn.AsnInputStream, int)
112	 */
113	@Override
114	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
115		try {
116			this._decode(ansIS, length);
117		} catch (IOException e) {
118			throw new MAPParsingComponentException("IOException when decoding MWStatus: " + e.getMessage(), e,
119					MAPParsingComponentExceptionReason.MistypedParameter);
120		} catch (AsnException e) {
121			throw new MAPParsingComponentException("AsnException when decoding MWStatus: " + e.getMessage(), e,
122					MAPParsingComponentExceptionReason.MistypedParameter);
123		}
124	}
125	
126	private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
127		if (length == 0 || length > 4)
128			throw new MAPParsingComponentException("Error decoding DeferredLocationEventType: the DeferredLocationEventType field must contain from 1 or 4 octets. Contains: " + length,
129					MAPParsingComponentExceptionReason.MistypedParameter);
130		
131		this.bitString = ansIS.readBitStringData(length);
132	}
133
134	/* (non-Javadoc)
135	 * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll(org.mobicents.protocols.asn.AsnOutputStream)
136	 */
137	@Override
138	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
139		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.STRING_BIT);
140	}
141
142	/* (non-Javadoc)
143	 * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll(org.mobicents.protocols.asn.AsnOutputStream, int, int)
144	 */
145	@Override
146	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
147		try {
148			asnOs.writeTag(tagClass, true, tag);
149			int pos = asnOs.StartContentDefiniteLength();
150			this.encodeData(asnOs);
151			asnOs.FinalizeContent(pos);
152		} catch (AsnException e) {
153			throw new MAPException("AsnException when encoding MWStatus: " + e.getMessage(), e);
154		}
155	}
156
157	/* (non-Javadoc)
158	 * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeData(org.mobicents.protocols.asn.AsnOutputStream)
159	 */
160	@Override
161	public void encodeData(AsnOutputStream asnOs) throws MAPException {
162		try {
163			asnOs.writeBitStringData(this.bitString);
164		} catch (IOException e) {
165			throw new MAPException("IOException when encoding MWStatus: " + e.getMessage(), e);
166		} catch (AsnException e) {
167			throw new MAPException("AsnException when encoding MWStatus: " + e.getMessage(), e);
168		}
169	}
170
171	/* (non-Javadoc)
172	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.DeferredLocationEventType#getMsAvailable()
173	 */
174	@Override
175	public boolean getMsAvailable() {
176		return this.bitString.get(_INDEX_MS_AVAILABLE);
177	}
178
179	/* (non-Javadoc)
180	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.DeferredLocationEventType#getEnteringIntoArea()
181	 */
182	@Override
183	public boolean getEnteringIntoArea() {
184		return this.bitString.get(_INDEX__ENTERING_INTO_AREA);
185	}
186
187	/* (non-Javadoc)
188	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.DeferredLocationEventType#getLeavingFromArea()
189	 */
190	@Override
191	public boolean getLeavingFromArea() {
192		return this.bitString.get(_INDEX_LEAVING_FROM_AREA);
193	}
194
195	/* (non-Javadoc)
196	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.DeferredLocationEventType#beingInsideArea()
197	 */
198	@Override
199	public boolean getBeingInsideArea() {
200		return this.bitString.get(_INDEX_BEING_INSIDE_AREA);
201	}
202
203	@Override
204	public int hashCode() {
205		final int prime = 31;
206		int result = 1;
207		result = prime * result + ((bitString == null) ? 0 : bitString.hashCode());
208		return result;
209	}
210
211	@Override
212	public boolean equals(Object obj) {
213		if (this == obj)
214			return true;
215		if (obj == null)
216			return false;
217		if (getClass() != obj.getClass())
218			return false;
219		DeferredLocationEventTypeImpl other = (DeferredLocationEventTypeImpl) obj;
220		if (bitString == null) {
221			if (other.bitString != null)
222				return false;
223		} else if (!bitString.equals(other.bitString))
224			return false;
225		return true;
226	}
227
228}