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