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

/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/sms/MWStatusImpl.java

http://mobicents.googlecode.com/
Java | 180 lines | 120 code | 34 blank | 26 comment | 7 complexity | 254ba898cbdf4f86507ac5182ffc4314 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.sms;
 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.BitSetStrictLength;
 31import org.mobicents.protocols.asn.Tag;
 32import org.mobicents.protocols.ss7.map.api.MAPException;
 33import org.mobicents.protocols.ss7.map.api.MAPParsingComponentException;
 34import org.mobicents.protocols.ss7.map.api.MAPParsingComponentExceptionReason;
 35import org.mobicents.protocols.ss7.map.api.service.sms.MWStatus;
 36import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
 37
 38/**
 39 * 
 40 * @author sergey vetyutnev
 41 * 
 42 */
 43public class MWStatusImpl implements MWStatus, MAPAsnPrimitive {
 44	
 45	private static final int _INDEX_ScAddressNotIncluded = 0;
 46	private static final int _INDEX_MnrfSet = 1;
 47	private static final int _INDEX_McefSet = 2;
 48	private static final int _INDEX_MnrgSet = 3;
 49	
 50	private BitSetStrictLength bitString = new BitSetStrictLength(6);
 51	
 52	
 53	public MWStatusImpl() {
 54	}
 55	
 56	public MWStatusImpl(boolean scAddressNotIncluded, boolean mnrfSet, boolean mcefSet, boolean mnrgSet) {
 57		if (scAddressNotIncluded)
 58			this.bitString.set(_INDEX_ScAddressNotIncluded);
 59		if (mnrfSet)
 60			this.bitString.set(_INDEX_MnrfSet);
 61		if (mcefSet)
 62			this.bitString.set(_INDEX_McefSet);
 63		if (mnrgSet)
 64			this.bitString.set(_INDEX_MnrgSet);
 65	}
 66	
 67
 68	@Override
 69	public boolean getScAddressNotIncluded() {
 70		return this.bitString.get(_INDEX_ScAddressNotIncluded);
 71	}
 72
 73	@Override
 74	public boolean getMnrfSet() {
 75		return this.bitString.get(_INDEX_MnrfSet);
 76	}
 77
 78	@Override
 79	public boolean getMcefSet() {
 80		return this.bitString.get(_INDEX_McefSet);
 81	}
 82
 83	@Override
 84	public boolean getMnrgSet() {
 85		return this.bitString.get(_INDEX_MnrgSet);
 86	}
 87	
 88
 89	@Override
 90	public int getTag() throws MAPException {
 91		return Tag.STRING_BIT;
 92	}
 93
 94	@Override
 95	public int getTagClass() {
 96		return Tag.CLASS_UNIVERSAL;
 97	}
 98
 99	@Override
100	public boolean getIsPrimitive() {
101		return true;
102	}
103	
104
105	@Override
106	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
107
108		try {
109			int length = ansIS.readLength();
110			this._decode(ansIS, length);
111		} catch (IOException e) {
112			throw new MAPParsingComponentException("IOException when decoding MWStatus: " + e.getMessage(), e,
113					MAPParsingComponentExceptionReason.MistypedParameter);
114		} catch (AsnException e) {
115			throw new MAPParsingComponentException("AsnException when decoding MWStatus: " + e.getMessage(), e,
116					MAPParsingComponentExceptionReason.MistypedParameter);
117		}
118	}
119
120	@Override
121	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
122
123		try {
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	private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
135		if (length == 0 || length > 2)
136			throw new MAPParsingComponentException("Error decoding MWStatus: the MWStatus field must contain from 1 or 2 octets. Contains: " + length,
137					MAPParsingComponentExceptionReason.MistypedParameter);
138		
139		this.bitString = ansIS.readBitStringData(length);
140	}
141
142	@Override
143	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
144		
145		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.STRING_BIT);
146	}
147
148	@Override
149	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
150		
151		try {
152			asnOs.writeTag(tagClass, true, tag);
153			int pos = asnOs.StartContentDefiniteLength();
154			this.encodeData(asnOs);
155			asnOs.FinalizeContent(pos);
156		} catch (AsnException e) {
157			throw new MAPException("AsnException when encoding MWStatus: " + e.getMessage(), e);
158		}
159	}
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	@Override
173	public String toString() {
174		return "MWStatus [ScAddressNotIncluded=" + this.getScAddressNotIncluded() + ", MnrfSet=" + this.getMnrfSet() + ", McefSet=" + this.getMcefSet()
175				+ ", MnrgSet=" + this.getMnrgSet() + "]";
176	}
177
178}
179
180