PageRenderTime 38ms CodeModel.GetById 1ms app.highlight 31ms RepoModel.GetById 1ms app.codeStats 0ms

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

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