/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/sms/SendRoutingInfoForSMRequestIndicationImpl.java
Java | 360 lines | 274 code | 57 blank | 29 comment | 51 complexity | 8e2fdd24fe961b063dafdd7cea74cc0e 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.SM_RP_MTI; 40import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_SMEA; 41import org.mobicents.protocols.ss7.map.api.service.sms.SendRoutingInfoForSMRequestIndication; 42import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl; 43import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl; 44import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl; 45 46/** 47 * 48 * @author sergey vetyutnev 49 * 50 */ 51public class SendRoutingInfoForSMRequestIndicationImpl extends SmsMessageImpl implements SendRoutingInfoForSMRequestIndication { 52 53 protected static final int _TAG_msisdn = 0; 54 protected static final int _TAG_sm_RP_PRI = 1; 55 protected static final int _TAG_serviceCentreAddress = 2; 56 protected static final int _TAG_extensionContainer = 6; 57 protected static final int _TAG_gprsSupportIndicator = 7; 58 protected static final int _TAG_sm_RP_MTI = 8; 59 protected static final int _TAG_sm_RP_SMEA = 9; 60 61 private ISDNAddressString msisdn; 62 private boolean sm_RP_PRI; 63 private AddressString serviceCentreAddress; 64 private MAPExtensionContainer extensionContainer; 65 private boolean gprsSupportIndicator; 66 private SM_RP_MTI sM_RP_MTI; 67 private SM_RP_SMEAImpl sM_RP_SMEA; 68 69 70 public SendRoutingInfoForSMRequestIndicationImpl() { 71 } 72 73 public SendRoutingInfoForSMRequestIndicationImpl(ISDNAddressString msisdn, boolean sm_RP_PRI, AddressString serviceCentreAddress, 74 MAPExtensionContainer extensionContainer, boolean gprsSupportIndicator, SM_RP_MTI sM_RP_MTI, SM_RP_SMEA sM_RP_SMEA) { 75 this.msisdn = msisdn; 76 this.sm_RP_PRI = sm_RP_PRI; 77 this.serviceCentreAddress = serviceCentreAddress; 78 this.extensionContainer = extensionContainer; 79 this.gprsSupportIndicator = gprsSupportIndicator; 80 this.sM_RP_MTI = sM_RP_MTI; 81 this.sM_RP_SMEA = (SM_RP_SMEAImpl)sM_RP_SMEA; 82 } 83 84 @Override 85 public MAPMessageType getMessageType() { 86 return MAPMessageType.sendRoutingInfoForSM_Request; 87 } 88 89 @Override 90 public int getOperationCode() { 91 return MAPOperationCode.sendRoutingInfoForSM; 92 } 93 94 @Override 95 public ISDNAddressString getMsisdn() { 96 return this.msisdn; 97 } 98 99 @Override 100 public boolean getSm_RP_PRI() { 101 return this.sm_RP_PRI; 102 } 103 104 @Override 105 public AddressString getServiceCentreAddress() { 106 return this.serviceCentreAddress; 107 } 108 109 @Override 110 public MAPExtensionContainer getExtensionContainer() { 111 return this.extensionContainer; 112 } 113 114 @Override 115 public boolean getGprsSupportIndicator() { 116 return this.gprsSupportIndicator; 117 } 118 119 @Override 120 public SM_RP_MTI getSM_RP_MTI() { 121 return this.sM_RP_MTI; 122 } 123 124 @Override 125 public SM_RP_SMEA getSM_RP_SMEA() { 126 return this.sM_RP_SMEA; 127 } 128 129 130 @Override 131 public int getTag() throws MAPException { 132 return Tag.SEQUENCE; 133 } 134 135 @Override 136 public int getTagClass() { 137 return Tag.CLASS_UNIVERSAL; 138 } 139 140 @Override 141 public boolean getIsPrimitive() { 142 return false; 143 } 144 145 146 @Override 147 public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException { 148 149 try { 150 int length = ansIS.readLength(); 151 this._decode(ansIS, length); 152 } catch (IOException e) { 153 throw new MAPParsingComponentException("IOException when decoding sendRoutingInfoForSMRequest: " + e.getMessage(), e, 154 MAPParsingComponentExceptionReason.MistypedParameter); 155 } catch (AsnException e) { 156 throw new MAPParsingComponentException("AsnException when decoding sendRoutingInfoForSMRequest: " + e.getMessage(), e, 157 MAPParsingComponentExceptionReason.MistypedParameter); 158 } 159 } 160 161 @Override 162 public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException { 163 164 try { 165 this._decode(ansIS, length); 166 } catch (IOException e) { 167 throw new MAPParsingComponentException("IOException when decoding sendRoutingInfoForSMRequest: " + e.getMessage(), e, 168 MAPParsingComponentExceptionReason.MistypedParameter); 169 } catch (AsnException e) { 170 throw new MAPParsingComponentException("AsnException when decoding sendRoutingInfoForSMRequest: " + e.getMessage(), e, 171 MAPParsingComponentExceptionReason.MistypedParameter); 172 } 173 } 174 175 private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException { 176 177 this.msisdn = null; 178 this.sm_RP_PRI = false; 179 this.serviceCentreAddress = null; 180 this.extensionContainer = null; 181 this.gprsSupportIndicator = false; 182 this.sM_RP_MTI = null; 183 this.sM_RP_SMEA = null; 184 185 AsnInputStream ais = ansIS.readSequenceStreamData(length); 186 int num = 0; 187 while (true) { 188 if (ais.available() == 0) 189 break; 190 191 int tag = ais.readTag(); 192 193 switch (num) { 194 case 0: 195 // msisdn 196 if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive() || tag != _TAG_msisdn) 197 throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMRequest.msisdn: Parameter bad tag or tag class or not primitive", 198 MAPParsingComponentExceptionReason.MistypedParameter); 199 this.msisdn = new ISDNAddressStringImpl(); 200 ((ISDNAddressStringImpl)this.msisdn).decodeAll(ais); 201 break; 202 203 case 1: 204 // sm-RP-PRI 205 if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive() || tag != _TAG_sm_RP_PRI) 206 throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMRequest.sm-RP-PRI: Parameter 1 bad tag class or tag or not primitive", 207 MAPParsingComponentExceptionReason.MistypedParameter); 208 this.sm_RP_PRI = ais.readBoolean(); 209 break; 210 211 case 2: 212 // serviceCentreAddress 213 if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive() || tag != _TAG_serviceCentreAddress) 214 throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMRequest.serviceCentreAddress: Parameter 2 bad tag class or tag or not primitive", 215 MAPParsingComponentExceptionReason.MistypedParameter); 216 this.serviceCentreAddress = new ISDNAddressStringImpl(); 217 ((AddressStringImpl)this.serviceCentreAddress).decodeAll(ais); 218 break; 219 220 default: 221 if (ais.getTagClass() == Tag.CLASS_CONTEXT_SPECIFIC) { 222 223 switch (tag) { 224 case _TAG_extensionContainer: 225 if (ais.isTagPrimitive()) 226 throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMRequest.extensionContainer: Parameter extensionContainer is primitive", 227 MAPParsingComponentExceptionReason.MistypedParameter); 228 this.extensionContainer = new MAPExtensionContainerImpl(); 229 ((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais); 230 break; 231 232 case _TAG_gprsSupportIndicator: 233 if (!ais.isTagPrimitive()) 234 throw new MAPParsingComponentException( 235 "Error while decoding sendRoutingInfoForSMRequest.gprsSupportIndicator: Parameter gprsSupportIndicator is not primitive", 236 MAPParsingComponentExceptionReason.MistypedParameter); 237 ais.readNull(); 238 this.gprsSupportIndicator = true; 239 break; 240 241 case _TAG_sm_RP_MTI: 242 if (!ais.isTagPrimitive()) 243 throw new MAPParsingComponentException( 244 "Error while decoding sendRoutingInfoForSMRequest.sM_RP_MTI: Parameter sM_RP_MTI is not primitive", 245 MAPParsingComponentExceptionReason.MistypedParameter); 246 int i1 = (int)ais.readInteger(); 247 this.sM_RP_MTI = SM_RP_MTI.getInstance(i1); 248 break; 249 250 case _TAG_sm_RP_SMEA: 251 if (!ais.isTagPrimitive()) 252 throw new MAPParsingComponentException( 253 "Error while decoding sendRoutingInfoForSMRequest.sM_RP_SMEA: Parameter sM_RP_SMEA is not primitive", 254 MAPParsingComponentExceptionReason.MistypedParameter); 255 this.sM_RP_SMEA = new SM_RP_SMEAImpl(); 256 this.sM_RP_SMEA.decodeAll(ais); 257 break; 258 259 default: 260 ais.advanceElement(); 261 break; 262 } 263 264 } else { 265 266 ais.advanceElement(); 267 } 268 break; 269 } 270 271 num++; 272 } 273 274 if (num < 3) 275 throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMRequest: Needs at least 3 mandatory parameters, found " + num, 276 MAPParsingComponentExceptionReason.MistypedParameter); 277 } 278 279 @Override 280 public void encodeAll(AsnOutputStream asnOs) throws MAPException { 281 282 this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE); 283 } 284 285 @Override 286 public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException { 287 288 try { 289 asnOs.writeTag(tagClass, false, tag); 290 int pos = asnOs.StartContentDefiniteLength(); 291 this.encodeData(asnOs); 292 asnOs.FinalizeContent(pos); 293 } catch (AsnException e) { 294 throw new MAPException("AsnException when encoding sendRoutingInfoForSMRequest: " + e.getMessage(), e); 295 } 296 } 297 298 @Override 299 public void encodeData(AsnOutputStream asnOs) throws MAPException { 300 301 if (msisdn == null || serviceCentreAddress == null) 302 throw new MAPException("msisdn, sm_RP_PRI and serviceCentreAddress must not be null"); 303 304 try { 305 ((ISDNAddressStringImpl)this.msisdn).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_msisdn); 306 asnOs.writeBoolean(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_sm_RP_PRI, this.sm_RP_PRI); 307 ((AddressStringImpl)this.serviceCentreAddress).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_serviceCentreAddress); 308 309 if (this.extensionContainer != null) 310 ((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_extensionContainer); 311 if (this.gprsSupportIndicator == true) 312 asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_gprsSupportIndicator); 313 if (this.sM_RP_MTI != null) 314 asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_sm_RP_MTI, this.sM_RP_MTI.getCode()); 315 if (this.sM_RP_SMEA != null) 316 this.sM_RP_SMEA.encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_sm_RP_SMEA); 317 318 } catch (IOException e) { 319 throw new MAPException("IOException when encoding sendRoutingInfoForSMRequest: " + e.getMessage(), e); 320 } catch (AsnException e) { 321 throw new MAPException("AsnException when encoding sendRoutingInfoForSMRequest: " + e.getMessage(), e); 322 } 323 } 324 325 @Override 326 public String toString() { 327 StringBuilder sb = new StringBuilder(); 328 sb.append("SendRoutingInfoForSMRequest ["); 329 330 if (this.msisdn != null) { 331 sb.append("msisdn="); 332 sb.append(this.msisdn.toString()); 333 } 334 sb.append(", sm_RP_PRI="); 335 sb.append(((Boolean)this.sm_RP_PRI).toString()); 336 if (this.serviceCentreAddress != null) { 337 sb.append(", serviceCentreAddress="); 338 sb.append(this.serviceCentreAddress.toString()); 339 } 340 if (this.extensionContainer != null) { 341 sb.append(", extensionContainer="); 342 sb.append(this.extensionContainer.toString()); 343 } 344 if (this.gprsSupportIndicator) { 345 sb.append(", gprsSupportIndicator"); 346 } 347 if (this.sM_RP_MTI != null) { 348 sb.append(", sM_RP_MTI="); 349 sb.append(this.sM_RP_MTI.toString()); 350 } 351 if (this.sM_RP_SMEA != null) { 352 sb.append(", sM_RP_SMEA="); 353 sb.append(this.sM_RP_SMEA.toString()); 354 } 355 356 sb.append("]"); 357 358 return sb.toString(); 359 } 360}