PageRenderTime 34ms CodeModel.GetById 17ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/sms/SendRoutingInfoForSMResponseIndicationImpl.java

http://mobicents.googlecode.com/
Java | 249 lines | 181 code | 45 blank | 23 comment | 32 complexity | 227d76c736ac7b99badea56e9c7bf193 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.service.sms;
 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.MAPMessageType;
 33import org.mobicents.protocols.ss7.map.api.MAPOperationCode;
 34import org.mobicents.protocols.ss7.map.api.MAPParsingComponentException;
 35import org.mobicents.protocols.ss7.map.api.MAPParsingComponentExceptionReason;
 36import org.mobicents.protocols.ss7.map.api.primitives.IMSI;
 37import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
 38import org.mobicents.protocols.ss7.map.api.service.sms.LocationInfoWithLMSI;
 39import org.mobicents.protocols.ss7.map.api.service.sms.SendRoutingInfoForSMResponseIndication;
 40import org.mobicents.protocols.ss7.map.primitives.IMSIImpl;
 41import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
 42
 43public class SendRoutingInfoForSMResponseIndicationImpl extends SmsMessageImpl implements SendRoutingInfoForSMResponseIndication {
 44	
 45	protected static final int _TAG_LocationInfoWithLMSI = 0; 
 46	protected static final int _TAG_ExtensionContainer = 4; 
 47
 48	private IMSI imsi;
 49	private LocationInfoWithLMSI locationInfoWithLMSI;
 50	private MAPExtensionContainer extensionContainer;
 51	
 52	
 53	public SendRoutingInfoForSMResponseIndicationImpl() {
 54	}	
 55	
 56	public SendRoutingInfoForSMResponseIndicationImpl(IMSI imsi, LocationInfoWithLMSI locationInfoWithLMSI, MAPExtensionContainer extensionContainer) {
 57		this.imsi = imsi;
 58		this.locationInfoWithLMSI = locationInfoWithLMSI;
 59		this.extensionContainer = extensionContainer;
 60	}	
 61
 62	@Override
 63	public MAPMessageType getMessageType() {
 64		return MAPMessageType.sendRoutingInfoForSM_Response;
 65	}
 66
 67	@Override
 68	public int getOperationCode() {
 69		return MAPOperationCode.sendRoutingInfoForSM;
 70	}
 71
 72	@Override
 73	public IMSI getIMSI() {
 74		return this.imsi;
 75	}
 76
 77	@Override
 78	public LocationInfoWithLMSI getLocationInfoWithLMSI() {
 79		return this.locationInfoWithLMSI;
 80	}
 81
 82	@Override
 83	public MAPExtensionContainer getExtensionContainer() {
 84		return this.extensionContainer;
 85	}
 86
 87	
 88	@Override
 89	public int getTag() throws MAPException {
 90		return Tag.SEQUENCE;
 91	}
 92
 93	@Override
 94	public int getTagClass() {
 95		return Tag.CLASS_UNIVERSAL;
 96	}
 97
 98	@Override
 99	public boolean getIsPrimitive() {
100		return false;
101	}
102
103	
104	@Override
105	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
106
107		try {
108			int length = ansIS.readLength();
109			this._decode(ansIS, length);
110		} catch (IOException e) {
111			throw new MAPParsingComponentException("IOException when decoding sendRoutingInfoForSMResponse: " + e.getMessage(), e,
112					MAPParsingComponentExceptionReason.MistypedParameter);
113		} catch (AsnException e) {
114			throw new MAPParsingComponentException("AsnException when decoding sendRoutingInfoForSMResponse: " + e.getMessage(), e,
115					MAPParsingComponentExceptionReason.MistypedParameter);
116		}
117	}
118
119	@Override
120	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
121
122		try {
123			this._decode(ansIS, length);
124		} catch (IOException e) {
125			throw new MAPParsingComponentException("IOException when decoding sendRoutingInfoForSMResponse: " + e.getMessage(), e,
126					MAPParsingComponentExceptionReason.MistypedParameter);
127		} catch (AsnException e) {
128			throw new MAPParsingComponentException("AsnException when decoding sendRoutingInfoForSMResponse: " + e.getMessage(), e,
129					MAPParsingComponentExceptionReason.MistypedParameter);
130		}
131	}
132
133	private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
134
135		this.imsi = null;
136		this.locationInfoWithLMSI = null;
137		this.extensionContainer = null;
138		
139		AsnInputStream ais = ansIS.readSequenceStreamData(length);
140		int num = 0;
141		while (true) {
142			if (ais.available() == 0)
143				break;
144
145			int tag = ais.readTag();
146			switch (num) {
147			case 0:
148				// imsi
149				if (ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive() || tag != Tag.STRING_OCTET)
150					throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMResponse.imsi: Parameter 0 bad tag or tag class or not primitive",
151							MAPParsingComponentExceptionReason.MistypedParameter);
152				this.imsi = new IMSIImpl();
153				((IMSIImpl)this.imsi).decodeAll(ais);
154				break;
155				
156			case 1:
157				// locationInfoWithLMSI
158				if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || ais.isTagPrimitive() || tag != _TAG_LocationInfoWithLMSI)
159					throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMResponse.locationInfoWithLMSI: Parameter 1 bad tag class or tag or primitive",
160							MAPParsingComponentExceptionReason.MistypedParameter);
161				this.locationInfoWithLMSI = new LocationInfoWithLMSIImpl();
162				((LocationInfoWithLMSIImpl)this.locationInfoWithLMSI).decodeAll(ais);
163				break;
164
165			default:
166				if (ais.getTagClass() == Tag.CLASS_CONTEXT_SPECIFIC) {
167					switch (tag) {
168					case _TAG_ExtensionContainer:
169						if (ais.isTagPrimitive())
170								throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMResponse.extensionContainer: Parameter extensionContainer is primitive",
171										MAPParsingComponentExceptionReason.MistypedParameter);
172						this.extensionContainer = new MAPExtensionContainerImpl();
173						((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
174					break;
175
176					default:
177						ais.advanceElement();
178						break;
179					}
180
181				} else {
182
183					ais.advanceElement();
184				}
185				break;
186			}
187			
188			num++;
189		}
190
191		if (num < 2)
192			throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMResponse: Needs at least 2 mandatory parameters, found " + num,
193					MAPParsingComponentExceptionReason.MistypedParameter);
194	}
195
196	@Override
197	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
198
199		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
200	}
201
202	@Override
203	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
204		
205		try {
206			asnOs.writeTag(tagClass, false, tag);
207			int pos = asnOs.StartContentDefiniteLength();
208			this.encodeData(asnOs);
209			asnOs.FinalizeContent(pos);
210		} catch (AsnException e) {
211			throw new MAPException("AsnException when encoding sendRoutingInfoForSMResponse: " + e.getMessage(), e);
212		}
213	}
214
215	@Override
216	public void encodeData(AsnOutputStream asnOs) throws MAPException {
217		
218		if (this.imsi == null || this.locationInfoWithLMSI == null)
219			throw new MAPException("imsi and locationInfoWithLMSI must not be null");
220
221		((IMSIImpl)this.imsi).encodeAll(asnOs);
222		((LocationInfoWithLMSIImpl)this.locationInfoWithLMSI).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LocationInfoWithLMSI);
223		if (this.extensionContainer != null)
224			((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_ExtensionContainer);
225	}	
226	
227	@Override
228	public String toString() {
229		StringBuilder sb = new StringBuilder();
230		sb.append("SendRoutingInfoForSMResponse [");
231
232		if (this.imsi != null) {
233			sb.append(", imsi=");
234			sb.append(this.imsi.toString());
235		}
236		if (this.locationInfoWithLMSI != null) {
237			sb.append(", locationInfoWithLMSI=");
238			sb.append(this.locationInfoWithLMSI.toString());
239		}
240		if (this.extensionContainer != null) {
241			sb.append(", extensionContainer=");
242			sb.append(this.extensionContainer.toString());
243		}
244
245		sb.append("]");
246
247		return sb.toString();
248	}
249}