PageRenderTime 31ms CodeModel.GetById 25ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 104 lines | 55 code | 20 blank | 29 comment | 2 complexity | c72cdda778bb99eb8b468f4afd0cb52f 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.nio.ByteBuffer;
 26
 27import org.mobicents.protocols.ss7.m3ua.parameter.DeregistrationResult;
 28import org.mobicents.protocols.ss7.m3ua.parameter.DeregistrationStatus;
 29import org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
 30import org.mobicents.protocols.ss7.m3ua.parameter.RoutingContext;
 31
 32/**
 33 * 
 34 * @author amit bhayani
 35 *
 36 */
 37public class DeregistrationResultImpl extends ParameterImpl implements
 38        DeregistrationResult {
 39
 40    private RoutingContext rc;
 41    private DeregistrationStatus status;
 42    private byte[] value;
 43
 44    private ByteBuffer buffer = ByteBuffer.allocate(16);
 45
 46    public DeregistrationResultImpl(RoutingContext rc,
 47            DeregistrationStatus status) {
 48        this.tag = Parameter.Deregistration_Result;
 49        this.rc = rc;
 50        this.status = status;
 51
 52        this.encode();
 53    }
 54
 55    public DeregistrationResultImpl(byte[] data) {
 56        this.tag = Parameter.Deregistration_Result;
 57        int pos = 0;
 58
 59        while (pos < data.length) {
 60            short tag = (short) ((data[pos] & 0xff) << 8 | (data[pos + 1] & 0xff));
 61            short len = (short) ((data[pos + 2] & 0xff) << 8 | (data[pos + 3] & 0xff));
 62
 63            byte[] value = new byte[len - 4];
 64
 65            System.arraycopy(data, pos + 4, value, 0, value.length);
 66            pos += len;
 67            // parameters.put(tag, factory.createParameter(tag, value));
 68            switch (tag) {
 69            case ParameterImpl.Routing_Context:
 70                this.rc = new RoutingContextImpl(value);
 71                break;
 72
 73            case ParameterImpl.Deregistration_Status:
 74                this.status = new DeregistrationStatusImpl(value);
 75                break;
 76
 77            }
 78
 79            // The Parameter Length does not include any padding octets. We have
 80            // to consider padding here
 81            pos += (pos % 4);
 82        }// end of while
 83    }
 84
 85    private void encode() {
 86        ((RoutingContextImpl) this.rc).write(buffer);
 87        ((DeregistrationStatusImpl) this.status).write(buffer);
 88        value = buffer.array();
 89    }
 90
 91    @Override
 92    protected byte[] getValue() {
 93        return this.value;
 94    }
 95
 96    public DeregistrationStatus getDeregistrationStatus() {
 97        return this.status;
 98    }
 99
100    public RoutingContext getRoutingContext() {
101        return this.rc;
102    }
103
104}