KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > snmp > agent > SnmpStandardObjectServer


1 /*
2  * @(#)file SnmpStandardObjectServer.java
3  * @(#)author Sun Microsystems, Inc.
4  * @(#)version 1.10
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 package com.sun.jmx.snmp.agent;
11
12 // java imports
13
//
14
import java.io.Serializable JavaDoc;
15 import java.util.Hashtable JavaDoc;
16 import java.util.Enumeration JavaDoc;
17 import java.util.Vector JavaDoc;
18
19 // jmx imports
20
//
21
import com.sun.jmx.snmp.SnmpOid;
22 import com.sun.jmx.snmp.SnmpValue;
23 import com.sun.jmx.snmp.SnmpVarBind;
24 import com.sun.jmx.snmp.SnmpStatusException;
25
26 // SNMP Runtime imports
27
//
28

29 /**
30  * <p>
31  * This class is a utility class that transform SNMP GET / SET requests
32  * into series of get<i>AttributeName</i>() set<i>AttributeName</i>()
33  * invoked on the MBean.
34  * </p>
35  *
36  * <p>
37  * The transformation relies on the metadata information provided by the
38  * {@link com.sun.jmx.snmp.agent.SnmpStandardMetaServer} object which is
39  * passed as first parameter to every method. This SnmpStandardMetaServer
40  * object is usually a Metadata object generated by <code>mibgen</code>.
41  * </p>
42  *
43  * <p>
44  * The MBean is not invoked directly by this class but through the
45  * metadata object which holds a reference on it.
46  * </p>
47  *
48  * <p><b><i>
49  * This class is used internally by mibgen generated metadata objects and
50  * you should never need to use it directly.
51  * </b></i></p>
52  * <p><b>This API is a Sun Microsystems internal API and is subject
53  * to change without notice.</b></p>
54  **/

