CorbaTableUi.java
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:5k
- /* $Id: CorbaTableUi.src,v 1.3 2002/09/09 05:45:01 tonyjpaul Exp $ */
- /*
- * @(#)CorbaTableUi.java
- * Copyright (c) 1996-2002 AdventNet, Inc. All Rights Reserved.
- * Please read the COPYRIGHTS file for more
- */
- import org.omg.CosNaming.*;
- import java.lang.*;
- import java.util.*;
- import java.net.*;
- import org.omg.CORBA.*;
- import com.adventnet.snmp.corba.*;
- import ParseOptions;
- import com.adventnet.snmp.mibs.*;
- import com.adventnet.snmp.snmp2.*;
- import javax.swing.*;
- import javax.swing.table.*;
- import java.awt.event.*;
- public class CorbaTableUi {
- SnmpTable table;
- org.omg.CORBA.ORB orb = null;
- com.adventnet.snmp.corba.SnmpFactory factory = null;
- com.adventnet.snmp.corba.SnmpTableListener listener = null;
- public CorbaTableUi( String args[], String version, String host, String community, String port, String retries, String timeout, String username, String authProtocol, String authPassword , String privPassword, String contextID, String contextName, String mibs , String tableoid)
- {
- final int USM_SECURITY_MODEL = 3;
- try
- {
- orb = org.omg.CORBA.ORB.init( args, null );
- org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService" );
- NamingContext ncRef = NamingContextHelper.narrow( objRef );
- NameComponent nc = new NameComponent( "AdventnetSnmpFactory" , "" );
- NameComponent[] path = { nc };
-
- factory = com.adventnet.snmp.corba.SnmpFactoryHelper.narrow( ncRef.resolve( path ) );
- table = factory.createTable();
- if(version != null)
- { // if SNMP version is specified, set it
- if(version.equals("v1"))
- table.setSnmpVersion( com.adventnet.snmp.beans.SnmpTarget.VERSION1 ) ;
- else if(version.equals("v2c"))
- table.setSnmpVersion( com.adventnet.snmp.beans.SnmpTarget.VERSION2C );
- else if(version.equals("v3"))
- table.setSnmpVersion( com.adventnet.snmp.beans.SnmpTarget.VERSION3 );
- else
- {
- JOptionPane.showMessageDialog(null,"Invalid Version Number" ,"Error Message",JOptionPane.ERROR_MESSAGE);
- factory.destroyTable(table.getName());
- table = null;
- factory = null;
- return ;
- }
- }
- else
- table.setSnmpVersion( com.adventnet.snmp.beans.SnmpTarget.VERSION1 );
-
- table.setTargetHost(host ); // set the agent hostname
- table.setPollInterval(10);
- if (community != null) // set the community if specified
- table.setCommunity( community );
- // set the timeout/retries/port parameters, if specified
- if (port != null)
- table.setTargetPort( Integer.parseInt(port) );
- if (retries != null)
- table.setRetries( Integer.parseInt(retries) );
- if (timeout != null)
- table.setTimeout( Integer.parseInt(timeout) );
-
-
- if(table.getSnmpVersion() == com.adventnet.snmp.beans.SnmpTarget.VERSION3)
- {
- table.setPrincipal(username);
- table.setAuthPassword(authPassword);
- table.setPrivPassword(privPassword);
- table.setContextID(contextID);
- table.setContextName(contextName);
- if(authProtocol.equals("SHA"))
- table.setAuthProtocol(com.adventnet.snmp.beans.SnmpTarget.SHA_AUTH);
- else
- table.setAuthProtocol(com.adventnet.snmp.beans.SnmpTarget.MD5_AUTH);
- }
- // instantiate this class to receive table events, and register it
- listener = new CorbaTableDemoListenerImpl( table );
- table.addSnmpTableListener(listener);
- orb.connect( listener );
- if (mibs != null)
- {
- table.loadMibs(mibs);
- }
- // Set the table OID in SnmpTable. Once specified,
- // SnmpTable will automatically get the data and send table events
- try {
- table.setTableOID( tableoid );
- } catch (Exception ex) {
- JOptionPane.showMessageDialog(null,"Invalid Table oid " +ex.toString() ,"Error Message",JOptionPane.ERROR_MESSAGE);
- factory.destroyTable(table.getName());
- table = null;
- factory = null;
- return ;
- }
- TableModel model = (TableModel)listener;
- JTable t = new JTable(model);
- if( t.getColumnCount() > 5)
- t.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- JScrollPane pan = new JScrollPane(t);
- JFrame f = new JFrame();
- f.setTitle("AdventNet SNMP CORBA Demo");
- f.getContentPane().add(pan);
- f.setVisible(true);
- f.setSize(600,400);
- WindowListener l = new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- table.removeSnmpTableListener((CorbaTableDemoListenerImpl)listener);
- orb.disconnect(listener);
- listener = null;
- factory.destroyTable(table.getName());
- table = null;
- factory = null;
- }
- };
- f.addWindowListener(l);
- t.validate();
- t.updateUI();
- f.validate();
- } catch (Exception ex) {
- JOptionPane.showMessageDialog(null,"Failed "+ex.toString() ,"Error Message",JOptionPane.ERROR_MESSAGE);
- }
- }
- }