/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/lsm/AreaDefinitionImpl.java
Java | 246 lines | 128 code | 25 blank | 93 comment | 24 complexity | 98a42cb3854b151825b522f642b95cc3 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.lsm; 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.lsm.AreaDefinition; 35import org.mobicents.protocols.ss7.map.api.service.lsm.AreaList; 36import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive; 37 38/** 39 * @author amit bhayani 40 * 41 */ 42public class AreaDefinitionImpl implements AreaDefinition, MAPAsnPrimitive { 43 44 private AreaList areaList = null; 45 46 /** 47 * 48 */ 49 public AreaDefinitionImpl() { 50 super(); 51 } 52 53 /** 54 * @param areaList 55 */ 56 public AreaDefinitionImpl(AreaList areaList) { 57 super(); 58 this.areaList = areaList; 59 } 60 61 /* 62 * (non-Javadoc) 63 * 64 * @see 65 * org.mobicents.protocols.ss7.map.api.service.lsm.AreaDefinition#getAreaList 66 * () 67 */ 68 @Override 69 public AreaList getAreaList() { 70 return this.areaList; 71 } 72 73 /* 74 * (non-Javadoc) 75 * 76 * @see 77 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTag() 78 */ 79 @Override 80 public int getTag() throws MAPException { 81 return Tag.SEQUENCE; 82 } 83 84 /* 85 * (non-Javadoc) 86 * 87 * @see 88 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTagClass 89 * () 90 */ 91 @Override 92 public int getTagClass() { 93 return Tag.CLASS_UNIVERSAL; 94 } 95 96 /* 97 * (non-Javadoc) 98 * 99 * @see 100 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getIsPrimitive 101 * () 102 */ 103 @Override 104 public boolean getIsPrimitive() { 105 return false; 106 } 107 108 /* 109 * (non-Javadoc) 110 * 111 * @see 112 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeAll 113 * (org.mobicents.protocols.asn.AsnInputStream) 114 */ 115 @Override 116 public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException { 117 try { 118 int length = ansIS.readLength(); 119 this._decode(ansIS, length); 120 } catch (IOException e) { 121 throw new MAPParsingComponentException("IOException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e, 122 MAPParsingComponentExceptionReason.MistypedParameter); 123 } catch (AsnException e) { 124 throw new MAPParsingComponentException("AsnException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e, 125 MAPParsingComponentExceptionReason.MistypedParameter); 126 } 127 } 128 129 /* 130 * (non-Javadoc) 131 * 132 * @see 133 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeData 134 * (org.mobicents.protocols.asn.AsnInputStream, int) 135 */ 136 @Override 137 public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException { 138 try { 139 this._decode(ansIS, length); 140 } catch (IOException e) { 141 throw new MAPParsingComponentException("IOException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e, 142 MAPParsingComponentExceptionReason.MistypedParameter); 143 } catch (AsnException e) { 144 throw new MAPParsingComponentException("AsnException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e, 145 MAPParsingComponentExceptionReason.MistypedParameter); 146 } 147 } 148 149 private void _decode(AsnInputStream asnIS, int length) throws MAPParsingComponentException, IOException, AsnException { 150 AsnInputStream ais = asnIS.readSequenceStreamData(length); 151 152 int tag = ais.readTag(); 153 154 if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || ais.isTagPrimitive() || tag != 0) { 155 throw new MAPParsingComponentException( 156 "Error while decoding AreaDefinition: Parameter 0 [areaList [0] AreaList] bad tag class, tag or not primitive", 157 MAPParsingComponentExceptionReason.MistypedParameter); 158 } 159 160 this.areaList = new AreaListImpl(); 161 ((AreaListImpl) this.areaList).decodeAll(ais); 162 163 while (true) { 164 if (ais.available() == 0) 165 break; 166 switch (ais.readTag()) { 167 default: 168 ais.advanceElement(); 169 break; 170 } 171 } 172 } 173 174 /* 175 * (non-Javadoc) 176 * 177 * @see 178 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll 179 * (org.mobicents.protocols.asn.AsnOutputStream) 180 */ 181 @Override 182 public void encodeAll(AsnOutputStream asnOs) throws MAPException { 183 this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE); 184 } 185 186 /* 187 * (non-Javadoc) 188 * 189 * @see 190 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll 191 * (org.mobicents.protocols.asn.AsnOutputStream, int, int) 192 */ 193 @Override 194 public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException { 195 try { 196 asnOs.writeTag(tagClass, false, tag); 197 int pos = asnOs.StartContentDefiniteLength(); 198 this.encodeData(asnOs); 199 asnOs.FinalizeContent(pos); 200 } catch (AsnException e) { 201 throw new MAPException("AsnException when encoding reportSMDeliveryStatusRequest: " + e.getMessage(), e); 202 } 203 } 204 205 /* 206 * (non-Javadoc) 207 * 208 * @see 209 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeData 210 * (org.mobicents.protocols.asn.AsnOutputStream) 211 */ 212 @Override 213 public void encodeData(AsnOutputStream asnOs) throws MAPException { 214 if (this.areaList == null) { 215 throw new MAPException("Error while encoding AreaDefinition the mandatory parameter[areaList [0] AreaList] is not defined"); 216 } 217 218 ((AreaListImpl) this.areaList).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, 0); 219 } 220 221 @Override 222 public int hashCode() { 223 final int prime = 31; 224 int result = 1; 225 result = prime * result + ((areaList == null) ? 0 : areaList.hashCode()); 226 return result; 227 } 228 229 @Override 230 public boolean equals(Object obj) { 231 if (this == obj) 232 return true; 233 if (obj == null) 234 return false; 235 if (getClass() != obj.getClass()) 236 return false; 237 AreaDefinitionImpl other = (AreaDefinitionImpl) obj; 238 if (areaList == null) { 239 if (other.areaList != null) 240 return false; 241 } else if (!areaList.equals(other.areaList)) 242 return false; 243 return true; 244 } 245 246}