PageRenderTime 30ms CodeModel.GetById 15ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/errors/MAPErrorMessageSubscriberBusyForMtSmsImpl.java

http://mobicents.googlecode.com/
Java | 235 lines | 163 code | 46 blank | 26 comment | 28 complexity | 14cd19ce084a67dededd1b752f840c94 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.errors;
 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.errors.MAPErrorCode;
 35import org.mobicents.protocols.ss7.map.api.errors.MAPErrorMessageSubscriberBusyForMtSms;
 36import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
 37import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
 38
 39/**
 40 * 
 41 * @author sergey vetyutnev
 42 * 
 43 */
 44public class MAPErrorMessageSubscriberBusyForMtSmsImpl extends MAPErrorMessageImpl implements MAPErrorMessageSubscriberBusyForMtSms {
 45
 46	private MAPExtensionContainer extensionContainer;
 47	private Boolean gprsConnectionSuspended;	
 48	
 49	
 50	public MAPErrorMessageSubscriberBusyForMtSmsImpl(MAPExtensionContainer extensionContainer, Boolean gprsConnectionSuspended) {
 51		super((long) MAPErrorCode.subscriberBusyForMTSMS);
 52
 53		this.extensionContainer = extensionContainer;
 54		this.gprsConnectionSuspended = gprsConnectionSuspended;
 55	}
 56
 57	protected MAPErrorMessageSubscriberBusyForMtSmsImpl() {
 58		super((long) MAPErrorCode.subscriberBusyForMTSMS);
 59	}
 60
 61
 62	@Override
 63	public boolean isEmSubscriberBusyForMtSms() {
 64		return true;
 65	}
 66
 67	@Override
 68	public MAPErrorMessageSubscriberBusyForMtSms getEmSubscriberBusyForMtSms() {
 69		return this;
 70	}
 71
 72	@Override
 73	public MAPExtensionContainer getExtensionContainer() {
 74		return this.extensionContainer;
 75	}
 76
 77	@Override
 78	public Boolean getGprsConnectionSuspended() {
 79		return this.gprsConnectionSuspended;
 80	}
 81
 82	@Override
 83	public void setExtensionContainer(MAPExtensionContainer extensionContainer) {
 84		this.extensionContainer = extensionContainer;
 85	}
 86
 87	@Override
 88	public void setGprsConnectionSuspended(Boolean gprsConnectionSuspended) {
 89		this.gprsConnectionSuspended = gprsConnectionSuspended;
 90	}
 91	
 92	
 93	@Override
 94	public int getTag() throws MAPException {
 95		return Tag.SEQUENCE;
 96	}
 97
 98	@Override
 99	public int getTagClass() {
100		return Tag.CLASS_UNIVERSAL;
101	}
102
103	@Override
104	public boolean getIsPrimitive() {
105		return false;
106	}
107
108	@Override
109	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
110
111		try {
112			int length = ansIS.readLength();
113			this._decode(ansIS, length);
114		} catch (IOException e) {
115			throw new MAPParsingComponentException("IOException when decoding MAPErrorMessageSubscriberBusyForMtSms: " + e.getMessage(), e,
116					MAPParsingComponentExceptionReason.MistypedParameter);
117		} catch (AsnException e) {
118			throw new MAPParsingComponentException("AsnException when decoding MAPErrorMessageSubscriberBusyForMtSms: " + e.getMessage(), e,
119					MAPParsingComponentExceptionReason.MistypedParameter);
120		}
121	}
122
123	@Override
124	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
125
126		try {
127			this._decode(ansIS, length);
128		} catch (IOException e) {
129			throw new MAPParsingComponentException("IOException when decoding MAPErrorMessageSubscriberBusyForMtSms: " + e.getMessage(), e,
130					MAPParsingComponentExceptionReason.MistypedParameter);
131		} catch (AsnException e) {
132			throw new MAPParsingComponentException("AsnException when decoding MAPErrorMessageSubscriberBusyForMtSms: " + e.getMessage(), e,
133					MAPParsingComponentExceptionReason.MistypedParameter);
134		}
135	}
136
137	private void _decode(AsnInputStream localAis, int length) throws MAPParsingComponentException, IOException, AsnException {
138
139		this.extensionContainer = null;
140		this.gprsConnectionSuspended = null;
141		
142		if (localAis.getTagClass() != Tag.CLASS_UNIVERSAL || localAis.getTag() != Tag.SEQUENCE || localAis.isTagPrimitive())
143			throw new MAPParsingComponentException(
144					"Error decoding MAPErrorMessageSubscriberBusyForMtSms: bad tag class or tag or parameter is primitive",
145					MAPParsingComponentExceptionReason.MistypedParameter);
146
147		AsnInputStream ais = localAis.readSequenceStreamData(length);
148
149		while (true) {
150			if (ais.available() == 0)
151				break;
152
153			int tag = ais.readTag();
154
155			switch (ais.getTagClass()) {
156			case Tag.CLASS_UNIVERSAL:
157				switch (tag) {
158				case Tag.SEQUENCE:
159					this.extensionContainer = new MAPExtensionContainerImpl();
160					((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
161					break;
162
163				case Tag.NULL:
164					ais.readNull();
165					this.gprsConnectionSuspended = true;
166					break;
167
168				default:
169					ais.advanceElement();
170					break;
171				}
172				break;
173
174			default:
175				ais.advanceElement();
176				break;
177			}
178		}
179		
180		if (this.gprsConnectionSuspended == null)
181			this.gprsConnectionSuspended = false;
182	}
183
184	@Override
185	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
186
187		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
188	}
189
190	@Override
191	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
192		
193		try {
194			asnOs.writeTag(tagClass, false, tag);
195			int pos = asnOs.StartContentDefiniteLength();
196			this.encodeData(asnOs);
197			asnOs.FinalizeContent(pos);
198		} catch (AsnException e) {
199			throw new MAPException("AsnException when encoding MAPErrorMessageSubscriberBusyForMtSms: " + e.getMessage(), e);
200		}
201	}
202
203	@Override
204	public void encodeData(AsnOutputStream aos) throws MAPException {
205
206		if (this.gprsConnectionSuspended == null && this.extensionContainer == null)
207			return;
208
209		try {
210			if (this.extensionContainer != null)
211				((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(aos);
212			if (this.gprsConnectionSuspended != null && this.gprsConnectionSuspended == true)
213				aos.writeNull();
214
215		} catch (IOException e) {
216			throw new MAPException("IOException when encoding MAPErrorMessageSubscriberBusyForMtSms: " + e.getMessage(), e);
217		} catch (AsnException e) {
218			throw new MAPException("AsnException when encoding MAPErrorMessageSubscriberBusyForMtSms: " + e.getMessage(), e);
219		}
220	}
221
222	@Override
223	public String toString() {
224		StringBuilder sb = new StringBuilder();
225		
226		sb.append("MAPErrorMessageSubscriberBusyForMtSms [");
227		if (this.extensionContainer != null)
228			sb.append("extensionContainer=" + this.extensionContainer.toString());
229		if (this.gprsConnectionSuspended != null && this.gprsConnectionSuspended == true)
230			sb.append(", gprsConnectionSuspended=true");
231		sb.append("]");
232		
233		return sb.toString();
234	}
235}