PageRenderTime 26ms CodeModel.GetById 12ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/protocols/ss7/m3ua/impl/src/main/java/org/mobicents/protocols/ss7/m3ua/impl/parameter/ServiceIndicatorsImpl.java

http://mobicents.googlecode.com/
Java | 119 lines | 68 code | 19 blank | 32 comment | 4 complexity | 55ad3b3c307451338622ad409e0b6d02 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.m3ua.impl.parameter;
 24
 25import java.util.Arrays;
 26
 27import javolution.xml.XMLFormat;
 28import javolution.xml.XMLSerializable;
 29import javolution.xml.stream.XMLStreamException;
 30
 31import org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
 32import org.mobicents.protocols.ss7.m3ua.parameter.ServiceIndicators;
 33
 34/**
 35 * 
 36 * @author amit bhayani
 37 * 
 38 */
 39public class ServiceIndicatorsImpl extends ParameterImpl implements ServiceIndicators, XMLSerializable {
 40
 41	private static final String INDICATOR = "indicator";
 42	private static final String ARRAY_SIZE = "size";
 43
 44	private short[] indicators;
 45	private byte[] value = null;
 46
 47	public ServiceIndicatorsImpl() {
 48		this.tag = Parameter.Service_Indicators;
 49	}
 50
 51	protected ServiceIndicatorsImpl(short[] inds) {
 52		this.tag = Parameter.Service_Indicators;
 53		this.indicators = inds;
 54		this.encode();
 55	}
 56
 57	protected ServiceIndicatorsImpl(byte[] value) {
 58		this.tag = Parameter.Service_Indicators;
 59		this.indicators = new short[value.length];
 60		for (int i = 0; i < value.length; i++) {
 61			this.indicators[i] = value[i];
 62		}
 63		this.value = value;
 64	}
 65
 66	private void encode() {
 67		// create byte array taking into account data, point codes and
 68		// indicators;
 69		this.value = new byte[indicators.length];
 70		int count = 0;
 71		// encode routing context
 72		while (count < value.length) {
 73			value[count] = (byte) indicators[count++];
 74		}
 75	}
 76
 77	@Override
 78	protected byte[] getValue() {
 79		return this.value;
 80	}
 81
 82	public short[] getIndicators() {
 83		return this.indicators;
 84	}
 85
 86	@Override
 87	public String toString() {
 88		return String.format("ServiceIndicators ids=%s", Arrays.toString(this.indicators));
 89	}
 90
 91	/**
 92	 * XML Serialization/Deserialization
 93	 */
 94	protected static final XMLFormat<ServiceIndicatorsImpl> RC_XML = new XMLFormat<ServiceIndicatorsImpl>(
 95			ServiceIndicatorsImpl.class) {
 96
 97		@Override
 98		public void read(javolution.xml.XMLFormat.InputElement xml, ServiceIndicatorsImpl si) throws XMLStreamException {
 99			int size = xml.getAttribute(ARRAY_SIZE).toInt();
100			si.indicators = new short[size];
101			size = 0;
102			while (xml.hasNext()) {
103				si.indicators[size++] = xml.get(INDICATOR);
104			}
105			
106			si.encode();
107		}
108
109		@Override
110		public void write(ServiceIndicatorsImpl si, javolution.xml.XMLFormat.OutputElement xml)
111				throws XMLStreamException {
112			xml.setAttribute(ARRAY_SIZE, si.indicators.length);
113			for (Short s : si.indicators) {
114				xml.add(s, INDICATOR);
115			}
116		}
117	};
118
119}