KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > snmp > SnmpNull


1 /*
2  * @(#)file SnmpNull.java
3  * @(#)author Sun Microsystems, Inc.
4  * @(#)version 4.9
5  * @(#)date 08/02/09
6  *
7  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
8  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
9  *
10  */

11
12
13 package com.sun.jmx.snmp;
14
15
16
17 /**
18  * Represents an SNMP null value.
19  * <p><b>This API is a Sun Microsystems internal API and is subject
20  * to change without notice.</b></p>
21  */

22
23 public class SnmpNull extends SnmpValue {
24
25     // CONSTRUCTORS
26
//-------------
27
/**
28      * Constructs a new <CODE>SnmpNull</CODE>.
29      */

30     public SnmpNull() {
31         tag = NullTag ;
32     }
33   
34     /**
35      * Constructs a new <CODE>SnmpNull</CODE>.
36      * <BR>For mibgen private use only.
37      */

38     public SnmpNull(String JavaDoc dummy) {
39         this();
40     }
41    
42     /**
43      * Constructs a new <CODE>SnmpNull</CODE> from the specified tag value.
44      * @param t The initialization value.
45      */

46     public SnmpNull(int t) {
47         tag = t ;
48     }
49   
50     // PUBLIC METHODS
51
//---------------
52
/**
53      * Returns the tag value of this <CODE>SnmpNull</CODE>.
54      * @return The value.
55      */

56     public int getTag() {
57         return tag ;
58     }
59   
60     /**
61      * Converts the <CODE>NULL</CODE> value to its ASN.1 <CODE>String</CODE> form.
62      * When the tag is not the universal one, it is preprended
63      * to the <CODE>String</CODE> form.
64      * @return The <CODE>String</CODE> representation of the value.
65      */

66     public String JavaDoc toString() {
67         String JavaDoc result = "" ;
68         if (tag != 5) {
69             result += "[" + tag + "] " ;
70         }
71         result += "NULL" ;
72         switch(tag) {
73         case errNoSuchObjectTag :
74             result += " (noSuchObject)" ;
75             break ;
76         
77         case errNoSuchInstanceTag :
78             result += " (noSuchInstance)" ;
79             break ;
80         
81         case errEndOfMibViewTag :
82             result += " (endOfMibView)" ;
83             break ;
84         }
85         return result ;
86     }
87
88     /**
89      * Converts the <CODE>NULL</CODE> value to its <CODE>SnmpOid</CODE> form.
90      * Normally, a <CODE>NULL</CODE> value cannot be used as an index value,
91      * this method triggers an exception.
92      * @return The OID representation of the value.
93      */

94     public SnmpOid toOid() {
95         throw new IllegalArgumentException JavaDoc() ;
96     }
97   
98     /**
99      * Performs a clone action. This provides a workaround for the
100      * <CODE>SnmpValue</CODE> interface.
101      * @return The SnmpValue clone.
102      */

103     final synchronized public SnmpValue duplicate() {
104         return (SnmpValue) clone() ;
105     }
106
107     /**
108      * Clones the <CODE>SnmpNull</CODE> object, making a copy of its data.
109      * @return The object clone.
110      */

111     final synchronized public Object JavaDoc clone() {
112         SnmpNull newclone = null ;
113         try {
114             newclone = (SnmpNull) super.clone() ;
115             newclone.tag = tag ;
116         } catch (CloneNotSupportedException JavaDoc e) {
117             throw new InternalError JavaDoc() ; // vm bug.
118
}
119         return newclone ;
120     }
121
122     /**
123      * Returns a textual description of the type object.
124      * @return ASN.1 textual description.
125      */

126     final public String JavaDoc getTypeName() {
127         return name ;
128     }
129
130     /**
131      * Checks if this <CODE>SnmpNull</CODE> object corresponds to a <CODE>noSuchObject</CODE> value.
132      * @return <CODE>true</CODE> if the tag equals {@link com.sun.jmx.snmp.SnmpDataTypeEnums#errNoSuchObjectTag},
133      * <CODE>false</CODE> otherwise.
134      */

135     public boolean isNoSuchObjectValue() {
136         return (tag == SnmpDataTypeEnums.errNoSuchObjectTag);
137     }
138
139     /**
140      * Checks if this <CODE>SnmpNull</CODE> object corresponds to a <CODE>noSuchInstance</CODE> value.
141      * @return <CODE>true</CODE> if the tag equals {@link com.sun.jmx.snmp.SnmpDataTypeEnums#errNoSuchInstanceTag},
142      * <CODE>false</CODE> otherwise.
143      */

144     public boolean isNoSuchInstanceValue() {
145         return (tag == SnmpDataTypeEnums.errNoSuchInstanceTag);
146     }
147
148     /**
149      * Checks if this <CODE>SnmpNull</CODE> object corresponds to an <CODE>endOfMibView</CODE> value.
150      * @return <CODE>true</CODE> if the tag equals {@link com.sun.jmx.snmp.SnmpDataTypeEnums#errEndOfMibViewTag},
151      * <CODE>false</CODE> otherwise.
152      */

153     public boolean isEndOfMibViewValue() {
154         return (tag == SnmpDataTypeEnums.errEndOfMibViewTag);
155     }
156     
157     // VARIABLES
158
//----------
159
/**
160      * Name of the type.
161      */

162     final static String JavaDoc name = "Null" ;
163
164     /**
165      * This is the tag of the NULL value. By default, it is the universal tag value.
166      */

167     private int tag = 5 ;
168 }
169
Popular Tags