/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/errors/MAPErrorMessageAbsentSubscriberImpl.java
Java | 244 lines | 170 code | 48 blank | 26 comment | 23 complexity | a69a5f9134746a1839b274eda632080e 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.errors; 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.MAPParsingComponentException; 33import org.mobicents.protocols.ss7.map.api.MAPParsingComponentExceptionReason; 34import org.mobicents.protocols.ss7.map.api.errors.AbsentSubscriberReason; 35import org.mobicents.protocols.ss7.map.api.errors.MAPErrorCode; 36import org.mobicents.protocols.ss7.map.api.errors.MAPErrorMessageAbsentSubscriber; 37import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer; 38import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl; 39 40/** 41 * 42 * @author sergey vetyutnev 43 * 44 */ 45public class MAPErrorMessageAbsentSubscriberImpl extends MAPErrorMessageImpl implements MAPErrorMessageAbsentSubscriber { 46 47 public static final int AbsentSubscriberReason_TAG = 0; 48 49 private MAPExtensionContainer extensionContainer; 50 private AbsentSubscriberReason absentSubscriberReason; 51 52 53 public MAPErrorMessageAbsentSubscriberImpl(MAPExtensionContainer extensionContainer, AbsentSubscriberReason absentSubscriberReason) { 54 super((long) MAPErrorCode.absentSubscriber); 55 56 this.extensionContainer = extensionContainer; 57 this.absentSubscriberReason = absentSubscriberReason; 58 } 59 60 protected MAPErrorMessageAbsentSubscriberImpl() { 61 super((long) MAPErrorCode.absentSubscriber); 62 } 63 64 65 @Override 66 public boolean isEmAbsentSubscriber() { 67 return true; 68 } 69 70 @Override 71 public MAPErrorMessageAbsentSubscriber getEmAbsentSubscriber() { 72 return this; 73 } 74 75 @Override 76 public MAPExtensionContainer getExtensionContainer() { 77 return this.extensionContainer; 78 } 79 80 @Override 81 public AbsentSubscriberReason getAbsentSubscriberReason() { 82 return this.absentSubscriberReason; 83 } 84 85 @Override 86 public void setExtensionContainer(MAPExtensionContainer extensionContainer) { 87 this.extensionContainer = extensionContainer; 88 } 89 90 @Override 91 public void setAbsentSubscriberReason(AbsentSubscriberReason absentSubscriberReason) { 92 this.absentSubscriberReason = absentSubscriberReason; 93 } 94 95 96 @Override 97 public int getTag() throws MAPException { 98 return Tag.SEQUENCE; 99 } 100 101 @Override 102 public int getTagClass() { 103 return Tag.CLASS_UNIVERSAL; 104 } 105 106 @Override 107 public boolean getIsPrimitive() { 108 return false; 109 } 110 111 @Override 112 public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException { 113 114 try { 115 int length = ansIS.readLength(); 116 this._decode(ansIS, length); 117 } catch (IOException e) { 118 throw new MAPParsingComponentException("IOException when decoding MAPErrorMessageAbsentSubscriber: " + e.getMessage(), e, 119 MAPParsingComponentExceptionReason.MistypedParameter); 120 } catch (AsnException e) { 121 throw new MAPParsingComponentException("AsnException when decoding MAPErrorMessageAbsentSubscriber: " + e.getMessage(), e, 122 MAPParsingComponentExceptionReason.MistypedParameter); 123 } 124 } 125 126 @Override 127 public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException { 128 129 try { 130 this._decode(ansIS, length); 131 } catch (IOException e) { 132 throw new MAPParsingComponentException("IOException when decoding MAPErrorMessageAbsentSubscriber: " + e.getMessage(), e, 133 MAPParsingComponentExceptionReason.MistypedParameter); 134 } catch (AsnException e) { 135 throw new MAPParsingComponentException("AsnException when decoding MAPErrorMessageAbsentSubscriber: " + e.getMessage(), e, 136 MAPParsingComponentExceptionReason.MistypedParameter); 137 } 138 } 139 140 private void _decode(AsnInputStream localAis, int length) throws MAPParsingComponentException, IOException, AsnException { 141 142 this.extensionContainer = null; 143 this.absentSubscriberReason = null; 144 145 if (localAis.getTagClass() != Tag.CLASS_UNIVERSAL || localAis.getTag() != Tag.SEQUENCE || localAis.isTagPrimitive()) 146 throw new MAPParsingComponentException( 147 "Error decoding MAPErrorMessageAbsentSubscriber: bad tag class or tag or parameter is primitive", 148 MAPParsingComponentExceptionReason.MistypedParameter); 149 150 AsnInputStream ais = localAis.readSequenceStreamData(length); 151 152 while (true) { 153 if (ais.available() == 0) 154 break; 155 156 int tag = ais.readTag(); 157 158 switch (ais.getTagClass()) { 159 case Tag.CLASS_UNIVERSAL: 160 switch (tag) { 161 case Tag.SEQUENCE: 162 this.extensionContainer = new MAPExtensionContainerImpl(); 163 ((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais); 164 break; 165 166 default: 167 ais.advanceElement(); 168 break; 169 } 170 break; 171 172 case Tag.CLASS_CONTEXT_SPECIFIC: 173 switch (tag) { 174 case AbsentSubscriberReason_TAG: 175 int code = (int) ais.readInteger(); 176 this.absentSubscriberReason = AbsentSubscriberReason.getInstance(code); 177 break; 178 179 default: 180 ais.advanceElement(); 181 break; 182 } 183 break; 184 185 default: 186 ais.advanceElement(); 187 break; 188 } 189 } 190 } 191 192 @Override 193 public void encodeAll(AsnOutputStream asnOs) throws MAPException { 194 195 this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE); 196 } 197 198 @Override 199 public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException { 200 201 try { 202 asnOs.writeTag(tagClass, false, tag); 203 int pos = asnOs.StartContentDefiniteLength(); 204 this.encodeData(asnOs); 205 asnOs.FinalizeContent(pos); 206 } catch (AsnException e) { 207 throw new MAPException("AsnException when encoding MAPErrorMessageAbsentSubscriber: " + e.getMessage(), e); 208 } 209 } 210 211 @Override 212 public void encodeData(AsnOutputStream aos) throws MAPException { 213 214 if (this.absentSubscriberReason == null && this.extensionContainer == null) 215 return; 216 217 try { 218 if (this.extensionContainer != null) 219 ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(aos); 220 if (this.absentSubscriberReason != null) 221 aos.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, AbsentSubscriberReason_TAG, this.absentSubscriberReason.getCode()); 222 223 } catch (IOException e) { 224 throw new MAPException("IOException when encoding MAPErrorMessageAbsentSubscriber: " + e.getMessage(), e); 225 } catch (AsnException e) { 226 throw new MAPException("AsnException when encoding MAPErrorMessageAbsentSubscriber: " + e.getMessage(), e); 227 } 228 } 229 230 @Override 231 public String toString() { 232 StringBuilder sb = new StringBuilder(); 233 234 sb.append("MAPErrorMessageAbsentSubscriber ["); 235 if (this.extensionContainer != null) 236 sb.append("extensionContainer=" + this.extensionContainer.toString()); 237 if (this.absentSubscriberReason != null) 238 sb.append(", absentSubscriberReason=" + this.absentSubscriberReason.toString()); 239 sb.append("]"); 240 241 return sb.toString(); 242 } 243 244}