1. /*
  2. * @(#)file SnmpOidDatabaseSupport.java
  3. * @(#)author Sun Microsystems, Inc.
  4. * @(#)version 1.14
  5. * @(#)date 04/09/15
  6. *
  7. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  8. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  9. *
  10. */
  11. package com.sun.jmx.snmp;
  12. // java import
  13. //
  14. import java.util.Vector;
  15. // jmx import
  16. //
  17. import com.sun.jmx.snmp.SnmpOidTable;
  18. import com.sun.jmx.snmp.SnmpOidRecord;
  19. import com.sun.jmx.snmp.SnmpStatusException;
  20. /**
  21. * Defines a set of <CODE>SnmpOidTable</CODE> objects containing metadata definitions for MIB variables.
  22. * Each <CODE>SnmpOidTable</CODE> should contain information on variables of one MIB.
  23. * It provides resolution of all MIB variables contained in the <CODE>SnmpOidTable</CODE> objects.
  24. * <p><b>This API is a Sun Microsystems internal API and is subject
  25. * to change without notice.</b></p>
  26. */
  27. public class SnmpOidDatabaseSupport implements SnmpOidDatabase {
  28. /**
  29. * Creates an empty <CODE>SnmpOidDatabaseSupport</CODE>.
  30. */
  31. public SnmpOidDatabaseSupport(){
  32. tables=new Vector();
  33. }
  34. /**
  35. * Creates an <CODE>SnmpOidDatabaseSupport</CODE> containing the specified <CODE>SnmpOidTable</CODE> object.
  36. * @param table The <CODE>SnmpOidTable</CODE> object used to initialize this <CODE>SnmpOidDatabaseSupport</CODE>.
  37. */
  38. public SnmpOidDatabaseSupport(SnmpOidTable table){
  39. tables=new Vector();
  40. tables.addElement(table);
  41. }
  42. /**
  43. * Adds a <CODE>SnmpOidTable</CODE> object in this <CODE>SnmpOidDatabase</CODE>.
  44. * @param table The table to add.
  45. */
  46. public void add(SnmpOidTable table) {
  47. if (!tables.contains(table)) {
  48. tables.addElement(table);
  49. }
  50. }
  51. /**
  52. * Removes a <CODE>SnmpOidTable</CODE> object from this <CODE>SnmpOidDatabase</CODE>.
  53. * @param table The table to be removed.
  54. * @exception SnmpStatusException The specified <CODE>SnmpOidTable</CODE> does not exist in this <CODE>SnmpOidDatabase</CODE>.
  55. */
  56. public void remove(SnmpOidTable table) throws SnmpStatusException {
  57. if (!tables.contains(table)) {
  58. throw new SnmpStatusException("The specified SnmpOidTable does not exist in this SnmpOidDatabase");
  59. }
  60. tables.removeElement(table);
  61. }
  62. /**
  63. * Searches for a MIB variable given its logical name and returns an <CODE>SnmpOidRecord</CODE>
  64. * object containing information on the variable.
  65. * @param name The name of the MIB variable.
  66. * @return The <CODE>SnmpOidRecord</CODE> object containing information on the variable.
  67. *
  68. * @exception SnmpStatusException The specified name does not exist in this <CODE>SnmpOidDatabase</CODE>
  69. */
  70. public SnmpOidRecord resolveVarName(String name) throws SnmpStatusException {
  71. for (int i=0;i<tables.size();i++) {
  72. try {
  73. return (((SnmpOidTable)tables.elementAt(i)).resolveVarName(name));
  74. }
  75. catch (SnmpStatusException e) {
  76. if (i==tables.size()-1) {
  77. throw new SnmpStatusException(e.getMessage());
  78. }
  79. }
  80. }
  81. return null;
  82. }
  83. /**
  84. * Searches for a MIB variable given its OID and returns an <CODE>SnmpOidRecord</CODE> object containing
  85. * information on the variable.
  86. * @param oid The OID of the MIB variable.
  87. * @return The <CODE>SnmpOidRecord</CODE> object containing information on the variable.
  88. * @exception SnmpStatusException The specified oid does not exist in this <CODE>SnmpOidDatabase</CODE>.
  89. */
  90. public SnmpOidRecord resolveVarOid(String oid) throws SnmpStatusException {
  91. for (int i=0;i<tables.size();i++) {
  92. try {
  93. return (((SnmpOidTable)tables.elementAt(i)).resolveVarOid(oid));
  94. }
  95. catch (SnmpStatusException e) {
  96. if (i==tables.size()-1) {
  97. throw new SnmpStatusException(e.getMessage());
  98. }
  99. }
  100. }
  101. return null;
  102. }
  103. /**
  104. * Returns a list that can be used to traverse all the entries of the <CODE>SnmpOidTable</CODE> objects
  105. * of this <CODE>SnmpOidDatabase</CODE>.
  106. * @return A vector of <CODE>SnmpOidTable</CODE> objects containing all the elements of this <CODE>SnmpOidDatabase</CODE>.
  107. */
  108. public Vector getAllEntries() {
  109. Vector res = new Vector();
  110. for (int i=0;i<tables.size();i++) {
  111. Vector tmp = ((SnmpOidTable)tables.elementAt(i)).getAllEntries();
  112. if (tmp != null) {
  113. for(int ii=0; ii<tmp.size(); ii++) {
  114. res.addElement(tmp.elementAt(ii));
  115. }
  116. }
  117. }
  118. // res.addAll(((SnmpOidTable)tables.elementAt(i)).getAllEntries());
  119. return res;
  120. }
  121. /**
  122. * Removes all <CODE>SnmpOidTable</CODE> objects from this <CODE>SnmpOidDatabase</CODE>.
  123. */
  124. public void removeAll(){
  125. tables.removeAllElements() ;
  126. }
  127. private Vector tables;
  128. }