PageRenderTime 36ms CodeModel.GetById 2ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://mobicents.googlecode.com/
Java | 293 lines | 216 code | 48 blank | 29 comment | 48 complexity | 0be915caed4d9f100b5a7382e7052e02 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.MoForwardShortMessageRequestIndication;
 39import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_DA;
 40import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_OA;
 41import org.mobicents.protocols.ss7.map.api.service.sms.SmsSignalInfo;
 42import org.mobicents.protocols.ss7.map.primitives.IMSIImpl;
 43import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
 44
 45
 46/**
 47 * 
 48 * @author sergey vetyutnev
 49 * 
 50 */
 51public class MoForwardShortMessageRequestIndicationImpl extends SmsMessageImpl implements MoForwardShortMessageRequestIndication {
 52	
 53	private SM_RP_DA sm_RP_DA;
 54	private SM_RP_OA sm_RP_OA;
 55	private SmsSignalInfoImpl sm_RP_UI;
 56	private MAPExtensionContainer extensionContainer;
 57	private IMSI imsi;
 58
 59	
 60	public MoForwardShortMessageRequestIndicationImpl() {
 61	}
 62	
 63	public MoForwardShortMessageRequestIndicationImpl(SM_RP_DA sm_RP_DA, SM_RP_OA sm_RP_OA, SmsSignalInfo sm_RP_UI, MAPExtensionContainer extensionContainer, IMSI imsi) {
 64		this.sm_RP_DA = sm_RP_DA;
 65		this.sm_RP_OA = sm_RP_OA;
 66		this.sm_RP_UI = (SmsSignalInfoImpl)sm_RP_UI;
 67		this.extensionContainer = extensionContainer;
 68		this.imsi = imsi;
 69	}
 70
 71	@Override
 72	public MAPMessageType getMessageType() {
 73		return MAPMessageType.moForwardSM_Request;
 74	}
 75
 76	@Override
 77	public int getOperationCode() {
 78		return MAPOperationCode.mo_forwardSM;
 79	}
 80
 81	@Override
 82	public SM_RP_DA getSM_RP_DA() {
 83		return this.sm_RP_DA;
 84	}
 85
 86	@Override
 87	public SM_RP_OA getSM_RP_OA() {
 88		return this.sm_RP_OA;
 89	}
 90
 91	@Override
 92	public SmsSignalInfo getSM_RP_UI() {
 93		return this.sm_RP_UI;
 94	}
 95
 96	@Override
 97	public MAPExtensionContainer getExtensionContainer() {
 98		return this.extensionContainer;
 99	}
100
101	@Override
102	public IMSI getIMSI() {
103		return this.imsi;
104	}
105
106	
107	@Override
108	public int getTag() throws MAPException {
109		return Tag.SEQUENCE;
110	}
111
112	@Override
113	public int getTagClass() {
114		return Tag.CLASS_UNIVERSAL;
115	}
116
117	@Override
118	public boolean getIsPrimitive() {
119		return false;
120	}
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 moForwardShortMessageRequest: " + e.getMessage(), e,
131					MAPParsingComponentExceptionReason.MistypedParameter);
132		} catch (AsnException e) {
133			throw new MAPParsingComponentException("AsnException when decoding moForwardShortMessageRequest: " + 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 moForwardShortMessageRequest: " + e.getMessage(), e,
145					MAPParsingComponentExceptionReason.MistypedParameter);
146		} catch (AsnException e) {
147			throw new MAPParsingComponentException("AsnException when decoding moForwardShortMessageRequest: " + e.getMessage(), e,
148					MAPParsingComponentExceptionReason.MistypedParameter);
149		}
150	}
151
152	private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
153		
154		this.sm_RP_DA = null;
155		this.sm_RP_OA = null;
156		this.sm_RP_UI = null;
157		this.extensionContainer = null;
158		this.imsi = null;
159
160		AsnInputStream ais = ansIS.readSequenceStreamData(length);
161		int num = 0;
162		while (true) {
163			if (ais.available() == 0)
164				break;
165
166			int tag = ais.readTag();
167
168			switch (num) {
169			case 0:
170				// SM_RP_DA
171				if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive())
172					throw new MAPParsingComponentException("Error while decoding moForwardShortMessageRequest: Parameter 0 bad tag class or not primitive",
173							MAPParsingComponentExceptionReason.MistypedParameter);
174				this.sm_RP_DA = new SM_RP_DAImpl();
175				((SM_RP_DAImpl)this.sm_RP_DA).decodeAll(ais);
176				break;
177
178			case 1:
179				// SM_RP_OA
180				if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive())
181					throw new MAPParsingComponentException("Error while decoding moForwardShortMessageRequest: Parameter 1 bad tag class or not primitive",
182							MAPParsingComponentExceptionReason.MistypedParameter);
183				this.sm_RP_OA = new SM_RP_OAImpl();
184				((SM_RP_OAImpl)this.sm_RP_OA).decodeAll(ais);
185				break;
186
187			case 2:
188				// sm-RP-UI
189				if (ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive())
190					throw new MAPParsingComponentException("Error while decoding moForwardShortMessageRequest: Parameter 2 bad tag class or not primitive",
191							MAPParsingComponentExceptionReason.MistypedParameter);
192				if (tag != Tag.STRING_OCTET)
193					throw new MAPParsingComponentException("Error while decoding moForwardShortMessageRequest: Parameter 2 tag must be STRING_OCTET, found: "
194							+ tag, MAPParsingComponentExceptionReason.MistypedParameter);
195				this.sm_RP_UI = new SmsSignalInfoImpl();
196				this.sm_RP_UI.decodeAll(ais);
197				break;
198
199			default:
200				if (tag == Tag.SEQUENCE && ais.getTagClass() == Tag.CLASS_UNIVERSAL) {
201					if (ais.isTagPrimitive())
202						throw new MAPParsingComponentException("Error while decoding moForwardShortMessageRequest: Parameter extensionContainer is primitive",
203								MAPParsingComponentExceptionReason.MistypedParameter);
204					this.extensionContainer = new MAPExtensionContainerImpl();
205					((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
206				} else if (tag == Tag.STRING_OCTET && ais.getTagClass() == Tag.CLASS_UNIVERSAL) {
207					if (!ais.isTagPrimitive())
208						throw new MAPParsingComponentException("Error while decoding moForwardShortMessageRequest: Parameter imsi is not primitive",
209								MAPParsingComponentExceptionReason.MistypedParameter);
210					this.imsi = new IMSIImpl();
211					((IMSIImpl)this.imsi).decodeAll(ais);
212				} else {
213					ais.advanceElement();
214				}
215				break;
216			}
217
218			num++;
219		}
220
221		if (num < 3)
222			throw new MAPParsingComponentException("Error while decoding moForwardShortMessageRequest: Needs at least 3 mandatory parameters, found " + num,
223					MAPParsingComponentExceptionReason.MistypedParameter);
224	}
225
226	@Override
227	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
228
229		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
230	}
231
232	@Override
233	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
234		
235		try {
236			asnOs.writeTag(tagClass, false, tag);
237			int pos = asnOs.StartContentDefiniteLength();
238			this.encodeData(asnOs);
239			asnOs.FinalizeContent(pos);
240		} catch (AsnException e) {
241			throw new MAPException("AsnException when encoding moForwardShortMessageRequest: " + e.getMessage(), e);
242		}
243	}
244
245	@Override
246	public void encodeData(AsnOutputStream asnOs) throws MAPException {
247
248		if (this.sm_RP_DA == null || this.sm_RP_OA == null || this.sm_RP_UI == null)
249			throw new MAPException("sm_RP_DA,sm_RP_OA and sm_RP_UI must not be null");
250
251		((SM_RP_DAImpl) this.sm_RP_DA).encodeAll(asnOs);
252		((SM_RP_OAImpl) this.sm_RP_OA).encodeAll(asnOs);
253		this.sm_RP_UI.encodeAll(asnOs);
254
255		if (this.extensionContainer != null)
256			((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs);
257		if (this.imsi != null)
258			((IMSIImpl) this.imsi).encodeAll(asnOs);
259	}	
260	
261	@Override
262	public String toString() {
263		StringBuilder sb = new StringBuilder();
264		sb.append("MoForwardShortMessageRequest [");
265
266		if (this.sm_RP_DA != null) {
267			sb.append("sm_RP_DA=");
268			sb.append(this.sm_RP_DA.toString());
269		}
270		if (this.sm_RP_OA != null) {
271			sb.append(", sm_RP_OA=");
272			sb.append(this.sm_RP_OA.toString());
273		}
274		if (this.sm_RP_UI != null) {
275			sb.append(", sm_RP_UI=[");
276			sb.append(this.sm_RP_UI.toString());
277			sb.append("]");
278		}
279		if (this.extensionContainer != null) {
280			sb.append(", extensionContainer=");
281			sb.append(this.extensionContainer.toString());
282		}
283		if (this.imsi != null) {
284			sb.append(", imsi=");
285			sb.append(this.imsi.toString());
286		}
287
288		sb.append("]");
289
290		return sb.toString();
291	}
292}
293