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

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

http://mobicents.googlecode.com/
Java | 263 lines | 187 code | 50 blank | 26 comment | 29 complexity | b82878c175b6bcd63f16fe9aa0206cc3 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.MAPErrorMessageAbsentSubscriberSM;
 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 MAPErrorMessageAbsentSubscriberSMImpl extends MAPErrorMessageImpl implements MAPErrorMessageAbsentSubscriberSM {
 45
 46	public static final int additionalAbsentSubscriberDiagnosticSM_TAG = 0x00;
 47	
 48	private Integer absentSubscriberDiagnosticSM;
 49	private MAPExtensionContainer extensionContainer;
 50	private Integer additionalAbsentSubscriberDiagnosticSM;
 51
 52	
 53	public MAPErrorMessageAbsentSubscriberSMImpl(Integer absentSubscriberDiagnosticSM, MAPExtensionContainer extensionContainer,
 54			Integer additionalAbsentSubscriberDiagnosticSM) {
 55		super((long) MAPErrorCode.absentSubscriberSM);
 56
 57		this.absentSubscriberDiagnosticSM = absentSubscriberDiagnosticSM;
 58		this.extensionContainer = extensionContainer;
 59		this.additionalAbsentSubscriberDiagnosticSM = additionalAbsentSubscriberDiagnosticSM;
 60	}
 61	
 62	protected MAPErrorMessageAbsentSubscriberSMImpl() {
 63		super((long) MAPErrorCode.absentSubscriberSM);
 64	}
 65	
 66	
 67	@Override
 68	public Integer getAbsentSubscriberDiagnosticSM() {
 69		return this.absentSubscriberDiagnosticSM;
 70	}
 71
 72	@Override
 73	public MAPExtensionContainer getExtensionContainer() {
 74		return this.extensionContainer;
 75	}
 76
 77	@Override
 78	public Integer getAdditionalAbsentSubscriberDiagnosticSM() {
 79		return this.additionalAbsentSubscriberDiagnosticSM;
 80	}
 81	
 82	@Override
 83	public void setAbsentSubscriberDiagnosticSM(Integer absentSubscriberDiagnosticSM) {
 84		this.absentSubscriberDiagnosticSM = absentSubscriberDiagnosticSM;
 85	}
 86
 87	@Override
 88	public void setExtensionContainer(MAPExtensionContainer extensionContainer) {
 89		this.extensionContainer = extensionContainer;
 90	}
 91
 92	@Override
 93	public void setAdditionalAbsentSubscriberDiagnosticSM(Integer additionalAbsentSubscriberDiagnosticSM) {
 94		this.additionalAbsentSubscriberDiagnosticSM = additionalAbsentSubscriberDiagnosticSM;
 95	}
 96	
 97	@Override
 98	public boolean isEmAbsentSubscriberSM() {
 99		return true;
100	}
101
102	@Override
103	public MAPErrorMessageAbsentSubscriberSM getEmAbsentSubscriberSM() {
104		return this;
105	}
106	
107	
108	@Override
109	public int getTag() throws MAPException {
110		return Tag.SEQUENCE;
111	}
112
113	@Override
114	public int getTagClass() {
115		return Tag.CLASS_UNIVERSAL;
116	}
117
118	@Override
119	public boolean getIsPrimitive() {
120		return false;
121	}
122
123	@Override
124	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
125
126		try {
127			int length = ansIS.readLength();
128			this._decode(ansIS, length);
129		} catch (IOException e) {
130			throw new MAPParsingComponentException("IOException when decoding MAPErrorMessageAbsentSubscriberSM: " + e.getMessage(), e,
131					MAPParsingComponentExceptionReason.MistypedParameter);
132		} catch (AsnException e) {
133			throw new MAPParsingComponentException("AsnException when decoding MAPErrorMessageAbsentSubscriberSM: " + e.getMessage(), e,
134					MAPParsingComponentExceptionReason.MistypedParameter);
135		}
136	}
137
138	@Override
139	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
140
141		try {
142			this._decode(ansIS, length);
143		} catch (IOException e) {
144			throw new MAPParsingComponentException("IOException when decoding MAPErrorMessageAbsentSubscriberSM: " + e.getMessage(), e,
145					MAPParsingComponentExceptionReason.MistypedParameter);
146		} catch (AsnException e) {
147			throw new MAPParsingComponentException("AsnException when decoding MAPErrorMessageAbsentSubscriberSM: " + e.getMessage(), e,
148					MAPParsingComponentExceptionReason.MistypedParameter);
149		}
150	}
151
152	private void _decode(AsnInputStream localAis, int length) throws MAPParsingComponentException, IOException, AsnException {
153
154		this.absentSubscriberDiagnosticSM = null;
155		this.additionalAbsentSubscriberDiagnosticSM = null;
156		this.extensionContainer = null;
157		
158		if (localAis.getTagClass() != Tag.CLASS_UNIVERSAL || localAis.getTag() != Tag.SEQUENCE || localAis.isTagPrimitive())
159			throw new MAPParsingComponentException(
160					"Error decoding MAPErrorMessageAbsentSubscriberSM: bad tag class or tag or parameter is primitive",
161					MAPParsingComponentExceptionReason.MistypedParameter);
162
163		AsnInputStream ais = localAis.readSequenceStreamData(length);
164
165		while (true) {
166			if (ais.available() == 0)
167				break;
168
169			int tag = ais.readTag();
170
171			switch (ais.getTagClass()) {
172			case Tag.CLASS_UNIVERSAL:
173				switch (tag) {
174				case Tag.INTEGER:
175					this.absentSubscriberDiagnosticSM = (int)ais.readInteger();
176					break;
177
178				case Tag.SEQUENCE:
179					this.extensionContainer = new MAPExtensionContainerImpl();
180					((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
181					break;
182
183				default:
184					ais.advanceElement();
185					break;
186				}
187				break;
188				
189			case Tag.CLASS_CONTEXT_SPECIFIC:
190				switch (tag) {
191				case additionalAbsentSubscriberDiagnosticSM_TAG:
192					this.additionalAbsentSubscriberDiagnosticSM = (int)ais.readInteger();
193					break;
194
195				default:
196					ais.advanceElement();
197					break;
198				}
199				break;
200
201			default:
202				ais.advanceElement();
203				break;
204			}
205		}
206	}
207
208	@Override
209	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
210
211		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
212	}
213
214	@Override
215	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
216		
217		try {
218			asnOs.writeTag(tagClass, false, tag);
219			int pos = asnOs.StartContentDefiniteLength();
220			this.encodeData(asnOs);
221			asnOs.FinalizeContent(pos);
222		} catch (AsnException e) {
223			throw new MAPException("AsnException when encoding MAPErrorMessageAbsentSubscriberSM: " + e.getMessage(), e);
224		}
225	}
226
227	@Override
228	public void encodeData(AsnOutputStream aos) throws MAPException {
229
230		if (this.absentSubscriberDiagnosticSM == null && this.additionalAbsentSubscriberDiagnosticSM == null && this.extensionContainer == null)
231			return;
232
233		try {
234			if (this.absentSubscriberDiagnosticSM != null)
235				aos.writeInteger(this.absentSubscriberDiagnosticSM);
236			if (this.extensionContainer != null)
237				((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(aos);
238			if (this.additionalAbsentSubscriberDiagnosticSM != null)
239				aos.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, additionalAbsentSubscriberDiagnosticSM_TAG, this.additionalAbsentSubscriberDiagnosticSM);
240
241		} catch (IOException e) {
242			throw new MAPException("IOException when encoding MAPErrorMessageAbsentSubscriberSM: " + e.getMessage(), e);
243		} catch (AsnException e) {
244			throw new MAPException("AsnException when encoding MAPErrorMessageAbsentSubscriberSM: " + e.getMessage(), e);
245		}
246	}
247
248	@Override
249	public String toString() {
250		StringBuilder sb = new StringBuilder();
251		
252		sb.append("MAPErrorMessageAbsentSubscriberSM [");
253		if (this.absentSubscriberDiagnosticSM != null)
254			sb.append("absentSubscriberDiagnosticSM=" + this.absentSubscriberDiagnosticSM.toString());
255		if (this.extensionContainer != null)
256			sb.append(", extensionContainer=" + this.extensionContainer.toString());
257		if (this.additionalAbsentSubscriberDiagnosticSM != null)
258			sb.append(", additionalAbsentSubscriberDiagnosticSM=" + this.additionalAbsentSubscriberDiagnosticSM.toString());
259		sb.append("]");
260		
261		return sb.toString();
262	}
263}