jdk/src/share/classes/com/sun/jmx/snmp/SnmpString.java
author sherman
Tue, 30 Aug 2011 11:53:11 -0700
changeset 10419 12c063b39232
parent 5506 202f599c92aa
child 14342 8435a30053c1
permissions -rw-r--r--
7084245: Update usages of InternalError to use exception chaining Summary: to use new InternalError constructor with cause chainning Reviewed-by: alanb, ksrini, xuelei, neugens Contributed-by: sebastian.sickelmann@gmx.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package com.sun.jmx.snmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.UnknownHostException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Represents an SNMP string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p><b>This API is a Sun Microsystems internal API  and is subject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * to change without notice.</b></p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class SnmpString extends SnmpValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private static final long serialVersionUID = -7011986973225194188L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    // CONSTRUCTORS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    //-------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * Constructs a new empty <CODE>SnmpString</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public SnmpString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        value = new byte[0] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * Constructs a new <CODE>SnmpString</CODE> from the specified bytes array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @param v The bytes composing the string value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public SnmpString(byte[] v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        value = v.clone() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Constructs a new <CODE>SnmpString</CODE> from the specified <CODE>Bytes</CODE> array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @param v The <CODE>Bytes</CODE> composing the string value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public SnmpString(Byte[] v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        value = new byte[v.length] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        for (int i = 0 ; i < v.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            value[i] = v[i].byteValue() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Constructs a new <CODE>SnmpString</CODE> from the specified <CODE>String</CODE> value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @param v The initialization value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public SnmpString(String v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        value = v.getBytes() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Constructs a new <CODE>SnmpString</CODE> from the specified <CODE> InetAddress </Code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param address The <CODE>InetAddress </CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public SnmpString(InetAddress address) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        value = address.getAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    // PUBLIC METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    //---------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Converts the string value to its <CODE> InetAddress </CODE> form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @return an {@link InetAddress} defined by the string value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @exception UnknownHostException If string value is not a legal address format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public InetAddress inetAddressValue() throws UnknownHostException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return InetAddress.getByAddress(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Converts the specified binary string into a character string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param bin The binary string value to convert.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @return The character string representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public static String BinToChar(String bin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        char value[] = new char[bin.length()/8];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        int binLength = value.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        for (int i = 0; i < binLength; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            value[i] = (char)Integer.parseInt(bin.substring(8*i, 8*i+8), 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return new String(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Converts the specified hexadecimal string into a character string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param hex The hexadecimal string value to convert.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @return The character string representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public static String HexToChar(String hex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        char value[] = new char[hex.length()/2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        int hexLength = value.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        for (int i = 0; i < hexLength; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            value[i] = (char)Integer.parseInt(hex.substring(2*i, 2*i+2), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return new String(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Returns the bytes array of this <CODE>SnmpString</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @return The value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public byte[] byteValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        return value ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Converts the string value to its array of <CODE>Bytes</CODE> form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @return The array of <CODE>Bytes</CODE> representation of the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public Byte[] toByte() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        Byte[] result = new Byte[value.length] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        for (int i = 0 ; i < value.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            result[i] = new Byte(value[i]) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return result ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Converts the string value to its <CODE>String</CODE> form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @return The <CODE>String</CODE> representation of the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return new String(value) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Converts the string value to its <CODE>SnmpOid</CODE> form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @return The OID representation of the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public SnmpOid toOid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        long[] ids = new long[value.length] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        for (int i = 0 ; i < value.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            ids[i] = (long)(value[i] & 0xFF) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return new SnmpOid(ids) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Extracts the string from an index OID and returns its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * value converted as an <CODE>SnmpOid</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param index The index array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param start The position in the index array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @return The OID representing the string value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @exception SnmpStatusException There is no string value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * available at the start position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public static SnmpOid toOid(long[] index, int start) throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            if (index[start] > Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            int strLen = (int)index[start++] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            long[] ids = new long[strLen] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            for (int i = 0 ; i < strLen ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                ids[i] = index[start + i] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            return new SnmpOid(ids) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        catch(IndexOutOfBoundsException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Scans an index OID, skips the string value and returns the position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * of the next value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param index The index array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param start The position in the index array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return The position of the next value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @exception SnmpStatusException There is no string value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * available at the start position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public static int nextOid(long[] index, int start) throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            if (index[start] > Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            int strLen = (int)index[start++] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            start += strLen ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            if (start <= index.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                return start ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        catch(IndexOutOfBoundsException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Appends an <CODE>SnmpOid</CODE> representing an <CODE>SnmpString</CODE> to another OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param source An OID representing an <CODE>SnmpString</CODE> value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param dest Where source should be appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public static void appendToOid(SnmpOid source, SnmpOid dest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        dest.append(source.getLength()) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        dest.append(source) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Performs a clone action. This provides a workaround for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * <CODE>SnmpValue</CODE> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @return The SnmpValue clone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    final synchronized public SnmpValue duplicate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return (SnmpValue) clone() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Clones the <CODE>SnmpString</CODE> object, making a copy of its data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @return The object clone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    synchronized public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        SnmpString newclone = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            newclone = (SnmpString) super.clone() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            newclone.value = new byte[value.length] ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            System.arraycopy(value, 0, newclone.value, 0, value.length) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        } catch (CloneNotSupportedException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   253
            throw new InternalError(e) ; // vm bug.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return newclone ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Returns a textual description of the type object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @return ASN.1 textual description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public String getTypeName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return name ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    // VARIABLES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    //----------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Name of the type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    final static String name = "String" ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * This is the bytes array of the string value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    protected byte[] value = null ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
}