PageRenderTime 16ms CodeModel.GetById 1ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 303 lines | 225 code | 47 blank | 31 comment | 36 complexity | 9ffba24f7c0b6b28467f0686bf05c54f 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.ISDNAddressString;
 37import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
 38import org.mobicents.protocols.ss7.map.api.service.sms.InformServiceCentreRequestIndication;
 39import org.mobicents.protocols.ss7.map.api.service.sms.MWStatus;
 40import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
 41import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
 42
 43/**
 44 * 
 45 * @author sergey vetyutnev
 46 * 
 47 */
 48public class InformServiceCentreRequestIndicationImpl extends SmsMessageImpl implements InformServiceCentreRequestIndication {
 49	
 50	protected static final int _TAG_AdditionalAbsentSubscriberDiagnosticSM = 0;
 51
 52	private ISDNAddressString storedMSISDN;
 53	private MWStatus mwStatus;
 54	private MAPExtensionContainer extensionContainer;
 55	private Integer absentSubscriberDiagnosticSM;
 56	private Integer additionalAbsentSubscriberDiagnosticSM;
 57	
 58	public InformServiceCentreRequestIndicationImpl() {
 59	}
 60	
 61	public InformServiceCentreRequestIndicationImpl(ISDNAddressString storedMSISDN, MWStatus mwStatus, MAPExtensionContainer extensionContainer,
 62			Integer absentSubscriberDiagnosticSM, Integer additionalAbsentSubscriberDiagnosticSM) {
 63		this.storedMSISDN = storedMSISDN;
 64		this.mwStatus = mwStatus;
 65		this.extensionContainer = extensionContainer;
 66		this.absentSubscriberDiagnosticSM = absentSubscriberDiagnosticSM;
 67		this.additionalAbsentSubscriberDiagnosticSM = additionalAbsentSubscriberDiagnosticSM;
 68	}
 69
 70	@Override
 71	public MAPMessageType getMessageType() {
 72		return MAPMessageType.InformServiceCentre_Request;
 73	}
 74
 75	@Override
 76	public int getOperationCode() {
 77		return MAPOperationCode.informServiceCentre;
 78	}
 79
 80	@Override
 81	public ISDNAddressString getStoredMSISDN() {
 82		return this.storedMSISDN;
 83	}
 84
 85	@Override
 86	public MWStatus getMwStatus() {
 87		return this.mwStatus;
 88	}
 89
 90	@Override
 91	public MAPExtensionContainer getExtensionContainer() {
 92		return this.extensionContainer;
 93	}
 94
 95	@Override
 96	public Integer getAbsentSubscriberDiagnosticSM() {
 97		return this.absentSubscriberDiagnosticSM;
 98	}
 99
100	@Override
101	public Integer getAdditionalAbsentSubscriberDiagnosticSM() {
102		return this.additionalAbsentSubscriberDiagnosticSM;
103	}
104
105	
106	@Override
107	public int getTag() throws MAPException {
108		return Tag.SEQUENCE;
109	}
110
111	@Override
112	public int getTagClass() {
113		return Tag.CLASS_UNIVERSAL;
114	}
115
116	@Override
117	public boolean getIsPrimitive() {
118		return false;
119	}
120
121	
122	@Override
123	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
124
125		try {
126			int length = ansIS.readLength();
127			this._decode(ansIS, length);
128		} catch (IOException e) {
129			throw new MAPParsingComponentException("IOException when decoding InformServiceCentreRequest: " + e.getMessage(), e,
130					MAPParsingComponentExceptionReason.MistypedParameter);
131		} catch (AsnException e) {
132			throw new MAPParsingComponentException("AsnException when decoding InformServiceCentreRequest: " + e.getMessage(), e,
133					MAPParsingComponentExceptionReason.MistypedParameter);
134		}
135	}
136
137	@Override
138	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
139
140		try {
141			this._decode(ansIS, length);
142		} catch (IOException e) {
143			throw new MAPParsingComponentException("IOException when decoding InformServiceCentreRequest: " + e.getMessage(), e,
144					MAPParsingComponentExceptionReason.MistypedParameter);
145		} catch (AsnException e) {
146			throw new MAPParsingComponentException("AsnException when decoding InformServiceCentreRequest: " + e.getMessage(), e,
147					MAPParsingComponentExceptionReason.MistypedParameter);
148		}
149	}
150
151	private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
152
153		this.storedMSISDN = null;
154		this.mwStatus = null;
155		this.extensionContainer = null;
156		this.absentSubscriberDiagnosticSM = null;
157		this.additionalAbsentSubscriberDiagnosticSM = null;
158
159		AsnInputStream ais = ansIS.readSequenceStreamData(length);
160		while (true) {
161			if (ais.available() == 0)
162				break;
163
164			int tag = ais.readTag();
165
166			if (ais.getTagClass() == Tag.CLASS_UNIVERSAL) {
167
168				switch (tag) {
169				case Tag.STRING_OCTET:
170					// storedMSISDN
171					if (!ais.isTagPrimitive())
172						throw new MAPParsingComponentException("Error while decoding informServiceCentreRequest: Parameter storedMSISDN is not primitive",
173								MAPParsingComponentExceptionReason.MistypedParameter);
174					storedMSISDN = new ISDNAddressStringImpl();
175					((ISDNAddressStringImpl)storedMSISDN).decodeAll(ais);
176					break;
177
178				case Tag.STRING_BIT:
179					// mw-Status
180					if (!ais.isTagPrimitive())
181						throw new MAPParsingComponentException("Error while decoding informServiceCentreRequest: Parameter mw-Status is not primitive",
182								MAPParsingComponentExceptionReason.MistypedParameter);
183					mwStatus = new MWStatusImpl();
184					((MWStatusImpl)mwStatus).decodeAll(ais);
185					break;
186
187				case Tag.SEQUENCE:
188					// extensionContainer
189					if (ais.isTagPrimitive())
190						throw new MAPParsingComponentException("Error while decoding reportSMDeliveryStatusRequest: Parameter extensionContainer is primitive",
191								MAPParsingComponentExceptionReason.MistypedParameter);
192					extensionContainer = new MAPExtensionContainerImpl();
193					((MAPExtensionContainerImpl)extensionContainer).decodeAll(ais);
194					break;
195
196				case Tag.INTEGER:
197					// absentSubscriberDiagnosticSM
198					if (!ais.isTagPrimitive())
199						throw new MAPParsingComponentException(
200								"Error while decoding informServiceCentreRequest: Parameter absentSubscriberDiagnosticSM is not primitive",
201								MAPParsingComponentExceptionReason.MistypedParameter);
202					absentSubscriberDiagnosticSM = (int) ais.readInteger();
203					break;
204
205				default:
206					ais.advanceElement();
207					break;
208				}
209			} else if (ais.getTagClass() == Tag.CLASS_CONTEXT_SPECIFIC) {
210
211				switch (tag) {
212				case InformServiceCentreRequestIndicationImpl._TAG_AdditionalAbsentSubscriberDiagnosticSM:
213					// additionalAbsentSubscriberDiagnosticSM
214					if (!ais.isTagPrimitive())
215						throw new MAPParsingComponentException(
216								"Error while decoding informServiceCentreRequest: Parameter deliveryOutcomeIndicator is not primitive",
217								MAPParsingComponentExceptionReason.MistypedParameter);
218					additionalAbsentSubscriberDiagnosticSM = (int) ais.readInteger();
219					break;
220
221				default:
222					ais.advanceElement();
223					break;
224				}
225			} else {
226				ais.advanceElement();
227			}
228		}
229	}
230
231	@Override
232	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
233
234		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
235	}
236
237	@Override
238	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
239		
240		try {
241			asnOs.writeTag(tagClass, false, tag);
242			int pos = asnOs.StartContentDefiniteLength();
243			this.encodeData(asnOs);
244			asnOs.FinalizeContent(pos);
245		} catch (AsnException e) {
246			throw new MAPException("AsnException when encoding InformServiceCentreRequest: " + e.getMessage(), e);
247		}
248	}
249
250	@Override
251	public void encodeData(AsnOutputStream asnOs) throws MAPException {
252
253		if (this.storedMSISDN != null)
254			((ISDNAddressStringImpl)this.storedMSISDN).encodeAll(asnOs);
255		if (this.mwStatus != null)
256			((MWStatusImpl)this.mwStatus).encodeAll(asnOs);
257		if (this.extensionContainer != null)
258			((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs);
259		try {
260			if (this.absentSubscriberDiagnosticSM != null)
261				asnOs.writeInteger(this.absentSubscriberDiagnosticSM);
262			if (this.additionalAbsentSubscriberDiagnosticSM != null)
263				asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, InformServiceCentreRequestIndicationImpl._TAG_AdditionalAbsentSubscriberDiagnosticSM,
264						this.additionalAbsentSubscriberDiagnosticSM);
265		} catch (IOException e) {
266			throw new MAPException("IOException when encoding InformServiceCentreRequest: " + e.getMessage(), e);
267		} catch (AsnException e) {
268			throw new MAPException("AsnException when encoding InformServiceCentreRequest: " + e.getMessage(), e);
269		}
270	}
271	
272	@Override
273	public String toString() {
274		StringBuilder sb = new StringBuilder();
275		sb.append("InformServiceCentreRequest [");
276
277		if (this.storedMSISDN != null) {
278			sb.append("storedMSISDN=");
279			sb.append(this.storedMSISDN.toString());
280		}
281		if (this.mwStatus != null) {
282			sb.append(", mwStatus=");
283			sb.append(this.mwStatus.toString());
284		}
285		if (this.extensionContainer != null) {
286			sb.append(", extensionContainer=");
287			sb.append(this.extensionContainer.toString());
288		}
289		if (this.absentSubscriberDiagnosticSM != null) {
290			sb.append(", absentSubscriberDiagnosticSM=");
291			sb.append(this.absentSubscriberDiagnosticSM.toString());
292		}
293		if (this.additionalAbsentSubscriberDiagnosticSM != null) {
294			sb.append(", additionalAbsentSubscriberDiagnosticSM=");
295			sb.append(this.additionalAbsentSubscriberDiagnosticSM.toString());
296		}
297
298		sb.append("]");
299
300		return sb.toString();
301	}
302	
303}