PageRenderTime 18ms CodeModel.GetById 1ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/lsm/AreaEventInfoImpl.java

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