MibBrowserApplet.java
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:7k
- /* $Id: MibBrowserApplet.src,v 1.11 2002/09/09 06:20:48 tonyjpaul Exp $ */
- /**
- * MibBrowser.java
- * Copyright (c) 1996-2002 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 java.awt.event.*;
- import com.adventnet.snmp.ui.*;
- import com.adventnet.snmp.beans.*;
- import com.adventnet.snmp.snmp2.*;
- import com.adventnet.utils.*;
- import java.util.StringTokenizer;
- import com.sun.jimi.core.component.JimiCanvas;
- import java.awt.Font;
- import java.util.StringTokenizer;
- import java.util.Locale;
- /** 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;
- JFrame f=null;
- public void init() {
- try {
- UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName());
- }catch (Exception e) {
- System.err.println(SnmpUtils.getString("Couldn't use the system look and feel:")+" "+ e);
- }
- //if (getParameter("PROTOCOL") != null)
- // SASClient.setProtocol(Integer.parseInt(getParameter("PROTOCOL")));
- if (getParameter("INTERNATIONALIZE") != null) {
- if(getParameter("INTERNATIONALIZE").equals("true")) {
- String locale = null;
- String font = null;
- String searchPath = null ;
- if (getParameter("LOCALE") != null)
- locale = getParameter("LOCALE");
- if (getParameter("FONT") != null)
- font = getParameter("FONT");
- if (getParameter("SEARCHPATH") != null)
- searchPath = getParameter("SEARCHPATH");
-
- if(locale == null || font == null)
- {
- System.out.println(SnmpUtils.getString("Please enter the Locale and Font for Internationalization"));
- System.out.println(SnmpUtils.getString("Continuing without Internationalizing"));
- //System.exit(1);
- }else
- {
- while(true)
- {
- StringTokenizer strt=new StringTokenizer(locale," ");
- if(strt.countTokens() != 2)
- {
- System.out.println(SnmpUtils.getString("Enter the Language and Country name for Locale"));
- System.out.println(SnmpUtils.getString("Continuing without Internationalizing"));
- break ;//System.exit(1);
- }
- Locale loc = new Locale((String)strt.nextToken(),(String)strt.nextToken());
- strt=new StringTokenizer(font," ");
- if(strt.countTokens() != 3)
- {
- System.out.println(SnmpUtils.getString("Enter the Font name, Style and Size for the font"));
- System.out.println(SnmpUtils.getString("Continuing without Internationalizing"));
- break ;//System.exit(1);
- }
-
- if(searchPath != null)
- SnmpUtils.setSearchPath(searchPath);
- try{
- Font f=new Font((String)strt.nextToken(), Integer.parseInt((String)strt.nextToken()),Integer.parseInt((String)strt.nextToken()));
- mbrowser.internationalize(loc,f);
- break ;
- }catch(Exception execpt){
- System.out.println(SnmpUtils.getString("Exception during Internationalizing")+" "+execpt);
- execpt.printStackTrace();
- System.out.println(SnmpUtils.getString("Continuing without Internationalizing"));
- break ;
- //System.exit(1);
- }
- }
- }
- }
- }
- /** instantiate the MibBrowser class */
- mbrowser = new MibBrowser(this);
-
- try {
- mbrowser.initSecurityProvider();
- }
- catch(SnmpException se) {
- System.err.println(SnmpUtils.getString("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"));
- /** 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(SnmpUtils.getString("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(SnmpUtils.getString("Error in Database Params :")+" "+ex);
- }
- mbrowser.setLoadMibsFromDatabase(true);
- }
- }
- }catch(Exception e)
- {
- System.out.println(SnmpUtils.getString("Error during setting Database Params: ")+" "+e);
- }
- f = new JFrame(SnmpUtils.getString("AdventNet MibBrowser"));
- WindowListener l=new WindowAdapter(){
- public void windowClosing(WindowEvent e){
- mbrowser.releaseResources();
- }
- };
- f.addWindowListener(l);
- JimiCanvas canvas = new JimiCanvas();
- canvas.setImageLocation(getClass().getResource("logo.png"));
- f.setIconImage(canvas.getImage());
- 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(SnmpUtils.getString("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);
- }
- public void destroy(){
- super.destroy();
- mbrowser.releaseResources();
- f.dispose();
- }
- }