KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)file SnmpOidDatabaseSupport.java
3  * @(#)author Sun Microsystems, Inc.
4  * @(#)version 1.14
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 // java import
17
//
18
import java.util.Vector JavaDoc;
19
20 // jmx import
21
//
22
import com.sun.jmx.snmp.SnmpOidTable;
23 import com.sun.jmx.snmp.SnmpOidRecord;
24 import com.sun.jmx.snmp.SnmpStatusException;
25
26 /**
27  * Defines a set of <CODE>SnmpOidTable</CODE> objects containing metadata definitions for MIB variables.
28  * Each <CODE>SnmpOidTable</CODE> should contain information on variables of one MIB.
29  * It provides resolution of all MIB variables contained in the <CODE>SnmpOidTable</CODE> objects.
30  * <p><b>This API is a Sun Microsystems internal API and is subject
31  * to change without notice.</b></p>
32  */

33
34 public class SnmpOidDatabaseSupport implements SnmpOidDatabase {
35
36     /**
37      * Creates an empty <CODE>SnmpOidDatabaseSupport</CODE>.
38      */

39     public SnmpOidDatabaseSupport(){
40         tables=new Vector JavaDoc();
41     }
42     
43     /**
44      * Creates an <CODE>SnmpOidDatabaseSupport</CODE> containing the specified <CODE>SnmpOidTable</CODE> object.
45      * @param table The <CODE>SnmpOidTable</CODE> object used to initialize this <CODE>SnmpOidDatabaseSupport</CODE>.
46      */

47     public SnmpOidDatabaseSupport(SnmpOidTable table){
48         tables=new Vector JavaDoc();
49         tables.addElement(table);
50     }
51
52     /**
53      * Adds a <CODE>SnmpOidTable</CODE> object in this <CODE>SnmpOidDatabase</CODE>.
54      * @param table The table to add.
55      */

56     public void add(SnmpOidTable table) {
57         if (!tables.contains(table)) {
58             tables.addElement(table);
59         }
60     }
61
62     /**
63      * Removes a <CODE>SnmpOidTable</CODE> object from this <CODE>SnmpOidDatabase</CODE>.
64      * @param table The table to be removed.
65      * @exception SnmpStatusException The specified <CODE>SnmpOidTable</CODE> does not exist in this <CODE>SnmpOidDatabase</CODE>.
66      */

67     public void remove(SnmpOidTable table) throws SnmpStatusException {
68         if (!tables.contains(table)) {
69             throw new SnmpStatusException("The specified SnmpOidTable does not exist in this SnmpOidDatabase");
70         }
71         tables.removeElement(table);
72     }
73
74     /**
75      * Searches for a MIB variable given its logical name and returns an <CODE>SnmpOidRecord</CODE>
76      * object containing information on the variable.
77      * @param name The name of the MIB variable.
78      * @return The <CODE>SnmpOidRecord</CODE> object containing information on the variable.
79      *
80      * @exception SnmpStatusException The specified name does not exist in this <CODE>SnmpOidDatabase</CODE>
81      */

82     public SnmpOidRecord resolveVarName(String JavaDoc name) throws SnmpStatusException {
83         for (int i=0;i<tables.size();i++) {
84             try {
85                 return (((SnmpOidTable)tables.elementAt(i)).resolveVarName(name));
86             }
87             catch (SnmpStatusException e) {
88                 if (i==tables.size()-1) {
89                     throw new SnmpStatusException(e.getMessage());
90                 }
91             }
92         }
93         return null;
94     }
95
96     /**
97      * Searches for a MIB variable given its OID and returns an <CODE>SnmpOidRecord</CODE> object containing
98      * information on the variable.
99      * @param oid The OID of the MIB variable.
100      * @return The <CODE>SnmpOidRecord</CODE> object containing information on the variable.
101      * @exception SnmpStatusException The specified oid does not exist in this <CODE>SnmpOidDatabase</CODE>.
102      */

103     public SnmpOidRecord resolveVarOid(String JavaDoc oid) throws SnmpStatusException {
104         for (int i=0;i<tables.size();i++) {
105             try {
106                 return (((SnmpOidTable)tables.elementAt(i)).resolveVarOid(oid));
107             }
108             catch (SnmpStatusException e) {
109                 if (i==tables.size()-1) {
110                     throw new SnmpStatusException(e.getMessage());
111                 }
112             }
113         }
114         return null;
115     }
116
117     /**
118      * Returns a list that can be used to traverse all the entries of the <CODE>SnmpOidTable</CODE> objects
119      * of this <CODE>SnmpOidDatabase</CODE>.
120      * @return A vector of <CODE>SnmpOidTable</CODE> objects containing all the elements of this <CODE>SnmpOidDatabase</CODE>.
121      */

122     public Vector JavaDoc getAllEntries() {
123         Vector JavaDoc res = new Vector JavaDoc();
124         for (int i=0;i<tables.size();i++) {
125         Vector JavaDoc tmp = ((SnmpOidTable)tables.elementAt(i)).getAllEntries();
126         if (tmp != null) {
127         for(int ii=0; ii<tmp.size(); ii++) {
128             res.addElement(tmp.elementAt(ii));
129         }
130         }
131     }
132 // res.addAll(((SnmpOidTable)tables.elementAt(i)).getAllEntries());
133
return res;
134     }
135
136     /**
137      * Removes all <CODE>SnmpOidTable</CODE> objects from this <CODE>SnmpOidDatabase</CODE>.
138      */

139     public void removeAll(){
140         tables.removeAllElements() ;
141     }
142
143     private Vector JavaDoc tables;
144 }
145
Popular Tags