MibBrowserApplet.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:4k
- /* $Id: MibBrowserApplet.java,v 1.1 2002/06/15 14:43:37 ram Exp $ */
- /**
- * MibBrowser.java
- * Copyright (c) 1998 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
-
- * ADVENTNET, INC. MAKES NO REPRESENTATIONS OR WARRANTIES
- * ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. ADVENTNET,
- * INC. SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
- * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE
- * OR ITS DERIVATIVES.
- */
- import javax.swing.*;
- import com.adventnet.snmp.ui.*;
- import com.adventnet.snmp.beans.*;
- import com.adventnet.snmp.snmp2.*;
- import java.util.StringTokenizer;
- /** This example of using MibBrowser class with JFC component
- * This enable you to load MIBs and you can perform all
- * SNMP operations in this applet .
- */
- public class MibBrowserApplet extends JApplet implements Runnable {
- MibBrowser mbrowser = null;
- public void init() {
- try {
- UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName());
- } catch (Exception e) {
- System.err.println("Couldn't use the system look and feel: "+ e);
- }
- //if (getParameter("PROTOCOL") != null)
- // SASClient.setProtocol(Integer.parseInt(getParameter("PROTOCOL")));
- /** instantiate the MibBrowser class */
- mbrowser = new MibBrowser(this);
- try {
- mbrowser.initSecurityProvider();
- }
- catch(SnmpException se) {
- System.err.println("Error initializing Security Provider: " +se.getMessage());
- }
- /**
- * MenuBar is an Option
- */
- mbrowser.setMenuBarVisible(true);
-
- /** get the Values for HOST ,COMMUNITY
- from HTML file */
- if (getParameter("HOST") != null)
- mbrowser.setTargetHost(getParameter("HOST"));
- if (getParameter("COMMUNITY") != null)
- mbrowser.setCommunity(getParameter("COMMUNITY"));
- if (getParameter("VERSION") != null)
- mbrowser.setSnmpVersion(Integer.parseInt(getParameter("VERSION")));
-
- /** get the Values for PORT, RETRIES and TIMEOUT
- from HTML file */
- try {
- if (getParameter("PORT") != null)
- mbrowser.setTargetPort(Integer.parseInt(getParameter("PORT")));
- if (getParameter("RETRIES") != null)
- mbrowser.setRetries(getParameter("RETRIES"));
- if (getParameter("TIMEOUT") != null)
- mbrowser.setTimeout(getParameter("TIMEOUT"));
- } catch (NumberFormatException ex) {
- System.err.println("Invalid option: "+ex);
- }
- /**get the Values for Database from html file*/
- try{
- if(getParameter("DATABASE") !=null)
- {
- StringTokenizer st = new StringTokenizer(getParameter("DATABASE"));
- if(st.countTokens()==4)
- {
- try{
- mbrowser.initJdbcParams(st.nextToken(),st.nextToken(),st.nextToken(),st.nextToken());
- }catch(Exception ex)
- {
- System.out.println("Error in Database Params :"+ex);
- }
- mbrowser.setLoadMibsFromDatabase(true);
- }
- }
- else
- mbrowser.setLoadFromCompiledMibs(true);
- }catch(Exception e)
- {
- System.out.println("Error during setting Database Params: "+e);
- }
- JFrame f = new JFrame("MibBrowser");
- f.getContentPane().add("Center",mbrowser);
- f.setSize(730,525);
- f.setVisible(true);
- }
- /** to avoid loading mibs multiple times */
- boolean started = false;
- public void start() {
- if (started) return;
- Thread t = new Thread(this);
- t.start();
- // set the flag to indicate that the MIBs have been loaded
- started = true;
- }
-
- // This double take to avoid swing problems
- boolean runOnce = false;
- public void run() {
- if (!runOnce) {
- runOnce = true;
- try {
- SwingUtilities.invokeAndWait(this);
- return;
- } catch (Exception ex) { System.err.println("Error: "+ex); }
- }
-
- /** get the MIBs value to be loaded from the HTML
- and Load those MIBs */
- if (getParameter("MIBS") != null)
- mbrowser.setMibModules(getParameter("MIBS"));
-
- /** After loading MIBs expand the Root node only */
- mbrowser.getMibTree().getTree().expandRow(0);
- }
-
- }