PageRenderTime 40ms CodeModel.GetById 27ms app.highlight 10ms RepoModel.GetById 0ms app.codeStats 1ms

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

http://mobicents.googlecode.com/
Java | 294 lines | 163 code | 30 blank | 101 comment | 28 complexity | 003ea4560fdbdafcf13fe7764809cbca 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.LCSPrivacyCheck;
 35import org.mobicents.protocols.ss7.map.api.service.lsm.PrivacyCheckRelatedAction;
 36import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
 37
 38/**
 39 * @author amit bhayani
 40 * 
 41 */
 42public class LCSPrivacyCheckImpl implements LCSPrivacyCheck, MAPAsnPrimitive {
 43
 44	private static final int _TAG_CALL_SESSION_UNRELATED = 0;
 45	private static final int _TAG_CALL_SESSION_RELATED = 1;
 46
 47	private PrivacyCheckRelatedAction callSessionUnrelated = null;
 48	private PrivacyCheckRelatedAction callSessionRelated = null;
 49
 50	/**
 51	 * 
 52	 */
 53	public LCSPrivacyCheckImpl() {
 54		super();
 55	}
 56
 57	/**
 58	 * @param callSessionUnrelated
 59	 * @param callSessionRelated
 60	 */
 61	public LCSPrivacyCheckImpl(PrivacyCheckRelatedAction callSessionUnrelated, PrivacyCheckRelatedAction callSessionRelated) {
 62		super();
 63		this.callSessionUnrelated = callSessionUnrelated;
 64		this.callSessionRelated = callSessionRelated;
 65	}
 66
 67	/*
 68	 * (non-Javadoc)
 69	 * 
 70	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.LCSPrivacyCheck#
 71	 * getCallSessionUnrelated()
 72	 */
 73	@Override
 74	public PrivacyCheckRelatedAction getCallSessionUnrelated() {
 75		return this.callSessionUnrelated;
 76	}
 77
 78	/*
 79	 * (non-Javadoc)
 80	 * 
 81	 * @see org.mobicents.protocols.ss7.map.api.service.lsm.LCSPrivacyCheck#
 82	 * getCallSessionRelated()
 83	 */
 84	@Override
 85	public PrivacyCheckRelatedAction getCallSessionRelated() {
 86		return this.callSessionRelated;
 87	}
 88
 89	/*
 90	 * (non-Javadoc)
 91	 * 
 92	 * @see
 93	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTag()
 94	 */
 95	@Override
 96	public int getTag() throws MAPException {
 97		return Tag.SEQUENCE;
 98	}
 99
100	/*
101	 * (non-Javadoc)
102	 * 
103	 * @see
104	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTagClass
105	 * ()
106	 */
107	@Override
108	public int getTagClass() {
109		return Tag.CLASS_UNIVERSAL;
110	}
111
112	/*
113	 * (non-Javadoc)
114	 * 
115	 * @see
116	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getIsPrimitive
117	 * ()
118	 */
119	@Override
120	public boolean getIsPrimitive() {
121		return false;
122	}
123
124	/*
125	 * (non-Javadoc)
126	 * 
127	 * @see
128	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeAll
129	 * (org.mobicents.protocols.asn.AsnInputStream)
130	 */
131	@Override
132	public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
133		try {
134			int length = ansIS.readLength();
135			this._decode(ansIS, length);
136		} catch (IOException e) {
137			throw new MAPParsingComponentException("IOException when decoding SM_RP_DA: " + e.getMessage(), e,
138					MAPParsingComponentExceptionReason.MistypedParameter);
139		} catch (AsnException e) {
140			throw new MAPParsingComponentException("AsnException when decoding SM_RP_DA: " + e.getMessage(), e,
141					MAPParsingComponentExceptionReason.MistypedParameter);
142		}
143	}
144
145	/*
146	 * (non-Javadoc)
147	 * 
148	 * @see
149	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeData
150	 * (org.mobicents.protocols.asn.AsnInputStream, int)
151	 */
152	@Override
153	public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
154		try {
155			this._decode(ansIS, length);
156		} catch (IOException e) {
157			throw new MAPParsingComponentException("IOException when decoding SM_RP_DA: " + e.getMessage(), e,
158					MAPParsingComponentExceptionReason.MistypedParameter);
159		} catch (AsnException e) {
160			throw new MAPParsingComponentException("AsnException when decoding SM_RP_DA: " + e.getMessage(), e,
161					MAPParsingComponentExceptionReason.MistypedParameter);
162		}
163	}
164
165	private void _decode(AsnInputStream asnIS, int length) throws MAPParsingComponentException, IOException, AsnException {
166
167		AsnInputStream ais = asnIS.readSequenceStreamData(length);
168
169		int tag = ais.readTag();
170
171		// Decode callSessionUnrelated [0] PrivacyCheckRelatedAction
172		if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive() || tag != _TAG_CALL_SESSION_UNRELATED) {
173			throw new MAPParsingComponentException(
174					"Error while decoding LCSPrivacyCheck: Parameter 0 [callSessionUnrelated [0] PrivacyCheckRelatedAction] bad tag class, tag or not primitive",
175					MAPParsingComponentExceptionReason.MistypedParameter);
176		}
177
178		int length1 = ais.readLength();
179		int action = (int) ais.readIntegerData(length1);
180		this.callSessionUnrelated = PrivacyCheckRelatedAction.getPrivacyCheckRelatedAction(action);
181
182		while (true) {
183			if (ais.available() == 0)
184				break;
185
186			tag = ais.readTag();
187			switch (tag) {
188			case _TAG_CALL_SESSION_RELATED:
189				if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
190					throw new MAPParsingComponentException(
191							"Error while decoding LCSPrivacyCheck: Parameter 1 [callSessionRelated [1] PrivacyCheckRelatedAction] bad tag class, tag or not primitive",
192							MAPParsingComponentExceptionReason.MistypedParameter);
193				}
194				length1 = ais.readLength();
195				action = (int) ais.readIntegerData(length1);
196				this.callSessionRelated = PrivacyCheckRelatedAction.getPrivacyCheckRelatedAction(action);
197				break;
198			default:
199				// Do we care?
200				ais.advanceElement();
201				break;
202			}
203		}
204	}
205
206	/*
207	 * (non-Javadoc)
208	 * 
209	 * @see
210	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
211	 * (org.mobicents.protocols.asn.AsnOutputStream)
212	 */
213	@Override
214	public void encodeAll(AsnOutputStream asnOs) throws MAPException {
215		this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
216	}
217
218	/*
219	 * (non-Javadoc)
220	 * 
221	 * @see
222	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
223	 * (org.mobicents.protocols.asn.AsnOutputStream, int, int)
224	 */
225	@Override
226	public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
227		try {
228			asnOs.writeTag(tagClass, false, tag);
229			int pos = asnOs.StartContentDefiniteLength();
230			this.encodeData(asnOs);
231			asnOs.FinalizeContent(pos);
232		} catch (AsnException e) {
233			throw new MAPException("AsnException when encoding InformServiceCentreRequest: " + e.getMessage(), e);
234		}
235	}
236
237	/*
238	 * (non-Javadoc)
239	 * 
240	 * @see
241	 * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeData
242	 * (org.mobicents.protocols.asn.AsnOutputStream)
243	 */
244	@Override
245	public void encodeData(AsnOutputStream asnOs) throws MAPException {
246		if (this.callSessionUnrelated == null) {
247			throw new MAPException("Error while encoding LCSPrivacyCheck the mandatory parameter callSessionUnrelated is not defined");
248		}
249
250		try {
251			asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_CALL_SESSION_UNRELATED, this.callSessionUnrelated.getAction());
252		} catch (IOException e) {
253			throw new MAPException("IOException when encoding parameter callSessionUnrelated", e);
254		} catch (AsnException e) {
255			throw new MAPException("AsnException when encoding parameter callSessionUnrelated", e);
256		}
257
258		if (this.callSessionRelated != null) {
259			try {
260				asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_CALL_SESSION_RELATED, this.callSessionRelated.getAction());
261			} catch (IOException e) {
262				throw new MAPException("IOException when encoding parameter callSessionRelated", e);
263			} catch (AsnException e) {
264				throw new MAPException("AsnException when encoding parameter callSessionRelated", e);
265			}
266		}
267	}
268
269	@Override
270	public int hashCode() {
271		final int prime = 31;
272		int result = 1;
273		result = prime * result + ((callSessionRelated == null) ? 0 : callSessionRelated.hashCode());
274		result = prime * result + ((callSessionUnrelated == null) ? 0 : callSessionUnrelated.hashCode());
275		return result;
276	}
277
278	@Override
279	public boolean equals(Object obj) {
280		if (this == obj)
281			return true;
282		if (obj == null)
283			return false;
284		if (getClass() != obj.getClass())
285			return false;
286		LCSPrivacyCheckImpl other = (LCSPrivacyCheckImpl) obj;
287		if (callSessionRelated != other.callSessionRelated)
288			return false;
289		if (callSessionUnrelated != other.callSessionUnrelated)
290			return false;
291		return true;
292	}
293
294}