PageRenderTime 38ms CodeModel.GetById 27ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 95 lines | 48 code | 18 blank | 29 comment | 0 complexity | d767561d36caf5c8e5c144c3e3053e72 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 org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
26import org.mobicents.protocols.ss7.m3ua.parameter.UserCause;
27
28/**
29 * 
30 * @author amit bhayani
31 * 
32 */
33public class UserCauseImpl extends ParameterImpl implements UserCause {
34
35    private int user = 0;
36    private int cause = 0;
37
38    private byte[] value;
39
40    protected UserCauseImpl(byte[] value) {
41        this.tag = Parameter.User_Cause;
42
43        this.user = 0;
44        this.user |= value[0] & 0xFF;
45        this.user <<= 8;
46        this.user |= value[1] & 0xFF;
47
48        this.cause = 0;
49        this.cause |= value[2] & 0xFF;
50        this.cause <<= 8;
51        this.cause |= value[3] & 0xFF;
52
53        this.value = value;
54    }
55
56    protected UserCauseImpl(int user, int cause) {
57        this.tag = Parameter.User_Cause;
58        this.user = user;
59        this.cause = cause;
60        encode();
61    }
62
63    private void encode() {
64        // create byte array taking into account data, point codes and
65        // indicators;
66        this.value = new byte[4];
67        // encode routing context
68        value[0] = (byte) (this.user >> 8);
69        value[1] = (byte) (this.user);
70
71        value[2] = (byte) (this.cause >> 8);
72        value[3] = (byte) (this.cause);
73
74    }
75
76    @Override
77    protected byte[] getValue() {
78        return value;
79    }
80
81    public int getCause() {
82        return this.cause;
83    }
84
85    public int getUser() {
86        return this.user;
87    }
88
89    @Override
90    public String toString() {
91        return String.format("UserCause cause = %d user = %d", this.cause,
92                this.user);
93    }
94
95}