PageRenderTime 24ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

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