PageRenderTime 22ms CodeModel.GetById 1ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

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

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