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

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

http://mobicents.googlecode.com/
Java | 103 lines | 58 code | 17 blank | 28 comment | 0 complexity | 1b7ba26d09f061e9587d9eabe67df961 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 javolution.xml.XMLFormat;
 26import javolution.xml.XMLSerializable;
 27import javolution.xml.stream.XMLStreamException;
 28
 29import org.mobicents.protocols.ss7.m3ua.parameter.NetworkAppearance;
 30import org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
 31
 32/**
 33 * @author amit bhayani
 34 * @author kulikov
 35 */
 36public class NetworkAppearanceImpl extends ParameterImpl implements NetworkAppearance, XMLSerializable {
 37
 38	private static final String VALUE = "value";
 39
 40	private static final long UNSIGNED_INT_MAX_VALUE = 0xFFFFFFFF;
 41	private long value;
 42	
 43	public NetworkAppearanceImpl(){
 44		this.tag = Parameter.Network_Appearance;
 45	}
 46
 47	protected NetworkAppearanceImpl(long value) {
 48		this.value = value;
 49		this.tag = Parameter.Network_Appearance;
 50	}
 51
 52	protected NetworkAppearanceImpl(byte[] data) {
 53		this.value = 0;
 54		this.value |= data[0] & 0xFF;
 55		this.value <<= 8;
 56		this.value |= data[1] & 0xFF;
 57		this.value <<= 8;
 58		this.value |= data[2] & 0xFF;
 59		this.value <<= 8;
 60		this.value |= data[3] & 0xFF;
 61		this.tag = Parameter.Network_Appearance;
 62	}
 63
 64	public long getNetApp() {
 65		return value;
 66	}
 67
 68	@Override
 69	protected byte[] getValue() {
 70		byte[] data = new byte[4];
 71		data[0] = (byte) (value >>> 24);
 72		data[1] = (byte) (value >>> 16);
 73		data[2] = (byte) (value >>> 8);
 74		data[3] = (byte) (value);
 75
 76		return data;
 77	}
 78
 79	@Override
 80	public String toString() {
 81		return String.format("NetworkAppearance value=%d", value);
 82	}
 83
 84	/**
 85	 * XML Serialization/Deserialization
 86	 */
 87	protected static final XMLFormat<NetworkAppearanceImpl> RC_XML = new XMLFormat<NetworkAppearanceImpl>(
 88			NetworkAppearanceImpl.class) {
 89
 90		@Override
 91		public void read(javolution.xml.XMLFormat.InputElement xml, NetworkAppearanceImpl localRkId)
 92				throws XMLStreamException {
 93			localRkId.value = xml.getAttribute(VALUE).toLong();
 94		}
 95
 96		@Override
 97		public void write(NetworkAppearanceImpl localRkId, javolution.xml.XMLFormat.OutputElement xml)
 98				throws XMLStreamException {
 99			xml.setAttribute(VALUE, localRkId.value);
100		}
101	};
102
103}