tableBeanDemo.java
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:7k
- /*$Id: tableBeanDemo.src,v 1.3.2.3 2009/01/28 12:51:12 prathika Exp $*/
- /*
- * @(#)tableBeanDemo.java
- * Copyright (c) 1996-2009 AdventNet, Inc. All Rights Reserved.
- * Please read the COPYRIGHTS file for more details.
- */
- /**
- * An example of using the TableBean component.
- * This combines the JTable and SnmpTableModel components.
- * [-v] <version> - version
- ifdef(VERSION3){
- (v1 / v2/ v3). By default v1.
- * [-d] debug - Debug output.By default off.
- * [-c] <community> - community String. By default "public".
- * [-p] <port> - remote port no. By default 161.
- * [-r] <Retries> - Retries. By default 0.
- * [-t] <Timeout> - Timeout. By default 5000ms.
- * [-u] <username> - The v3 principal/userName
- * [-a] <autProtocol> - The authProtocol(MD5/SHA). Mandatory if authPassword is specified
- * [-w] <authPassword> - The authentication password.
- * [-s] <privPassword> - The privacy protocol password. Must be accompanied with auth password and authProtocol fields.
- * [-n] <contextName> - The snmpv3 contextName to be used.
- * [-i] <contextID> - The snmpv3 contextID to be used.
- * host Mandatory - The RemoteHost (agent).Format (string without double qoutes/IpAddress).
- * tableOID Mandatory - Give the Object Identifier of a Table.
- * mibs Mandatory - The mibs to be loaded.
- **/
- import javax.swing.*;
- import javax.swing.table.*;
- import java.awt.*;
- import java.awt.event.*;
- import com.adventnet.snmp.beans.*;
- import com.adventnet.snmp.ui.*;
- public class tableBeanDemo extends JFrame {
- private static final int VERSION = 0;
- private static final int COMMUNITY = 1;
- private static final int PORT = 2;
- private static final int RETRIES = 3;
- private static final int TIMEOUT = 4;
- private static final int DEBUG = 5;
- private static final int USER_NAME = 6;
- private static final int AUTH_PROTOCOL = 7;
- private static final int AUTH_PASSWORD = 8;
- private static final int PRIV_PASSWORD = 9;
- private static final int CONTEXTNAME = 10;
- private static final int CONTEXTID = 11;
- /** Supply command line arguments to this constructor **/
- public tableBeanDemo(String host, String community, String mibs,
- String tableOID, int port, int retries, int timeout, String debug) {
-
- this("v1", host, community, mibs, tableOID, port, retries, timeout, debug, "", "", "", "","","");
- } /* tableBeanDemo */
-
- /** Supply command line arguments to this constructor **/
- public tableBeanDemo(String version, String host, String community, String mibs, String tableOID, int port, int retries,int timeout, String debug, String userName, String authProtocol, String authPassword, String privPassword,String contextName,String contextID) {
-
- super("MainWindow");
- TableBean tableBean = new TableBean();
- // set the properties fo the table model
-
- tableBean.setTargetHost (host);
- tableBean.setCommunity (community);
- tableBean.setTargetPort (port);
- tableBean.setRetries (retries);
- tableBean.setTimeout (timeout);
- if(debug.equals("set"))
- tableBean.setDebug(true);
- tableBean.setAutoResizeMode(0);
- tableBean.sizeColumnsToFit(-1);
- if(version.equals("v3"))
- tableBean.setSnmpVersion(SnmpTarget.VERSION3);
- else if(version.equals("v2"))
- tableBean.setSnmpVersion(SnmpTarget.VERSION2C);
- else tableBean.setSnmpVersion(SnmpTarget.VERSION1);
- if(version.equals("v3")){
- tableBean.setPrincipal(userName);
- if(authProtocol.compareTo("MD5") == 0)
- tableBean.setAuthProtocol(SnmpTarget.MD5_AUTH);
- else if(authProtocol.compareTo("SHA") == 0)
- tableBean.setAuthProtocol(SnmpTarget.SHA_AUTH);
- else tableBean.setAuthProtocol(SnmpTarget.NO_AUTH);
- tableBean.setAuthPassword(authPassword);
- tableBean.setPrivPassword(privPassword);
- tableBean.setContextName(contextName);
- tableBean.setContextID(contextID);
- }
- try {
- System.out.println("Loading MIBs: "+mibs);
- tableBean.setMibModules(mibs);
- System.out.println("Done.");
- if(tableBean.getSnmpVersion() == SnmpTarget.VERSION3){
- tableBean.create_v3_tables();
- }
- tableBean.setTableOID (tableOID);
- } catch (Exception ex) {
- System.err.println("Error: "+ex);
- System.exit(1);
- }
- JScrollPane scrollpane = new JScrollPane(tableBean);
- getContentPane().add(scrollpane);
- } /* tableBeanDemo */
- public static void main(String[] args) {
- // Take care of getting options
- String usage = "tableBeanDemo [-v version(v1/v2/v3)] [-c community] [-p port] [-r retries] [-t timeout] [-d] [-u userName] [-a authProtocol] [-w authPassword] [-s privPassword] [-n contextname] [-i contextID] host tableOID MIB_file ";
- String options[] = { "-v", "-c", "-p", "-r", "-t", "-d", "-u", "-a", "-w", "-s","-n","-i" };
- String values[] = { null, null, null, null, null, "None", null, null, null, null, null,null};
- ParseOptions opt = new ParseOptions(args,options,values, usage);
- // check for at least hostname and one OID in remaining arguments
- if (opt.remArgs.length<3) opt.usage_error();
- String host = opt.remArgs[0];
- String oidTable = opt.remArgs[1];
- String community = "public";
- String mibs = opt.remArgs[2];
- String debug = new String("");
- String version ="v1";
- String userName = "";
- String authProtocol = new String("NO_AUTH");
- String authPassword = new String ("");
- String privPassword = new String ("");
- String contextName = new String ("");
- String contextID = new String ("");
- if (values[COMMUNITY] != null) community = values[COMMUNITY];
-
- if(values[DEBUG].equals("Set"))
- debug="set";
- int port = 161, retries=0,timeout = 5000;
- try {
- if (values[PORT] != null)
- port = ( Integer.parseInt(values[PORT]) );
- if (values[RETRIES] != null)
- retries = ( Integer.parseInt(values[RETRIES]) );
- if (values[TIMEOUT] != null)
- timeout = ( Integer.parseInt(values[TIMEOUT]) );
- } catch (NumberFormatException ex) {
- System.err.println("Invalid Integer Argument "+ex);
- }
- if(values[VERSION] != null)
- version = values[VERSION];
- if(values[USER_NAME] != null)
- userName = values[USER_NAME];
- if(values[AUTH_PROTOCOL] != null)
- authProtocol = values[AUTH_PROTOCOL];
- if(values[AUTH_PASSWORD] != null)
- authPassword = values[AUTH_PASSWORD];
- if(values[PRIV_PASSWORD] != null)
- privPassword = values[PRIV_PASSWORD];
- if(values[CONTEXTNAME] != null)
- contextName = values[CONTEXTNAME];
- if(values[CONTEXTID] != null)
- contextID = values[CONTEXTID];
- try { //setup the look and feel for native platform L&F
- UIManager.setLookAndFeel(
- UIManager.getSystemLookAndFeelClassName());
- } catch (Exception e) {
- System.err.println("Couldn't use the system "
- + "look and feel: " + e);
- }
- JFrame frame = new tableBeanDemo(version, host, community, mibs, oidTable, port, retries, timeout,debug,
- userName, authProtocol, authPassword, privPassword,contextName,contextID);
- WindowListener l = new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- };
- frame.addWindowListener(l);
- frame.setSize(600,300);
- frame.setVisible(true);
- }
- }