CorbaTableDemoListenerImpl.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:3k
源码类别:

SNMP编程

开发平台:

C/C++

  1. /* $Id: CorbaTableDemoListenerImpl.src,v 1.3 2002/09/09 05:45:01 tonyjpaul Exp $ */
  2. /*
  3.  * @(#)CorbaTableDemoListenerImpl.java
  4.  * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
  5.  * Please read the COPYRIGHTS file for more 
  6.  */
  7. import java.util.*;
  8. import com.adventnet.snmp.snmp2.*;
  9. import com.adventnet.snmp.mibs.*;
  10. import com.adventnet.snmp.beans.*;
  11. import javax.swing.table.*;
  12. import javax.swing.event.*;
  13. public class CorbaTableDemoListenerImpl extends 
  14. com.adventnet.snmp.corba._SnmpTableListenerImplBase  implements TableModel {
  15. public CorbaTableDemoListenerImpl( com.adventnet.snmp.corba.SnmpTable tbl ){
  16. this.table = tbl;
  17. }
  18.             
  19.     // This method is called when trap is received by SnmpTrapReceiver
  20.     public void tableChanged(com.adventnet.snmp.corba.TableEvent tblEvent) {
  21. try {
  22. StringBuffer sb = new StringBuffer();
  23. if ( tblEvent.startRow == 0) {
  24. tableData = new Vector();
  25. colName = new String[table.getColumnCount()];
  26. for (int i=0;i<table.getColumnCount();i++)
  27. colName[i]=table.getColumnName(i);
  28. }
  29. if (table.getRowCount() == 0)
  30. System.err.println("Request failed or timed out. n"+
  31. table.getErrorString());
  32. else {
  33. sb = new StringBuffer();
  34. String data[] = new String[table.getColumnCount()];
  35.         for (int j= tblEvent.startRow;j<=tblEvent.endRow;j++) { 
  36. for (int i=0;i<table.getColumnCount();i++)
  37. {
  38. data[i] = table.getValueAt(j,i);
  39. }
  40. tableData.addElement(data);
  41. TableModelEvent tevt = new TableModelEvent(
  42. this,tblEvent.startRow,tblEvent.endRow,
  43. tblEvent.column, tblEvent.Type);
  44. for (Enumeration en=tablelisteners.elements();
  45. en.hasMoreElements();) {
  46. TableModelListener rl = (TableModelListener) 
  47. en.nextElement();
  48. rl.tableChanged(tevt);
  49. }   
  50. }
  51.         }
  52.     } catch (Exception ex) {
  53. System.err.println("Failed: "+ ex);
  54. }
  55.     com.adventnet.snmp.corba.SnmpTable table = null;    
  56. Vector tableData= null;
  57. String [] colName = null;
  58. Vector tablelisteners = new Vector();
  59.     
  60. public  void addTableModelListener(TableModelListener l){
  61. tablelisteners.addElement(l);
  62. }
  63. public  Class getColumnClass(int columnIndex){
  64. return String.class;
  65. }
  66. public String getColumnName(int columnIndex){
  67. return table.getColumnName(columnIndex);
  68. public int getRowCount(){
  69. if(tableData == null)
  70. return 0;
  71. return tableData.size();
  72. public Object getValueAt(int rowIndex, int columnIndex){
  73. if( tableData.size() ==0)
  74. return null;
  75. String [] a = (String [])tableData.elementAt(rowIndex);
  76. return a[columnIndex];
  77. public boolean isCellEditable(int rowIndex, int columnIndex) {
  78. return false;
  79. public void removeTableModelListener(TableModelListener l){
  80. tablelisteners.removeElement(l);
  81. public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
  82. }
  83. public int getColumnCount(){
  84. return table.getColumnCount();
  85. }