KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)file SnmpMibAgent.java
3  * @(#)author Sun Microsystems, Inc.
4  * @(#)version 4.40
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.agent;
14
15
16
17 // java imports
18
//
19
import java.io.Serializable JavaDoc;
20 import java.util.Vector JavaDoc;
21 import java.util.Enumeration JavaDoc;
22 import java.util.Set JavaDoc;
23
24 // jmx imports
25
//
26
import javax.management.MBeanServer JavaDoc;
27 import javax.management.MBeanRegistration JavaDoc;
28 import javax.management.ObjectName JavaDoc;
29 import javax.management.MalformedObjectNameException JavaDoc;
30 import javax.management.InstanceNotFoundException JavaDoc;
31 import javax.management.ServiceNotFoundException JavaDoc;
32 import javax.management.ReflectionException JavaDoc;
33 import javax.management.MBeanException JavaDoc;
34 import com.sun.jmx.snmp.SnmpVarBind;
35 import com.sun.jmx.snmp.SnmpDefinitions;
36 import com.sun.jmx.snmp.SnmpStatusException;
37 import com.sun.jmx.snmp.SnmpPdu;
38 import com.sun.jmx.snmp.SnmpOid;
39 import com.sun.jmx.snmp.SnmpEngine;
40
41 /**
42  * Abstract class for representing an SNMP agent.
43  *
44  * The class is used by the SNMP protocol adaptor as the entry point in
45  * the SNMP agent to query.
46  *
47  * <p><b>This API is a Sun Microsystems internal API and is subject
48  * to change without notice.</b></p>
49  * @version 4.40 12/19/03
50  * @author Sun Microsystems, Inc
51  */

52
53 public abstract class SnmpMibAgent
54     implements SnmpMibAgentMBean, MBeanRegistration JavaDoc, Serializable JavaDoc {
55   
56     /**
57      * Default constructor.
58      */

59     public SnmpMibAgent() {
60     }
61     
62     // ---------------------------------------------------------------------
63
// PUBLIC METHODS
64
//----------------------------------------------------------------------
65

66     /**
67      * Initializes the MIB (with no registration of the MBeans into the
68      * MBean server).
69      *
70      * @exception IllegalAccessException The MIB can not be initialized.
71      */

72     public abstract void init() throws IllegalAccessException JavaDoc;
73   
74     /**
75      * Initializes the MIB but each single MBean representing the MIB
76      * is inserted into the MBean server.
77      *
78      * @param server The MBean server to register the service with.
79      * @param name The object name.
80      *
81      * @return The name of the SNMP MIB registered.
82      *
83      * @exception java.lang.Exception
84      */

85     public abstract ObjectName JavaDoc preRegister(MBeanServer JavaDoc server,
86                        ObjectName JavaDoc name)
87     throws java.lang.Exception JavaDoc;
88             
89     /**
90      * Not used in this context.
91      */

92     public void postRegister (Boolean JavaDoc registrationDone) {
93     }
94
95     /**
96      * Not used in this context.
97      */

98     public void preDeregister() throws java.lang.Exception JavaDoc {
99     }
100
101     /**
102      * Not used in this context.
103      */

104     public void postDeregister() {
105     }
106         
107     /**
108      * Processes a <CODE>get</CODE> operation.
109      * This method must update the SnmpVarBinds contained in the
110      * <var>{@link SnmpMibRequest} req</var> parameter.
111      *
112      * @param req The SnmpMibRequest object holding the list of variable to
113      * be retrieved. This list is composed of
114      * <CODE>SnmpVarBind</CODE> objects.
115      *
116      * @exception SnmpStatusException An error occured during the operation.
117      */

118     public abstract void get(SnmpMibRequest req)
119     throws SnmpStatusException;
120   
121     /**
122      * Processes a <CODE>getNext</CODE> operation.
123      * This method must update the SnmpVarBinds contained in the
124      * <var>{@link SnmpMibRequest} req</var> parameter.
125      *
126      * @param req The SnmpMibRequest object holding the list of
127      * OIDs from which the next variables should be retrieved.
128      * This list is composed of <CODE>SnmpVarBind</CODE> objects.
129      *
130      * @exception SnmpStatusException An error occured during the operation.
131      */

132     public abstract void getNext(SnmpMibRequest req)
133     throws SnmpStatusException;
134     
135     /**
136      * Processes a <CODE>getBulk</CODE> operation.
137      * This method must update the SnmpVarBinds contained in the
138      * <var>{@link SnmpMibRequest} req</var> parameter.
139      *
140      * @param req The SnmpMibRequest object holding the list of variable to
141      * be retrieved. This list is composed of
142      * <CODE>SnmpVarBind</CODE> objects.
143      *
144      * @param nonRepeat The number of variables, starting with the first
145      * variable in the variable-bindings, for which a single
146      * lexicographic successor is requested.
147      *
148      * @param maxRepeat The number of lexicographic successors requested
149      * for each of the last R variables. R is the number of variables
150      * following the first <CODE>nonRepeat</CODE> variables for which
151      * multiple lexicographic successors are requested.
152      *
153      * @exception SnmpStatusException An error occured during the operation.
154      */

155     public abstract void getBulk(SnmpMibRequest req, int nonRepeat,
156                  int maxRepeat)
157     throws SnmpStatusException;
158   
159     /**
160      * Processes a <CODE>set</CODE> operation.
161      * This method must update the SnmpVarBinds contained in the
162      * <var>{@link SnmpMibRequest} req</var> parameter.
163      * This method is called during the second phase of the SET two-phase
164      * commit.
165      *
166      * @param req The SnmpMibRequest object holding the list of variable to
167      * be set. This list is composed of
168      * <CODE>SnmpVarBind</CODE> objects.
169      *
170      * @exception SnmpStatusException An error occured during the operation.
171      * Throwing an exception in this method will break the
172      * atomicity of the SET operation. Care must be taken so that
173      * the exception is thrown in the {@link #check(SnmpMibRequest)}
174      * method instead.
175      */

176     public abstract void set(SnmpMibRequest req)
177     throws SnmpStatusException;
178       
179
180     /**
181      * Checks if a <CODE>set</CODE> operation can be performed.
182      * If the operation can not be performed, the method should throw an
183      * <CODE>SnmpStatusException</CODE>.
184      * This method is called during the first phase of the SET two-phase
185      * commit.
186      *
187      * @param req The SnmpMibRequest object holding the list of variable to
188      * be set. This list is composed of
189      * <CODE>SnmpVarBind</CODE> objects.
190      *
191      * @exception SnmpStatusException The <CODE>set</CODE> operation
192      * cannot be performed.
193      */

194     public abstract void check(SnmpMibRequest req)
195     throws SnmpStatusException;
196   
197     /**
198      * Gets the root object identifier of the MIB.
199      * <P>The root object identifier is the object identifier uniquely
200      * identifying the MIB.
201      *
202      * @return The root object identifier.
203      */

204     public abstract long[] getRootOid();
205     
206     // ---------------------------------------------------------------------
207
// GETTERS AND SETTERS
208
// ---------------------------------------------------------------------
209

210     /**
211      * Gets the reference to the MBean server in which the SNMP MIB is
212      * registered.
213      *
214      * @return The MBean server or null if the MIB is not registered in any
215      * MBean server.
216      */

217     public MBeanServer JavaDoc getMBeanServer() {
218         return server;
219     }
220       
221     /**
222      * Gets the reference to the SNMP protocol adaptor to which the MIB is
223      * bound.
224      *
225      * @return The SNMP MIB handler.
226      */

227     public SnmpMibHandler getSnmpAdaptor() {
228         return adaptor;
229     }
230     
231     /**
232      * Sets the reference to the SNMP protocol adaptor through which the MIB
233      * will be SNMP accessible and add this new MIB in the SNMP MIB handler.
234      *
235      * @param stack The SNMP MIB handler.
236      */

237     public void setSnmpAdaptor(SnmpMibHandler stack) {
238         if (adaptor != null) {
239             adaptor.removeMib(this);
240         }
241         adaptor = stack;
242         if (adaptor != null) {
243             adaptor.addMib(this);
244         }
245     }
246     
247      /**
248      * Sets the reference to the SNMP protocol adaptor through which the MIB
249      * will be SNMP accessible and add this new MIB in the SNMP MIB handler.
250      * This method is to be called to set a specific agent to a specific OID. This can be useful when dealing with MIB overlapping.
251      * Some OID can be implemented in more than one MIB. In this case, the OID nearest the agent will be used on SNMP operations.
252      * @param stack The SNMP MIB handler.
253      * @param oids The set of OIDs this agent implements.
254      *
255      * @since 1.5
256      */

257     public void setSnmpAdaptor(SnmpMibHandler stack, SnmpOid[] oids) {
258         if (adaptor != null) {
259             adaptor.removeMib(this);
260         }
261         adaptor = stack;
262         if (adaptor != null) {
263             adaptor.addMib(this, oids);
264         }
265     }
266
267     /**
268      * Sets the reference to the SNMP protocol adaptor through which the MIB
269      * will be SNMP accessible and adds this new MIB in the SNMP MIB handler.
270      * Adds a new contextualized MIB in the SNMP MIB handler.
271      *
272      * @param stack The SNMP MIB handler.
273      * @param contextName The MIB context name. If null is passed, will be registered in the default context.
274      *
275      * @exception IllegalArgumentException If the parameter is null.
276      *
277      * @since 1.5
278      */

279     public void setSnmpAdaptor(SnmpMibHandler stack, String JavaDoc contextName) {
280         if (adaptor != null) {
281             adaptor.removeMib(this, contextName);
282         }
283         adaptor = stack;
284         if (adaptor != null) {
285             adaptor.addMib(this, contextName);
286         }
287     }
288     /**
289      * Sets the reference to the SNMP protocol adaptor through which the MIB
290      * will be SNMP accessible and adds this new MIB in the SNMP MIB handler.
291      * Adds a new contextualized MIB in the SNMP MIB handler.
292      *
293      * @param stack The SNMP MIB handler.
294      * @param contextName The MIB context name. If null is passed, will be registered in the default context.
295      * @param oids The set of OIDs this agent implements.
296      * @exception IllegalArgumentException If the parameter is null.
297      *
298      * @since 1.5
299      */

300     public void setSnmpAdaptor(SnmpMibHandler stack,
301                    String JavaDoc contextName,
302                    SnmpOid[] oids) {
303         if (adaptor != null) {
304             adaptor.removeMib(this, contextName);
305         }
306         adaptor = stack;
307         if (adaptor != null) {
308             adaptor.addMib(this, contextName, oids);
309         }
310     }
311
312     /**
313      * Gets the object name of the SNMP protocol adaptor to which the MIB
314      * is bound.
315      *
316      * @return The name of the SNMP protocol adaptor.
317      */

318     public ObjectName JavaDoc getSnmpAdaptorName() {
319         return adaptorName;
320     }
321     
322     /**
323      * Sets the reference to the SNMP protocol adaptor through which the MIB
324      * will be SNMP accessible and add this new MIB in the SNMP MIB handler
325      * associated to the specified <CODE>name</CODE>.
326      *
327      * @param name The name of the SNMP protocol adaptor.
328      *
329      * @exception InstanceNotFoundException The SNMP protocol adaptor does
330      * not exist in the MBean server.
331      *
332      * @exception ServiceNotFoundException This SNMP MIB is not registered
333      * in the MBean server or the requested service is not supported.
334      */

335     public void setSnmpAdaptorName(ObjectName JavaDoc name)
336     throws InstanceNotFoundException JavaDoc, ServiceNotFoundException JavaDoc {
337               
338         if (server == null) {
339             throw new ServiceNotFoundException JavaDoc(mibName + " is not registered in the MBean server");
340         }
341         // First remove the reference on the old adaptor server.
342
//
343
if (adaptor != null) {
344             adaptor.removeMib(this);
345         }
346         
347         // Then update the reference to the new adaptor server.
348
//
349
Object JavaDoc[] params = {this};
350         String JavaDoc[] signature = {"com.sun.jmx.snmp.agent.SnmpMibAgent"};
351         try {
352             adaptor = (SnmpMibHandler)(server.invoke(name, "addMib", params,
353                              signature));
354         } catch (InstanceNotFoundException JavaDoc e) {
355             throw new InstanceNotFoundException JavaDoc(name.toString());
356         } catch (ReflectionException JavaDoc e) {
357             throw new ServiceNotFoundException JavaDoc(name.toString());
358         } catch (MBeanException JavaDoc e) {
359             // Should never occur...
360
}
361         
362         adaptorName = name;
363     }
364     /**
365      * Sets the reference to the SNMP protocol adaptor through which the MIB
366      * will be SNMP accessible and add this new MIB in the SNMP MIB handler
367      * associated to the specified <CODE>name</CODE>.
368      * This method is to be called to set a specific agent to a specific OID. This can be useful when dealing with MIB overlapping.
369      * Some OID can be implemented in more than one MIB. In this case, the OID nearer agent will be used on SNMP operations.
370      * @param name The name of the SNMP protocol adaptor.
371      * @param oids The set of OIDs this agent implements.
372      * @exception InstanceNotFoundException The SNMP protocol adaptor does
373      * not exist in the MBean server.
374      *
375      * @exception ServiceNotFoundException This SNMP MIB is not registered
376      * in the MBean server or the requested service is not supported.
377      *
378      * @since 1.5
379      */

380     public void setSnmpAdaptorName(ObjectName JavaDoc name, SnmpOid[] oids)
381     throws InstanceNotFoundException JavaDoc, ServiceNotFoundException JavaDoc {
382               
383         if (server == null) {
384             throw new ServiceNotFoundException JavaDoc(mibName + " is not registered in the MBean server");
385         }
386         // First remove the reference on the old adaptor server.
387
//
388
if (adaptor != null) {
389             adaptor.removeMib(this);
390         }
391         
392         // Then update the reference to the new adaptor server.
393
//
394
Object JavaDoc[] params = {this, oids};
395         String JavaDoc[] signature = {"com.sun.jmx.snmp.agent.SnmpMibAgent",
396     oids.getClass().getName()};
397         try {
398             adaptor = (SnmpMibHandler)(server.invoke(name, "addMib", params,
399                              signature));
400         } catch (InstanceNotFoundException JavaDoc e) {
401             throw new InstanceNotFoundException JavaDoc(name.toString());
402         } catch (ReflectionException JavaDoc e) {
403             throw new ServiceNotFoundException JavaDoc(name.toString());
404         } catch (MBeanException JavaDoc e) {
405             // Should never occur...
406
}
407         
408         adaptorName = name;
409     }
410     /**
411      * Sets the reference to the SNMP protocol adaptor through which the MIB
412      * will be SNMP accessible and add this new MIB in the SNMP MIB handler
413      * associated to the specified <CODE>name</CODE>.
414      *
415      * @param name The name of the SNMP protocol adaptor.
416      * @param contextName The MIB context name. If null is passed, will be registered in the default context.
417      * @exception InstanceNotFoundException The SNMP protocol adaptor does
418      * not exist in the MBean server.
419      *
420      * @exception ServiceNotFoundException This SNMP MIB is not registered
421      * in the MBean server or the requested service is not supported.
422      *
423      * @since 1.5
424      */

425     public void setSnmpAdaptorName(ObjectName JavaDoc name, String JavaDoc contextName)
426     throws InstanceNotFoundException JavaDoc, ServiceNotFoundException JavaDoc {
427               
428         if (server == null) {
429             throw new ServiceNotFoundException JavaDoc(mibName + " is not registered in the MBean server");
430         }
431         
432         // First remove the reference on the old adaptor server.
433
//
434
if (adaptor != null) {
435             adaptor.removeMib(this, contextName);
436         }
437         
438         // Then update the reference to the new adaptor server.
439
//
440
Object JavaDoc[] params = {this, contextName};
441         String JavaDoc[] signature = {"com.sun.jmx.snmp.agent.SnmpMibAgent", "java.lang.String"};
442         try {
443             adaptor = (SnmpMibHandler)(server.invoke(name, "addMib", params,
444                              signature));
445         } catch (InstanceNotFoundException JavaDoc e) {
446             throw new InstanceNotFoundException JavaDoc(name.toString());
447         } catch (ReflectionException JavaDoc e) {
448             throw new ServiceNotFoundException JavaDoc(name.toString());
449         } catch (MBeanException JavaDoc e) {
450             // Should never occur...
451
}
452         
453         adaptorName = name;
454     }
455  
456     /**
457      * Sets the reference to the SNMP protocol adaptor through which the MIB
458      * will be SNMP accessible and add this new MIB in the SNMP MIB handler
459      * associated to the specified <CODE>name</CODE>.
460      *
461      * @param name The name of the SNMP protocol adaptor.
462      * @param contextName The MIB context name. If null is passed, will be registered in the default context.
463      * @param oids The set of OIDs this agent implements.
464      * @exception InstanceNotFoundException The SNMP protocol adaptor does
465      * not exist in the MBean server.
466      *
467      * @exception ServiceNotFoundException This SNMP MIB is not registered
468      * in the MBean server or the requested service is not supported.
469      *
470      * @since 1.5
471      */

472     public void setSnmpAdaptorName(ObjectName JavaDoc name,
473                    String JavaDoc contextName, SnmpOid[] oids)
474     throws InstanceNotFoundException JavaDoc, ServiceNotFoundException JavaDoc {
475     
476         if (server == null) {
477             throw new ServiceNotFoundException JavaDoc(mibName + " is not registered in the MBean server");
478         }
479         
480         // First remove the reference on the old adaptor server.
481
//
482
if (adaptor != null) {
483             adaptor.removeMib(this, contextName);
484         }
485         
486         // Then update the reference to the new adaptor server.
487
//
488
Object JavaDoc[] params = {this, contextName, oids};
489         String JavaDoc[] signature = {"com.sun.jmx.snmp.agent.SnmpMibAgent", "java.lang.String", oids.getClass().getName()};
490         try {
491             adaptor = (SnmpMibHandler)(server.invoke(name, "addMib", params,
492                              signature));
493         } catch (InstanceNotFoundException JavaDoc e) {
494             throw new InstanceNotFoundException JavaDoc(name.toString());
495         } catch (ReflectionException JavaDoc e) {
496             throw new ServiceNotFoundException JavaDoc(name.toString());
497         } catch (MBeanException JavaDoc e) {
498             // Should never occur...
499
}
500         
501         adaptorName = name;
502     }
503
504     /**
505      * Indicates whether or not the MIB module is bound to a SNMP protocol
506      * adaptor.
507      * As a reminder, only bound MIBs can be accessed through SNMP protocol
508      * adaptor.
509      *
510      * @return <CODE>true</CODE> if the MIB module is bound,
511      * <CODE>false</CODE> otherwise.
512      */

513     public boolean getBindingState() {
514         if (adaptor == null)
515             return false;
516         else
517             return true;
518     }
519
520     /**
521      * Gets the MIB name.
522      *
523      * @return The MIB name.
524      */

525     public String JavaDoc getMibName() {
526         return mibName;
527     }
528     
529     /**
530      * This is a factory method for creating new SnmpMibRequest objects.
531      * @param reqPdu The received PDU.
532      * @param vblist The vector of SnmpVarBind objects in which the
533      * MIB concerned by this request is involved.
534      * @param version The protocol version of the SNMP request.
535      * @param userData User allocated contextual data.
536      *
537      * @return A new SnmpMibRequest object.
538      *
539      * @since 1.5
540      **/

541     public static SnmpMibRequest newMibRequest(SnmpPdu reqPdu,
542                            Vector JavaDoc vblist,
543                            int version,
544                            Object JavaDoc userData)
545     {
546     return new SnmpMibRequestImpl(null,
547                       reqPdu,
548                       vblist,
549                       version,
550                       userData,
551                       null,
552                       SnmpDefinitions.noAuthNoPriv,
553                       getSecurityModel(version),
554                       null,null);
555     }
556     /**
557      * This is a factory method for creating new SnmpMibRequest objects.
558      * @param engine The local engine.
559      * @param reqPdu The received pdu.
560      * @param vblist The vector of SnmpVarBind objects in which the
561      * MIB concerned by this request is involved.
562      * @param version The protocol version of the SNMP request.
563      * @param userData User allocated contextual data.
564      *
565      * @return A new SnmpMibRequest object.
566      *
567      * @since 1.5
568      **/

569     public static SnmpMibRequest newMibRequest(SnmpEngine engine,
570                            SnmpPdu reqPdu,
571                            Vector JavaDoc vblist,
572                            int version,
573                            Object JavaDoc userData,
574                            String JavaDoc principal,
575                            int securityLevel,
576                            int securityModel,
577                            byte[] contextName,
578                            byte[] accessContextName) {
579     return new SnmpMibRequestImpl(engine,
580                       reqPdu,
581                       vblist,
582                       version,
583                       userData,
584                       principal,
585                       securityLevel,
586                       securityModel,
587                       contextName,
588                       accessContextName);
589     }
590     // ---------------------------------------------------------------------
591
// PACKAGE METHODS
592
// ---------------------------------------------------------------------
593

594     /**
595      * Processes a <CODE>getBulk</CODE> operation using call to
596      * <CODE>getNext</CODE>.
597      * The method implements the <CODE>getBulk</CODE> operation by calling
598      * appropriately the <CODE>getNext</CODE> method.
599      *
600      * @param req The SnmpMibRequest containing the variable list to be
601      * retrieved.
602      *
603      * @param nonRepeat The number of variables, starting with the first
604      * variable in the variable-bindings, for which a single lexicographic
605      * successor is requested.
606      *
607      * @param maxRepeat The number of lexicographic successors
608      * requested for each of the last R variables. R is the number of
609      * variables following the first nonRepeat variables for which
610      * multiple lexicographic successors are requested.
611      *
612      * @return The variable list containing returned values.
613      *
614      * @exception SnmpStatusException An error occured during the operation.
615      */

616     void getBulkWithGetNext(SnmpMibRequest req, int nonRepeat, int maxRepeat)
617     throws SnmpStatusException {
618     final Vector JavaDoc list = req.getSubList();
619
620         // RFC 1905, Section 4.2.3, p14
621
final int L = list.size() ;
622         final int N = Math.max(Math.min(nonRepeat, L), 0) ;
623         final int M = Math.max(maxRepeat, 0) ;
624         final int R = L - N ;
625     
626         // Let's build the varBindList for the response pdu
627
//
628
// int errorStatus = SnmpDefinitions.snmpRspNoError ;
629
// int errorIndex = 0 ;
630
if (L != 0) {
631       
632             // Non-repeaters and first row of repeaters
633
//
634
getNext(req);
635     
636             // Now the remaining repeaters
637
//
638
Vector JavaDoc repeaters= splitFrom(list, N);
639         SnmpMibRequestImpl repeatedReq =
640         new SnmpMibRequestImpl(req.getEngine(),
641                        req.getPdu(),
642                        repeaters,
643                        SnmpDefinitions.snmpVersionTwo,
644                        req.getUserData(),
645                        req.getPrincipal(),
646                        req.getSecurityLevel(),
647                        req.getSecurityModel(),
648                        req.getContextName(),
649                        req.getAccessContextName());
650             for (int i = 2 ; i <= M ; i++) {
651                 getNext(repeatedReq);
652                 concatVector(req, repeaters);
653             }
654         }
655     }
656     
657      
658     // ---------------------------------------------------------------------
659
// PRIVATE METHODS
660
// ---------------------------------------------------------------------
661

662     /**
663      * This method creates a new Vector which does not contain the first
664      * element up to the specified limit.
665      *
666      * @param original The original vector.
667      * @param limit The limit.
668      */

669     private Vector JavaDoc splitFrom(Vector JavaDoc original, int limit) {
670         
671         int max= original.size();
672         Vector JavaDoc result= new Vector JavaDoc(max - limit);
673         int i= limit;
674         
675         // Ok the loop looks a bit strange. But in order to improve the
676
// perf, we try to avoid reference to the limit variable from
677
// within the loop ...
678
//
679
for(Enumeration JavaDoc e= original.elements(); e.hasMoreElements(); --i) {
680             SnmpVarBind var= (SnmpVarBind) e.nextElement();
681             if (i >0)
682                 continue;
683             result.addElement(new SnmpVarBind(var.oid, var.value));
684         }
685         return result;
686     }
687   
688     private void concatVector(SnmpMibRequest req, Vector JavaDoc source) {
689         for(Enumeration JavaDoc e= source.elements(); e.hasMoreElements(); ) {
690             SnmpVarBind var= (SnmpVarBind) e.nextElement();
691             // We need to duplicate the SnmpVarBind otherwise it is going
692
// to be overloaded by the next get Next ...
693
req.addVarBind(new SnmpVarBind(var.oid, var.value));
694         }
695     }
696
697     private void concatVector(Vector JavaDoc target, Vector JavaDoc source) {
698         for(Enumeration JavaDoc e= source.elements(); e.hasMoreElements(); ) {
699             SnmpVarBind var= (SnmpVarBind) e.nextElement();
700             // We need to duplicate the SnmpVarBind otherwise it is going
701
// to be overloaded by the next get Next ...
702
target.addElement(new SnmpVarBind(var.oid, var.value));
703         }
704     }
705
706     static private Vector JavaDoc vector(Enumeration JavaDoc e) {
707     if (e == null) return null;
708     Vector JavaDoc v = new Vector JavaDoc();
709     while (e.hasMoreElements()) v.addElement(e.nextElement());
710     return v;
711     }
712
713     private static int getSecurityModel(int version) {
714     switch(version) {
715     case SnmpDefinitions.snmpVersionOne:
716         return SnmpDefinitions.snmpV1SecurityModel;
717     default:
718         return SnmpDefinitions.snmpV2SecurityModel;
719     }
720     }
721
722     // ---------------------------------------------------------------------
723
// PROTECTED VARIABLES
724
// ---------------------------------------------------------------------
725

726     /**
727      * The object name of the MIB.
728      * @serial
729      */

730     protected String JavaDoc mibName;
731     
732     /**
733      * The reference to the MBean server.
734      * @serial
735      */

736     protected MBeanServer JavaDoc server;
737   
738     // ---------------------------------------------------------------------
739
// PRIVATE VARIABLES
740
// ---------------------------------------------------------------------
741

742     /**
743      * The object name of the SNMP protocol adaptor.
744      * @serial
745      */

746     private ObjectName JavaDoc adaptorName;
747     
748     /**
749      * The reference to the SNMP stack.
750      */

751     private transient SnmpMibHandler adaptor;
752 }
753
Popular Tags