/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/subscriberManagement/ExtBearerServiceCodeImpl.java
Java | 167 lines | 109 code | 32 blank | 26 comment | 9 complexity | 0fa6d5574d40bfdf8c446250079be949 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.subscriberManagement; 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.service.subscriberManagement.ExtBearerServiceCode; 35import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive; 36 37/** 38 * 39 * @author sergey vetyutnev 40 * 41 */ 42public class ExtBearerServiceCodeImpl implements ExtBearerServiceCode, MAPAsnPrimitive { 43 44 public static final String _PrimitiveName = "ExtBearerServiceCode"; 45 46 private byte[] data; 47 48 49 public ExtBearerServiceCodeImpl() { 50 } 51 52 public ExtBearerServiceCodeImpl(byte[] data) { 53 this.data = data; 54 } 55 56 @Override 57 public byte[] getData() { 58 return data; 59 } 60 61 @Override 62 public int getTag() throws MAPException { 63 return Tag.STRING_OCTET; 64 } 65 66 @Override 67 public int getTagClass() { 68 return Tag.CLASS_UNIVERSAL; 69 } 70 71 @Override 72 public boolean getIsPrimitive() { 73 return true; 74 } 75 76 @Override 77 public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException { 78 79 try { 80 int length = ansIS.readLength(); 81 this._decode(ansIS, length); 82 } catch (IOException e) { 83 throw new MAPParsingComponentException("IOException when decoding " + _PrimitiveName + ": " + e.getMessage(), e, 84 MAPParsingComponentExceptionReason.MistypedParameter); 85 } catch (AsnException e) { 86 throw new MAPParsingComponentException("AsnException when decoding " + _PrimitiveName + ": " + e.getMessage(), e, 87 MAPParsingComponentExceptionReason.MistypedParameter); 88 } 89 } 90 91 @Override 92 public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException { 93 94 try { 95 this._decode(ansIS, length); 96 } catch (IOException e) { 97 throw new MAPParsingComponentException("IOException when decoding " + _PrimitiveName + ": " + e.getMessage(), e, 98 MAPParsingComponentExceptionReason.MistypedParameter); 99 } catch (AsnException e) { 100 throw new MAPParsingComponentException("AsnException when decoding " + _PrimitiveName + ": " + e.getMessage(), e, 101 MAPParsingComponentExceptionReason.MistypedParameter); 102 } 103 } 104 105 private void _decode(AsnInputStream ais, int length) throws MAPParsingComponentException, IOException, AsnException { 106 107 this.data = ais.readOctetStringData(length); 108 if (this.data.length < 1 || this.data.length > 5) 109 throw new MAPParsingComponentException("Error while decoding " + _PrimitiveName + ": octetString must be from 1 to 5 bytes length, found: " 110 + this.data.length, MAPParsingComponentExceptionReason.MistypedParameter); 111 } 112 113 @Override 114 public void encodeAll(AsnOutputStream asnOs) throws MAPException { 115 116 this.encodeAll(asnOs, this.getTagClass(), this.getTag()); 117 } 118 119 @Override 120 public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException { 121 122 try { 123 asnOs.writeTag(tagClass, true, tag); 124 int pos = asnOs.StartContentDefiniteLength(); 125 this.encodeData(asnOs); 126 asnOs.FinalizeContent(pos); 127 } catch (AsnException e) { 128 throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e); 129 } 130 } 131 132 @Override 133 public void encodeData(AsnOutputStream asnOs) throws MAPException { 134 135 if (this.data == null) 136 throw new MAPException("data must not be null"); 137 if (this.data.length < 1 && this.data.length > 5) 138 throw new MAPException("data length must be from 1 to 5"); 139 140 asnOs.writeOctetStringData(data); 141 } 142 143 @Override 144 public String toString() { 145 StringBuilder sb = new StringBuilder(); 146 sb.append("ExtBearerServiceCode ["); 147 148 if (this.data != null) { 149 sb.append("data="); 150 sb.append(printDataArr(this.data)); 151 } 152 153 sb.append("]"); 154 155 return sb.toString(); 156 } 157 158 private String printDataArr(byte[] arr) { 159 StringBuilder sb = new StringBuilder(); 160 for (int b : arr) { 161 sb.append(b); 162 sb.append(" "); 163 } 164 165 return sb.toString(); 166 } 167}