blob: 9605bebddff63cd70359a64dd8cd173b01de0ddd [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package com.sun.jmx.snmp;
27
28import java.io.Serializable;
29import java.util.Hashtable;
30
31import com.sun.jmx.snmp.SnmpValue;
32import com.sun.jmx.snmp.SnmpInt;
33
34import com.sun.jmx.snmp.Enumerated;
35
36/**
37 * This class is an internal class which is used to represent RowStatus
38 * codes as defined in RFC 2579.
39 *
40 * It defines an additional code, <i>unspecified</i>, which is
41 * implementation specific, and is used to identify
42 * unspecified actions (when for instance the RowStatus variable
43 * is not present in the varbind list) or uninitialized values.
44 *
45 * mibgen does not generate objects of this class but any variable
46 * using the RowStatus textual convention can be converted into an
47 * object of this class thanks to the
48 * <code>EnumRowStatus(Enumerated valueIndex)</code> constructor.
49 *
50 * <p><b>This API is a Sun Microsystems internal API and is subject
51 * to change without notice.</b></p>
52 **/
53
54public class EnumRowStatus extends Enumerated implements Serializable {
55 private static final long serialVersionUID = 8966519271130162420L;
56
57 /**
58 * This value is SNMP Runtime implementation specific, and is used to identify
59 * unspecified actions (when for instance the RowStatus variable
60 * is not present in the varbind list) or uninitialized values.
61 */
62 public final static int unspecified = 0;
63
64 /**
65 * This value corresponds to the <i>active</i> RowStatus, as defined in
66 * RFC 2579 from SMIv2:
67 * <ul>
68 * <i>active</i> indicates that the conceptual row is available for
69 * use by the managed device;
70 * </ul>
71 */
72 public final static int active = 1;
73
74 /**
75 * This value corresponds to the <i>notInService</i> RowStatus, as
76 * defined in RFC 2579 from SMIv2:
77 * <ul>
78 * <i>notInService</i> indicates that the conceptual
79 * row exists in the agent, but is unavailable for use by
80 * the managed device; <i>notInService</i> has
81 * no implication regarding the internal consistency of
82 * the row, availability of resources, or consistency with
83 * the current state of the managed device;
84 * </ul>
85 **/
86 public final static int notInService = 2;
87
88 /**
89 * This value corresponds to the <i>notReady</i> RowStatus, as defined
90 * in RFC 2579 from SMIv2:
91 * <ul>
92 * <i>notReady</i> indicates that the conceptual row
93 * exists in the agent, but is missing information
94 * necessary in order to be available for use by the
95 * managed device (i.e., one or more required columns in
96 * the conceptual row have not been instantiated);
97 * </ul>
98 */
99 public final static int notReady = 3;
100
101 /**
102 * This value corresponds to the <i>createAndGo</i> RowStatus,
103 * as defined in RFC 2579 from SMIv2:
104 * <ul>
105 * <i>createAndGo</i> is supplied by a management
106 * station wishing to create a new instance of a
107 * conceptual row and to have its status automatically set
108 * to active, making it available for use by the managed
109 * device;
110 * </ul>
111 */
112 public final static int createAndGo = 4;
113
114 /**
115 * This value corresponds to the <i>createAndWait</i> RowStatus,
116 * as defined in RFC 2579 from SMIv2:
117 * <ul>
118 * <i>createAndWait</i> is supplied by a management
119 * station wishing to create a new instance of a
120 * conceptual row (but not make it available for use by
121 * the managed device);
122 * </ul>
123 */
124 public final static int createAndWait = 5;
125
126 /**
127 * This value corresponds to the <i>destroy</i> RowStatus, as defined in
128 * RFC 2579 from SMIv2:
129 * <ul>
130 * <i>destroy</i> is supplied by a management station
131 * wishing to delete all of the instances associated with
132 * an existing conceptual row.
133 * </ul>
134 */
135 public final static int destroy = 6;
136
137 /**
138 * Build an <code>EnumRowStatus</code> from an <code>int</code>.
139 * @param valueIndex should be either 0 (<i>unspecified</i>), or one of
140 * the values defined in RFC 2579.
141 * @exception IllegalArgumentException if the given
142 * <code>valueIndex</code> is not valid.
143 **/
144 public EnumRowStatus(int valueIndex)
145 throws IllegalArgumentException {
146 super(valueIndex);
147 }
148
149 /**
150 * Build an <code>EnumRowStatus</code> from an <code>Enumerated</code>.
151 * @param valueIndex should be either 0 (<i>unspecified</i>), or one of
152 * the values defined in RFC 2579.
153 * @exception IllegalArgumentException if the given
154 * <code>valueIndex</code> is not valid.
155 **/
156 public EnumRowStatus(Enumerated valueIndex)
157 throws IllegalArgumentException {
158 this(valueIndex.intValue());
159 }
160
161 /**
162 * Build an <code>EnumRowStatus</code> from a <code>long</code>.
163 * @param valueIndex should be either 0 (<i>unspecified</i>), or one of
164 * the values defined in RFC 2579.
165 * @exception IllegalArgumentException if the given
166 * <code>valueIndex</code> is not valid.
167 **/
168 public EnumRowStatus(long valueIndex)
169 throws IllegalArgumentException {
170 this((int)valueIndex);
171 }
172
173 /**
174 * Build an <code>EnumRowStatus</code> from an <code>Integer</code>.
175 * @param valueIndex should be either 0 (<i>unspecified</i>), or one of
176 * the values defined in RFC 2579.
177 * @exception IllegalArgumentException if the given
178 * <code>valueIndex</code> is not valid.
179 **/
180 public EnumRowStatus(Integer valueIndex)
181 throws IllegalArgumentException {
182 super(valueIndex);
183 }
184
185 /**
186 * Build an <code>EnumRowStatus</code> from a <code>Long</code>.
187 * @param valueIndex should be either 0 (<i>unspecified</i>), or one of
188 * the values defined in RFC 2579.
189 * @exception IllegalArgumentException if the given
190 * <code>valueIndex</code> is not valid.
191 **/
192 public EnumRowStatus(Long valueIndex)
193 throws IllegalArgumentException {
194 this(valueIndex.longValue());
195 }
196
197 /**
198 * Build an <code>EnumRowStatus</code> with <i>unspecified</i> value.
199 **/
200 public EnumRowStatus()
201 throws IllegalArgumentException {
202 this(unspecified);
203 }
204
205 /**
206 * Build an <code>EnumRowStatus</code> from a <code>String</code>.
207 * @param x should be either "unspecified", or one of
208 * the values defined in RFC 2579 ("active", "notReady", etc...)
209 * @exception IllegalArgumentException if the given String
210 * <code>x</code> is not valid.
211 **/
212 public EnumRowStatus(String x)
213 throws IllegalArgumentException {
214 super(x);
215 }
216
217 /**
218 * Build an <code>EnumRowStatus</code> from an <code>SnmpInt</code>.
219 * @param valueIndex should be either 0 (<i>unspecified</i>), or one of
220 * the values defined in RFC 2579.
221 * @exception IllegalArgumentException if the given
222 * <code>valueIndex</code> is not valid.
223 **/
224 public EnumRowStatus(SnmpInt valueIndex)
225 throws IllegalArgumentException {
226 this(valueIndex.intValue());
227 }
228
229 /**
230 * Build an SnmpValue from this object.
231 *
232 * @exception IllegalArgumentException if this object holds an
233 * <i>unspecified</i> value.
234 * @return an SnmpInt containing this object value.
235 **/
236 public SnmpInt toSnmpValue()
237 throws IllegalArgumentException {
238 if (value == unspecified)
239 throw new
240 IllegalArgumentException("`unspecified' is not a valid SNMP value.");
241 return new SnmpInt(value);
242 }
243
244 /**
245 * Check that the given <code>value</code> is valid.
246 *
247 * Valid values are:
248 * <ul><li><i>unspecified(0)</i></li>
249 * <li><i>active(1)</i></li>
250 * <li><i>notInService(2)</i></li>
251 * <li><i>notReady(3)</i></li>
252 * <li><i>createAndGo(4)</i></li>
253 * <li><i>createAndWait(5)</i></li>
254 * <li><i>destroy(6)</i></li>
255 * </ul>
256 *
257 **/
258 static public boolean isValidValue(int value) {
259 if (value < 0) return false;
260 if (value > 6) return false;
261 return true;
262 }
263
264 // Documented in Enumerated
265 //
266 protected Hashtable getIntTable() {
267 return EnumRowStatus.getRSIntTable();
268 }
269
270 // Documented in Enumerated
271 //
272 protected Hashtable getStringTable() {
273 return EnumRowStatus.getRSStringTable();
274 }
275
276 static final Hashtable getRSIntTable() {
277 return intTable ;
278 }
279
280 static final Hashtable getRSStringTable() {
281 return stringTable ;
282 }
283
284 // Initialize the mapping tables.
285 //
286 final static Hashtable<Integer, String> intTable =
287 new Hashtable<Integer, String>();
288 final static Hashtable<String, Integer> stringTable =
289 new Hashtable<String, Integer>();
290 static {
291 intTable.put(new Integer(0), "unspecified");
292 intTable.put(new Integer(3), "notReady");
293 intTable.put(new Integer(6), "destroy");
294 intTable.put(new Integer(2), "notInService");
295 intTable.put(new Integer(5), "createAndWait");
296 intTable.put(new Integer(1), "active");
297 intTable.put(new Integer(4), "createAndGo");
298 stringTable.put("unspecified", new Integer(0));
299 stringTable.put("notReady", new Integer(3));
300 stringTable.put("destroy", new Integer(6));
301 stringTable.put("notInService", new Integer(2));
302 stringTable.put("createAndWait", new Integer(5));
303 stringTable.put("active", new Integer(1));
304 stringTable.put("createAndGo", new Integer(4));
305 }
306
307
308}