PageRenderTime 47ms CodeModel.GetById 22ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

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

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