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

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

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