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/dialog/MAPUserAbortInfoImpl.java

http://mobicents.googlecode.com/
Java | 276 lines | 170 code | 44 blank | 62 comment | 22 complexity | 4daae1629052f6970714172c7675a07c 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.dialog;
 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.dialog.MAPUserAbortChoice;
 35import org.mobicents.protocols.ss7.map.api.dialog.ProcedureCancellationReason;
 36import org.mobicents.protocols.ss7.map.api.dialog.ResourceUnavailableReason;
 37import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
 38import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
 39import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
 40
 41/**
 42 * MAP-UserAbortInfo ::= SEQUENCE { map-UserAbortChoice MAP-UserAbortChoice, ...
 43 * extensionContainer ExtensionContainer OPTIONAL }
 44 * 
 45 * MAP-UserAbortChoice ::= CHOICE { userSpecificReason [0] NULL,
 46 * userResourceLimitation [1] NULL, resourceUnavailable [2]
 47 * ResourceUnavailableReason, applicationProcedureCancellation [3]
 48 * ProcedureCancellationReason}
 49 * 
 50 * @author amit bhayani
 51 * @author sergey vetyutnev
 52 * 
 53 */
 54public class MAPUserAbortInfoImpl implements MAPAsnPrimitive {
 55
 56	public static final int MAP_USER_ABORT_INFO_TAG = 0x04;
 57
 58	protected static final int USER_ABORT_TAG_CLASS = Tag.CLASS_CONTEXT_SPECIFIC;
 59	protected static final boolean USER_ABORT_TAG_PC_CONSTRUCTED = false;
 60
 61	private MAPUserAbortChoice mapUserAbortChoice = null;
 62	private MAPExtensionContainer extensionContainer;
 63
 64	public MAPUserAbortChoice getMAPUserAbortChoice() {
 65		return this.mapUserAbortChoice;
 66	}
 67
 68	public MAPExtensionContainer getExtensionContainer() {
 69		return extensionContainer;
 70	}
 71
 72	public void setMAPUserAbortChoice(MAPUserAbortChoice mapUsrAbrtChoice) {
 73		this.mapUserAbortChoice = mapUsrAbrtChoice;
 74	}
 75
 76	public void setExtensionContainer(MAPExtensionContainer extensionContainer) {
 77		this.extensionContainer = extensionContainer;
 78	}
 79
 80
 81	@Override
 82	public int getTag() throws MAPException {
 83		return MAP_USER_ABORT_INFO_TAG;
 84	}
 85
 86	@Override
 87	public int getTagClass() {
 88		return Tag.CLASS_CONTEXT_SPECIFIC;
 89	}
 90
 91	@Override
 92	public boolean getIsPrimitive() {
 93		return false;
 94	}
 95
 96	@Override
 97	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
 98
 99		try {
100			int length = ansIS.readLength();
101			this._decode(ansIS, length);
102		} catch (IOException e) {
103			throw new MAPParsingComponentException("IOException when decoding MAPUserAbortInfo: " + e.getMessage(), e,
104					MAPParsingComponentExceptionReason.MistypedParameter);
105		} catch (AsnException e) {
106			throw new MAPParsingComponentException("AsnException when decoding MAPUserAbortInfo: " + e.getMessage(), e,
107					MAPParsingComponentExceptionReason.MistypedParameter);
108		}
109	}
110
111	@Override
112	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
113
114		try {
115			this._decode(ansIS, length);
116		} catch (IOException e) {
117			throw new MAPParsingComponentException("IOException when decoding MAPUserAbortInfo: " + e.getMessage(), e,
118					MAPParsingComponentExceptionReason.MistypedParameter);
119		} catch (AsnException e) {
120			throw new MAPParsingComponentException("AsnException when decoding MAPUserAbortInfo: " + e.getMessage(), e,
121					MAPParsingComponentExceptionReason.MistypedParameter);
122		}
123	}
124	
125	private void _decode(AsnInputStream ais, int length) throws MAPParsingComponentException, IOException, AsnException {
126
127		// MAP-UserAbortInfo ::= SEQUENCE {
128		//   map-UserAbortChoice   CHOICE {
129		//	      userSpecificReason                   [0] IMPLICIT NULL, 
130		//	      userResourceLimitation               [1] IMPLICIT NULL, 
131		//	      resourceUnavailable                  [2] IMPLICIT ENUMERATED {
132		//	         shortTermResourceLimitation    ( 0 ), 
133		//	         longTermResourceLimitation     ( 1 ) }, 
134		//	      applicationProcedureCancellation     [3] IMPLICIT ENUMERATED {
135		//	         handoverCancellation          ( 0 ), 
136		//	         radioChannelRelease           ( 1 ), 
137		//	         networkPathRelease            ( 2 ), 
138		//	         callRelease                   ( 3 ), 
139		//	         associatedProcedureFailure    ( 4 ), 
140		//	         tandemDialogueRelease         ( 5 ), 
141		//	         remoteOperationsFailure       ( 6 ) }}, 
142		//	   ... , 
143		//	   extensionContainer    SEQUENCE {
144		//	      privateExtensionList   [0] IMPLICIT SEQUENCE  ( SIZE( 1 .. 10 ) ) OF
145		//	         SEQUENCE {
146		//	            extId      MAP-EXTENSION .&extensionId  ( {
147		//	               , 
148		//	               ...} ) , 
149		//	            extType    MAP-EXTENSION .&ExtensionType  ( {
150		//	               , 
151		//	               ...} { @extId   }  )  OPTIONAL} OPTIONAL, 
152		//	      pcs-Extensions         [1] IMPLICIT SEQUENCE {
153		//	         ... } OPTIONAL, 
154		//	      ... } OPTIONAL}
155
156		this.mapUserAbortChoice = null;
157		this.extensionContainer = null;
158
159		AsnInputStream localAis = ais.readSequenceStreamData(length);
160
161		int tag = localAis.readTag();
162
163		if (localAis.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !localAis.isTagPrimitive())
164			throw new MAPParsingComponentException("Error while decoding MAPUserAbortInfo.map-UserAbortChoice: bad tag class or not primitive element",
165					MAPParsingComponentExceptionReason.MistypedParameter);
166
167		MAPUserAbortChoiceImpl usAbrtChoice = new MAPUserAbortChoiceImpl();
168		switch (tag) {
169		case MAPUserAbortChoiceImpl.USER_SPECIFIC_REASON_TAG:
170			localAis.readNull();
171			usAbrtChoice.setUserSpecificReason();
172			this.setMAPUserAbortChoice(usAbrtChoice);
173			break;
174
175		case MAPUserAbortChoiceImpl.USER_RESOURCE_LIMITATION_TAG:
176			localAis.readNull();
177			usAbrtChoice.setUserResourceLimitation();
178			this.setMAPUserAbortChoice(usAbrtChoice);
179			break;
180
181		case MAPUserAbortChoiceImpl.RESOURCE_UNAVAILABLE:
182			int code = (int) localAis.readInteger();
183			ResourceUnavailableReason resUnaReas = ResourceUnavailableReason.getInstance(code);
184			usAbrtChoice.setResourceUnavailableReason(resUnaReas);
185			this.setMAPUserAbortChoice(usAbrtChoice);
186			break;
187
188		case MAPUserAbortChoiceImpl.APPLICATION_PROCEDURE_CANCELLATION:
189			code = (int) localAis.readInteger();
190			ProcedureCancellationReason procCanReasn = ProcedureCancellationReason.getInstance(code);
191			usAbrtChoice.setProcedureCancellationReason(procCanReasn);
192			this.setMAPUserAbortChoice(usAbrtChoice);
193			break;
194
195		default:
196			throw new MAPParsingComponentException("Error while decoding MAPUserAbortInfo.map-UserAbortChoice: bad tag",
197					MAPParsingComponentExceptionReason.MistypedParameter);
198		}
199
200		while (localAis.available() > 0) {
201			tag = localAis.readTag();
202
203			switch (localAis.getTagClass()) {
204			case Tag.CLASS_UNIVERSAL:
205				switch (tag) {
206				case Tag.SEQUENCE:
207					this.extensionContainer = new MAPExtensionContainerImpl();
208					((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(localAis);
209					break;
210
211				default:
212					localAis.advanceElement();
213					break;
214				}
215				break;
216
217			default:
218				localAis.advanceElement();
219				break;
220			}
221		}
222	}
223
224	@Override
225	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
226
227		this.encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, MAP_USER_ABORT_INFO_TAG);
228	}
229
230	@Override
231	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
232		
233		try {
234			asnOs.writeTag(tagClass, false, tag);
235			int pos = asnOs.StartContentDefiniteLength();
236			this.encodeData(asnOs);
237			asnOs.FinalizeContent(pos);
238		} catch (AsnException e) {
239			throw new MAPException("AsnException when encoding MAPUserAbortInfo: " + e.getMessage(), e);
240		}
241	}
242
243	@Override
244	public void encodeData(AsnOutputStream asnOS) throws MAPException {
245		
246		if (this.mapUserAbortChoice == null)
247			throw new MAPException("Error encoding MAPUserAbortInfo: UserSpecificReason must not be null");
248
249		try {
250			if(this.mapUserAbortChoice.isUserSpecificReason()) {
251				asnOS.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, MAPUserAbortChoiceImpl.USER_SPECIFIC_REASON_TAG);
252			} else if(this.mapUserAbortChoice.isUserResourceLimitation()) {
253				asnOS.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, MAPUserAbortChoiceImpl.USER_RESOURCE_LIMITATION_TAG);
254			} else if(this.mapUserAbortChoice.isResourceUnavailableReason()) {
255				ResourceUnavailableReason rur = this.mapUserAbortChoice.getResourceUnavailableReason();
256				if (rur == null)
257					throw new MAPException("Error encoding MAPUserAbortInfo: ResourceUnavailableReason value must not be null");
258				asnOS.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, MAPUserAbortChoiceImpl.RESOURCE_UNAVAILABLE, rur.getCode());
259			} else if(this.mapUserAbortChoice.isProcedureCancellationReason()) {
260				ProcedureCancellationReason pcr = this.mapUserAbortChoice.getProcedureCancellationReason();
261				if (pcr == null)
262					throw new MAPException("Error encoding MAPUserAbortInfo: ProcedureCancellationReason value must not be null");
263				asnOS.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, MAPUserAbortChoiceImpl.APPLICATION_PROCEDURE_CANCELLATION, pcr.getCode());
264			}
265
266			if (this.extensionContainer != null)
267				((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOS);
268			
269		} catch (IOException e) {
270			throw new MAPException("IOException when encoding MAPUserAbortInfo: " + e.getMessage(), e);
271		} catch (AsnException e) {
272			throw new MAPException("AsnException when encoding MAPUserAbortInfo: " + e.getMessage(), e);
273		}
274	}
275}
276