PageRenderTime 44ms CodeModel.GetById 13ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://mobicents.googlecode.com/
Java | 421 lines | 325 code | 61 blank | 35 comment | 76 complexity | d538a3810f3a7655dff67002d3d296b9 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.AddressString;
 37import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
 38import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
 39import org.mobicents.protocols.ss7.map.api.service.sms.ReportSMDeliveryStatusRequestIndication;
 40import org.mobicents.protocols.ss7.map.api.service.sms.SMDeliveryOutcome;
 41import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
 42import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
 43import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
 44
 45/**
 46 * 
 47 * @author sergey vetyutnev
 48 * 
 49 */
 50public class ReportSMDeliveryStatusRequestIndicationImpl extends SmsMessageImpl implements ReportSMDeliveryStatusRequestIndication {
 51	
 52	protected static final int _TAG_AbsentSubscriberDiagnosticSM = 0; 
 53	protected static final int _TAG_ExtensionContainer = 1; 
 54	protected static final int _TAG_GprsSupportIndicator = 2; 
 55	protected static final int _TAG_DeliveryOutcomeIndicator = 3; 
 56	protected static final int _TAG_AdditionalSMDeliveryOutcome = 4; 
 57	protected static final int _TAG_AdditionalAbsentSubscriberDiagnosticSM = 5; 
 58
 59	private ISDNAddressString msisdn;
 60	private AddressString serviceCentreAddress;
 61	private SMDeliveryOutcome sMDeliveryOutcome;
 62	private Integer absentSubscriberDiagnosticSM;
 63	private MAPExtensionContainer extensionContainer;
 64	private boolean gprsSupportIndicator;
 65	private boolean deliveryOutcomeIndicator;
 66	private SMDeliveryOutcome additionalSMDeliveryOutcome;
 67	private Integer additionalAbsentSubscriberDiagnosticSM;
 68	private long mapProtocolVersion;
 69
 70	
 71	public ReportSMDeliveryStatusRequestIndicationImpl(long mapProtocolVersion) {
 72		this.mapProtocolVersion = mapProtocolVersion;
 73	}
 74
 75	public ReportSMDeliveryStatusRequestIndicationImpl(long mapProtocolVersion, ISDNAddressString msisdn, AddressString serviceCentreAddress, SMDeliveryOutcome sMDeliveryOutcome,
 76			Integer absentSubscriberDiagnosticSM, MAPExtensionContainer extensionContainer, boolean gprsSupportIndicator, boolean deliveryOutcomeIndicator,
 77			SMDeliveryOutcome additionalSMDeliveryOutcome, Integer additionalAbsentSubscriberDiagnosticSM) {
 78		this.mapProtocolVersion = mapProtocolVersion;
 79		this.msisdn = msisdn;
 80		this.serviceCentreAddress = serviceCentreAddress;
 81		this.sMDeliveryOutcome = sMDeliveryOutcome;
 82		this.absentSubscriberDiagnosticSM = absentSubscriberDiagnosticSM;
 83		this.extensionContainer = extensionContainer;
 84		this.gprsSupportIndicator = gprsSupportIndicator;
 85		this.deliveryOutcomeIndicator = deliveryOutcomeIndicator;
 86		this.additionalSMDeliveryOutcome = additionalSMDeliveryOutcome;
 87		this.additionalAbsentSubscriberDiagnosticSM = additionalAbsentSubscriberDiagnosticSM;
 88	}	
 89
 90	@Override
 91	public MAPMessageType getMessageType() {
 92		return MAPMessageType.reportSM_DeliveryStatus_Request;
 93	}
 94
 95	@Override
 96	public int getOperationCode() {
 97		return MAPOperationCode.reportSM_DeliveryStatus;
 98	}
 99
100	@Override
101	public ISDNAddressString getMsisdn() {
102		return this.msisdn;
103	}
104
105	@Override
106	public AddressString getServiceCentreAddress() {
107		return this.serviceCentreAddress;
108	}
109
110	@Override
111	public SMDeliveryOutcome getSMDeliveryOutcome() {
112		return this.sMDeliveryOutcome;
113	}
114
115	@Override
116	public Integer getAbsentSubscriberDiagnosticSM() {
117		return this.absentSubscriberDiagnosticSM;
118	}
119
120	@Override
121	public MAPExtensionContainer getExtensionContainer() {
122		return this.extensionContainer;
123	}
124
125	@Override
126	public boolean getGprsSupportIndicator() {
127		return this.gprsSupportIndicator;
128	}
129
130	@Override
131	public boolean getDeliveryOutcomeIndicator() {
132		return this.deliveryOutcomeIndicator;
133	}
134
135	@Override
136	public SMDeliveryOutcome getAdditionalSMDeliveryOutcome() {
137		return this.additionalSMDeliveryOutcome;
138	}
139
140	@Override
141	public Integer getAdditionalAbsentSubscriberDiagnosticSM() {
142		return this.additionalAbsentSubscriberDiagnosticSM;
143	}
144
145	
146	@Override
147	public int getTag() throws MAPException {
148		return Tag.SEQUENCE;
149	}
150
151	@Override
152	public int getTagClass() {
153		return Tag.CLASS_UNIVERSAL;
154	}
155
156	@Override
157	public boolean getIsPrimitive() {
158		return false;
159	}
160
161	
162	@Override
163	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
164
165		try {
166			int length = ansIS.readLength();
167			this._decode(ansIS, length);
168		} catch (IOException e) {
169			throw new MAPParsingComponentException("IOException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e,
170					MAPParsingComponentExceptionReason.MistypedParameter);
171		} catch (AsnException e) {
172			throw new MAPParsingComponentException("AsnException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e,
173					MAPParsingComponentExceptionReason.MistypedParameter);
174		}
175	}
176
177	@Override
178	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
179
180		try {
181			this._decode(ansIS, length);
182		} catch (IOException e) {
183			throw new MAPParsingComponentException("IOException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e,
184					MAPParsingComponentExceptionReason.MistypedParameter);
185		} catch (AsnException e) {
186			throw new MAPParsingComponentException("AsnException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e,
187					MAPParsingComponentExceptionReason.MistypedParameter);
188		}
189	}
190
191	private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
192
193		this.msisdn = null;
194		this.serviceCentreAddress = null;
195		this.sMDeliveryOutcome = null;
196		this.absentSubscriberDiagnosticSM = null;
197		this.extensionContainer = null;
198		this.gprsSupportIndicator = false;
199		this.deliveryOutcomeIndicator = false;
200		this.additionalSMDeliveryOutcome = null;
201		this.additionalAbsentSubscriberDiagnosticSM = null;
202
203		AsnInputStream ais = ansIS.readSequenceStreamData(length);
204		int num = 0;
205		while (true) {
206			if (ais.available() == 0)
207				break;
208
209			int tag = ais.readTag();
210
211			switch (num) {
212			case 0:
213				// msisdn
214				if (tag != Tag.STRING_OCTET || ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive())
215					throw new MAPParsingComponentException("Error while decoding ReportSMDeliveryStatusRequest.msisdn: Parameter bad tag or tag class or not primitive",
216							MAPParsingComponentExceptionReason.MistypedParameter);
217				this.msisdn = new ISDNAddressStringImpl();
218				((ISDNAddressStringImpl)this.msisdn).decodeAll(ais);
219				break;
220				
221			case 1:
222				// serviceCentreAddress
223				if (tag != Tag.STRING_OCTET || ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive())
224					throw new MAPParsingComponentException("Error while decoding ReportSMDeliveryStatusRequest.serviceCentreAddress: Parameter bad tag or tag class or not primitive",
225							MAPParsingComponentExceptionReason.MistypedParameter);
226				this.serviceCentreAddress = new AddressStringImpl();
227				((AddressStringImpl)this.serviceCentreAddress).decodeAll(ais);
228				break;
229				
230			case 2:
231				// sMDeliveryOutcome
232				if (tag != Tag.ENUMERATED || ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive())
233					throw new MAPParsingComponentException("Error while decoding ReportSMDeliveryStatusRequest.sMDeliveryOutcome: Parameter bad tag or tag class or not primitive",
234							MAPParsingComponentExceptionReason.MistypedParameter);
235				int i1 = (int)ais.readInteger();
236				this.sMDeliveryOutcome = SMDeliveryOutcome.getInstance(i1);
237				break;
238				
239			default:
240				if (ais.getTagClass() == Tag.CLASS_CONTEXT_SPECIFIC) {
241
242					switch (tag) {
243					case _TAG_AbsentSubscriberDiagnosticSM:
244						// absentSubscriberDiagnosticSM
245						if (!ais.isTagPrimitive())
246							throw new MAPParsingComponentException(
247									"Error while decoding reportSMDeliveryStatusRequest: Parameter absentSubscriberDiagnosticSM is not primitive",
248									MAPParsingComponentExceptionReason.MistypedParameter);
249						this.absentSubscriberDiagnosticSM = (int)ais.readInteger();
250						break;
251
252					case _TAG_ExtensionContainer:
253						// extensionContainer
254						if (ais.isTagPrimitive())
255							throw new MAPParsingComponentException(
256									"Error while decoding reportSMDeliveryStatusRequest: Parameter extensionContainer is primitive",
257									MAPParsingComponentExceptionReason.MistypedParameter);
258						this.extensionContainer = new MAPExtensionContainerImpl();
259						((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
260						break;
261
262					case _TAG_GprsSupportIndicator:
263						// gprsSupportIndicator
264						if (!ais.isTagPrimitive())
265							throw new MAPParsingComponentException(
266									"Error while decoding reportSMDeliveryStatusRequest: Parameter gprsSupportIndicator is not primitive",
267									MAPParsingComponentExceptionReason.MistypedParameter);
268						ais.readNull();
269						this.gprsSupportIndicator = true;
270						break;
271
272					case _TAG_DeliveryOutcomeIndicator:
273						// deliveryOutcomeIndicator
274						if (!ais.isTagPrimitive())
275							throw new MAPParsingComponentException(
276									"Error while decoding reportSMDeliveryStatusRequest: Parameter deliveryOutcomeIndicator is not primitive",
277									MAPParsingComponentExceptionReason.MistypedParameter);
278						ais.readNull();
279						this.deliveryOutcomeIndicator = true;
280						break;
281
282					case _TAG_AdditionalSMDeliveryOutcome:
283						// additionalSMDeliveryOutcome
284						if (!ais.isTagPrimitive())
285							throw new MAPParsingComponentException(
286									"Error while decoding reportSMDeliveryStatusRequest: Parameter additionalSMDeliveryOutcome is not primitive",
287									MAPParsingComponentExceptionReason.MistypedParameter);
288						i1 = (int) ais.readInteger();
289						this.additionalSMDeliveryOutcome = SMDeliveryOutcome.getInstance(i1);
290						break;
291
292					case _TAG_AdditionalAbsentSubscriberDiagnosticSM:
293						// additionalAbsentSubscriberDiagnosticSM
294						if (!ais.isTagPrimitive())
295							throw new MAPParsingComponentException(
296									"Error while decoding reportSMDeliveryStatusRequest: Parameter additionalAbsentSubscriberDiagnosticSM is not primitive",
297									MAPParsingComponentExceptionReason.MistypedParameter);
298						this.additionalAbsentSubscriberDiagnosticSM = (int)ais.readInteger();
299						break;
300
301					default:
302						ais.advanceElement();
303						break;
304					}
305
306				} else {
307
308					ais.advanceElement();
309				}
310				break;
311			}
312			
313			num++;
314		}
315
316		if (num < 3 && this.mapProtocolVersion >= 2 || num < 2 && this.mapProtocolVersion == 1)
317			throw new MAPParsingComponentException("Error while decoding reportSMDeliveryStatusRequest: Needs at least 3 mandatory parameters, found " + num,
318					MAPParsingComponentExceptionReason.MistypedParameter);
319	}
320
321	@Override
322	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
323
324		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
325	}
326
327	@Override
328	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
329		
330		try {
331			asnOs.writeTag(tagClass, false, tag);
332			int pos = asnOs.StartContentDefiniteLength();
333			this.encodeData(asnOs);
334			asnOs.FinalizeContent(pos);
335		} catch (AsnException e) {
336			throw new MAPException("AsnException when encoding reportSMDeliveryStatusRequest: " + e.getMessage(), e);
337		}
338	}
339
340	@Override
341	public void encodeData(AsnOutputStream asnOs) throws MAPException {
342
343		if (this.mapProtocolVersion == 1) {
344			if (this.msisdn == null || this.serviceCentreAddress == null)
345				throw new MAPException("msisdn and serviceCentreAddress must not be null");
346		} else {
347			if (this.msisdn == null || this.serviceCentreAddress == null || this.sMDeliveryOutcome == null)
348				throw new MAPException("msisdn, serviceCentreAddress and sMDeliveryOutcome must not be null");
349		}
350
351		try {
352			((ISDNAddressStringImpl)this.msisdn).encodeAll(asnOs);
353			((AddressStringImpl)this.serviceCentreAddress).encodeAll(asnOs);
354			if (this.mapProtocolVersion >= 1)
355				asnOs.writeInteger(Tag.CLASS_UNIVERSAL, Tag.ENUMERATED, this.sMDeliveryOutcome.getCode());
356
357			if (this.absentSubscriberDiagnosticSM != null)
358				asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_AbsentSubscriberDiagnosticSM, this.absentSubscriberDiagnosticSM);
359			if (this.extensionContainer != null)
360				((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_ExtensionContainer);
361			if (this.gprsSupportIndicator == true)
362				asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_GprsSupportIndicator);
363			if (this.deliveryOutcomeIndicator == true)
364				asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_DeliveryOutcomeIndicator);
365			if (this.additionalSMDeliveryOutcome != null)
366				asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_AdditionalSMDeliveryOutcome, this.additionalSMDeliveryOutcome.getCode());
367			if (this.additionalAbsentSubscriberDiagnosticSM != null)
368				asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_AdditionalAbsentSubscriberDiagnosticSM, this.additionalAbsentSubscriberDiagnosticSM);
369		} catch (IOException e) {
370			throw new MAPException("IOException when encoding mtForwardShortMessageRequest: " + e.getMessage(), e);
371		} catch (AsnException e) {
372			throw new MAPException("AsnException when encoding mtForwardShortMessageRequest: " + e.getMessage(), e);
373		}
374	}
375	
376	@Override
377	public String toString() {
378		StringBuilder sb = new StringBuilder();
379		sb.append("ReportSMDeliveryStatusRequest [");
380		
381		if (this.msisdn != null) {
382			sb.append("msisdn=");
383			sb.append(this.msisdn.toString());
384		}
385		if (this.serviceCentreAddress != null) {
386			sb.append(", serviceCentreAddress=");
387			sb.append(this.serviceCentreAddress.toString());
388		}
389		if (this.sMDeliveryOutcome != null) {
390			sb.append(", sMDeliveryOutcome=");
391			sb.append(this.sMDeliveryOutcome.toString());
392		}
393		if (this.absentSubscriberDiagnosticSM != null) {
394			sb.append(", absentSubscriberDiagnosticSM=");
395			sb.append(this.absentSubscriberDiagnosticSM.toString());
396		}
397		if (this.extensionContainer != null) {
398			sb.append(", extensionContainer=");
399			sb.append(this.extensionContainer.toString());
400		}
401		if (this.gprsSupportIndicator) {
402			sb.append(", gprsSupportIndicator");
403		}
404		if (this.deliveryOutcomeIndicator) {
405			sb.append(", deliveryOutcomeIndicator");
406		}
407		if (this.additionalSMDeliveryOutcome != null) {
408			sb.append(", additionalSMDeliveryOutcome=");
409			sb.append(this.additionalSMDeliveryOutcome.toString());
410		}
411		if (this.additionalAbsentSubscriberDiagnosticSM != null) {
412			sb.append(", additionalAbsentSubscriberDiagnosticSM=");
413			sb.append(this.additionalAbsentSubscriberDiagnosticSM.toString());
414		}
415
416		sb.append("]");
417
418		return sb.toString();
419	}
420}
421