PageRenderTime 24ms CodeModel.GetById 10ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

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