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

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

http://mobicents.googlecode.com/
Java | 217 lines | 149 code | 40 blank | 28 comment | 17 complexity | 145b9ed22ac89ab4189ad6d3f3471d6b 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.MAPExtensionContainer;
 37import org.mobicents.protocols.ss7.map.api.service.sms.MtForwardShortMessageResponseIndication;
 38import org.mobicents.protocols.ss7.map.api.service.sms.SmsSignalInfo;
 39import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
 40
 41/**
 42 * 
 43 * @author sergey vetyutnev
 44 * 
 45 */
 46public class MtForwardShortMessageResponseIndicationImpl extends SmsMessageImpl implements MtForwardShortMessageResponseIndication {
 47
 48	private SmsSignalInfoImpl sM_RP_UI;
 49	private MAPExtensionContainer extensionContainer;
 50	
 51	
 52	public MtForwardShortMessageResponseIndicationImpl() {
 53	}
 54	
 55	public MtForwardShortMessageResponseIndicationImpl(SmsSignalInfo sM_RP_UI, MAPExtensionContainer extensionContainer) {
 56		this.sM_RP_UI = (SmsSignalInfoImpl)sM_RP_UI;
 57		this.extensionContainer = extensionContainer;
 58	}
 59
 60	@Override
 61	public MAPMessageType getMessageType() {
 62		return MAPMessageType.mtForwardSM_Response;
 63	}
 64
 65	@Override
 66	public int getOperationCode() {
 67		return MAPOperationCode.mt_forwardSM;
 68	}
 69	
 70
 71	@Override
 72	public SmsSignalInfo getSM_RP_UI() {
 73		return this.sM_RP_UI;
 74	}
 75
 76	@Override
 77	public MAPExtensionContainer getExtensionContainer() {
 78		return this.extensionContainer;
 79	}
 80
 81	
 82	@Override
 83	public int getTag() throws MAPException {
 84		return Tag.SEQUENCE;
 85	}
 86
 87	@Override
 88	public int getTagClass() {
 89		return Tag.CLASS_UNIVERSAL;
 90	}
 91
 92	@Override
 93	public boolean getIsPrimitive() {
 94		return false;
 95	}
 96
 97	
 98	@Override
 99	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
100
101		try {
102			int length = ansIS.readLength();
103			this._decode(ansIS, length);
104		} catch (IOException e) {
105			throw new MAPParsingComponentException("IOException when decoding mtForwardShortMessageResponse: " + e.getMessage(), e,
106					MAPParsingComponentExceptionReason.MistypedParameter);
107		} catch (AsnException e) {
108			throw new MAPParsingComponentException("AsnException when decoding mtForwardShortMessageResponse: " + e.getMessage(), e,
109					MAPParsingComponentExceptionReason.MistypedParameter);
110		}
111	}
112
113	@Override
114	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
115
116		try {
117			this._decode(ansIS, length);
118		} catch (IOException e) {
119			throw new MAPParsingComponentException("IOException when decoding mtForwardShortMessageResponse: " + e.getMessage(), e,
120					MAPParsingComponentExceptionReason.MistypedParameter);
121		} catch (AsnException e) {
122			throw new MAPParsingComponentException("AsnException when decoding mtForwardShortMessageResponse: " + e.getMessage(), e,
123					MAPParsingComponentExceptionReason.MistypedParameter);
124		}
125	}
126
127	private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
128		
129		this.sM_RP_UI = null;
130		this.extensionContainer = null;
131
132		AsnInputStream ais = ansIS.readSequenceStreamData(length);
133		while (true) {
134			if (ais.available() == 0)
135				break;
136
137			int tag = ais.readTag();
138
139			if (ais.getTagClass() == Tag.CLASS_UNIVERSAL) {
140				switch (tag) {
141				case Tag.STRING_OCTET:
142					// sm-RP-UI
143					if (!ais.isTagPrimitive())
144						throw new MAPParsingComponentException("Error while decoding mtForwardShortMessageResponse: Parameter sm-RP-UI is not primitive",
145								MAPParsingComponentExceptionReason.MistypedParameter);
146					this.sM_RP_UI = new SmsSignalInfoImpl();
147					this.sM_RP_UI.decodeAll(ais);
148					break;
149
150				case Tag.SEQUENCE:
151					// ExtensionContainer
152					if (ais.isTagPrimitive())
153						throw new MAPParsingComponentException("Error while decoding mtForwardShortMessageResponse: Parameter extensionContainer is primitive",
154								MAPParsingComponentExceptionReason.MistypedParameter);
155					this.extensionContainer = new MAPExtensionContainerImpl();
156					((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
157					break;
158
159				default:
160					ais.advanceElement();
161					break;
162				}
163
164			} else {
165				ais.advanceElement();
166			}
167		}
168	}
169
170	@Override
171	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
172
173		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
174	}
175
176	@Override
177	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
178		
179		try {
180			asnOs.writeTag(tagClass, false, tag);
181			int pos = asnOs.StartContentDefiniteLength();
182			this.encodeData(asnOs);
183			asnOs.FinalizeContent(pos);
184		} catch (AsnException e) {
185			throw new MAPException("AsnException when encoding mtForwardShortMessageResponse: " + e.getMessage(), e);
186		}
187	}
188
189	@Override
190	public void encodeData(AsnOutputStream asnOs) throws MAPException {
191
192		if (this.sM_RP_UI != null)
193			this.sM_RP_UI.encodeAll(asnOs);
194		if (this.extensionContainer != null)
195			((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs);
196	}	
197	
198	@Override
199	public String toString() {
200		StringBuilder sb = new StringBuilder();
201		sb.append("MoForwardShortMessageResponse [");
202
203		if (this.sM_RP_UI != null) {
204			sb.append(", sm_RP_UI=[");
205			sb.append(this.sM_RP_UI.toString());
206			sb.append("]");
207		}
208		if (this.extensionContainer != null) {
209			sb.append(", extensionContainer=");
210			sb.append(this.extensionContainer.toString());
211		}
212
213		sb.append("]");
214
215		return sb.toString();
216	}
217}