55
56 public class SnmpStandardObjectServer implements Serializable JavaDoc {
57
58     /**
59      * Generic handling of the <CODE>get</CODE> operation.
60      * <p> The default implementation of this method is to loop over the
61      * varbind list associated with the sub-request and to call
62      * <CODE>get(var.oid.getOidArc(depth), data);</CODE>
63      * <pre>
64      * public void get(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
65      * int depth)
66      * throws SnmpStatusException {
67      *
68      * final Object data = req.getUserData();
69      *
70      * for (Enumeration e= req.getElements(); e.hasMoreElements();) {
71      *
72      * final SnmpVarBind var= (SnmpVarBind) e.nextElement();
73      *
74      * try {
75      * // This method will generate a SnmpStatusException
76      * // if `depth' is out of bounds.
77      * //
78      * final long id = var.oid.getOidArc(depth);
79      * var.value = meta.get(id, data);
80      * } catch(SnmpStatusException x) {
81      * req.registerGetException(var,x);
82      * }
83      * }
84      * }
85      * </pre>
86      * <p> You can override this method if you need to implement some
87      * specific policies for minimizing the accesses made to some remote
88      * underlying resources.
89      * <p>
90      *
91      * @param meta A pointer to the generated meta-data object which
92      * implements the <code>SnmpStandardMetaServer</code>
93      * interface.
94      *
95      * @param req The sub-request that must be handled by this node.
96      *
97      * @param depth The depth reached in the OID tree.
98      *
99      * @exception SnmpStatusException An error occurred while accessing
100      * the MIB node.
101      */

102     public void get(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
103             int depth)
104     throws SnmpStatusException {
105
106     final Object JavaDoc data = req.getUserData();
107
108         for (Enumeration JavaDoc e= req.getElements(); e.hasMoreElements();) {
109             final SnmpVarBind var= (SnmpVarBind) e.nextElement();
110         try {
111         final long id = var.oid.getOidArc(depth);
112         var.value = meta.get(id, data);
113             } catch(SnmpStatusException x) {
114         req.registerGetException(var,x);
115         }
116     }
117     }
118
119     /**
120      * Generic handling of the <CODE>set</CODE> operation.
121      * <p> The default implementation of this method is to loop over the
122      * varbind list associated with the sub-request and to call
123      * <CODE>set(var.value, var.oid.getOidArc(depth), data);</CODE>
124      * <pre>
125      * public void set(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
126      * int depth)
127      * throws SnmpStatusException {
128      *
129      * final Object data = req.getUserData();
130      *
131      * for (Enumeration e= req.getElements(); e.hasMoreElements();) {
132      *
133      * final SnmpVarBind var= (SnmpVarBind) e.nextElement();
134      *
135      * try {
136      * // This method will generate a SnmpStatusException
137      * // if `depth' is out of bounds.
138      * //
139      * final long id = var.oid.getOidArc(depth);
140      * var.value = meta.set(var.value, id, data);
141      * } catch(SnmpStatusException x) {
142      * req.registerSetException(var,x);
143      * }
144      * }
145      * }
146      * </pre>
147      * <p> You can override this method if you need to implement some
148      * specific policies for minimizing the accesses made to some remote
149      * underlying resources.
150      * <p>
151      *
152      * @param meta A pointer to the generated meta-data object which
153      * implements the <code>SnmpStandardMetaServer</code>
154      * interface.
155      *
156      * @param req The sub-request that must be handled by this node.
157      *
158      * @param depth The depth reached in the OID tree.
159      *
160      * @exception SnmpStatusException An error occurred while accessing
161      * the MIB node.
162      */

163     public void set(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
164             int depth)
165     throws SnmpStatusException {
166     
167     final Object JavaDoc data = req.getUserData();
168  
169     for (Enumeration JavaDoc e= req.getElements(); e.hasMoreElements();) {
170         SnmpVarBind var = null;
171         var = (SnmpVarBind) e.nextElement();
172         try {
173         // This method will generate a SnmpStatusException
174
// if `depth' is out of bounds.
175
//
176
final long id = var.oid.getOidArc(depth);
177         var.value = meta.set(var.value, id, data);
178         } catch(SnmpStatusException x) {
179         req.registerSetException(var,x);
180         }
181     }
182     }
183
184     /**
185      * Generic handling of the <CODE>check</CODE> operation.
186      * <p> The default implementation of this method is to loop over the
187      * varbind list associated with the sub-request and to call
188      * <CODE>check(var.value, var.oid.getOidArc(depth), data);</CODE>
189      * <pre>
190      * public void check(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
191      * int depth)
192      * throws SnmpStatusException {
193      *
194      * final Object data = req.getUserData();
195      *
196      * for (Enumeration e= req.getElements(); e.hasMoreElements();) {
197      *
198      * final SnmpVarBind var= (SnmpVarBind) e.nextElement();
199      *
200      * try {
201      * // This method will generate a SnmpStatusException
202      * // if `depth' is out of bounds.
203      * //
204      * final long id = var.oid.getOidArc(depth);
205      * meta.check(var.value, id, data);
206      * } catch(SnmpStatusException x) {
207      * req.registerCheckException(var,x);
208      * }
209      * }
210      * }
211      * </pre>
212      * <p> You can override this method if you need to implement some
213      * specific policies for minimizing the accesses made to some remote
214      * underlying resources, or if you need to implement some consistency
215      * checks between the different values provided in the varbind list.
216      * <p>
217      *
218      * @param meta A pointer to the generated meta-data object which
219      * implements the <code>SnmpStandardMetaServer</code>
220      * interface.
221      *
222      * @param req The sub-request that must be handled by this node.
223      *
224      * @param depth The depth reached in the OID tree.
225      *
226      * @exception SnmpStatusException An error occurred while accessing
227      * the MIB node.
228      */

229     public void check(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
230               int depth)
231     throws SnmpStatusException {
232     
233     final Object JavaDoc data = req.getUserData();
234     
235     for (Enumeration JavaDoc e= req.getElements(); e.hasMoreElements();) {
236         final SnmpVarBind var = (SnmpVarBind) e.nextElement();
237         try {
238         // This method will generate a SnmpStatusException
239
// if `depth' is out of bounds.
240
//
241
final long id = var.oid.getOidArc(depth);
242         meta.check(var.value,id,data);
243         } catch(SnmpStatusException x) {
244         req.registerCheckException(var,x);
245         }
246     }
247     }
248 }
249
Popular Tags