[Mc4j-cvs] mc4j/src/org/mc4j/console/dashboard DashboardManager.java,NONE,1.1
Brought to you by:
ghinkl
From: Greg H. <gh...@us...> - 2004-04-07 03:06:04
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/dashboard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15080/src/org/mc4j/console/dashboard Added Files: DashboardManager.java Log Message: Dashboard manager moved into the dashboard package where it belongs. --- NEW FILE: DashboardManager.java --- /* * Author: Greg Hinkle * * The contents of this file are subject to the Sapient Public License Version 1.0 (the "License"); * you may not use this file except in compliance with the License. You may obtain a copy of the * License at http://mc4j.sf.net/License-SPL.html. * * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, * either express or implied. See the License for the specific language governing rights and limitations * under the License. * * The Original Code is The MC4J Management Console * The Initial Developer of the Original Code is Greg Hinkle (gh...@us...) * Copyright (C) 2004 Greg Hinkle. All Rights Reserved. * * Redistributions of code or binary files using or based on this code must reproduce the * above copyright and disclaimer. For more information see <http://mc4j.sourceforge.net>. */ package org.mc4j.console.dashboard; import java.io.File; import java.io.FileFilter; import java.io.FilenameFilter; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.TreeSet; import org.openide.awt.StatusDisplayer; import org.openide.modules.InstalledFileLocator; import org.openide.windows.IOProvider; import org.mc4j.console.bean.MBeanNode; import org.mc4j.console.util.ExceptionUtility; /** * This static-singleton manages the set of dashboards for found by the MC4J * application. It provides lists of dashboard matches and launches new dashboards. * * @author Greg Hinkle (gh...@us...), November 2002 * @version $Revision: 1.1 $($Author: ghinkl $ / $Date: 2004/04/07 02:53:04 $) */ public class DashboardManager { private Set dashboardDocuments = new TreeSet(); private static DashboardManager INSTANCE = new DashboardManager(); private DashboardManager() { initialize(); } public static DashboardManager getInstance() { return DashboardManager.INSTANCE; } public Set getDashboards() { return dashboardDocuments; } /** * Retrieves the set of dashboards appropriate for a particular bean * @param mBeanNode * @return */ public Set getDashboards(MBeanNode mBeanNode) { Set results = new TreeSet(); Iterator dashboardIterator = this.dashboardDocuments.iterator(); while (dashboardIterator.hasNext()) { Dashboard dashboard = (Dashboard) dashboardIterator.next(); if (dashboard.matches(mBeanNode)) { results.add(dashboard); } } return results; } public final void initialize() { //File dashboardDir = new File("./dashboards"); String oldStatus = StatusDisplayer.getDefault().getStatusText(); StatusDisplayer.getDefault().setStatusText("Loading dashboards..."); IOProvider.getDefault().getIO("Dashboard debugging",false).getOut(). println("Parsing all dashboards"); this.dashboardDocuments = new HashSet(); File[] dashboardFiles = getDashboardFiles(); for (int i = 0; i < dashboardFiles.length; i++) { try { IOProvider.getDefault().getIO("Dashboard debugging",false).getOut(). println("Parsing dashboard: " + dashboardFiles[i].getName()); Dashboard dashboard = DashboardLoader.getInstance().buildDashboard(dashboardFiles[i]); this.dashboardDocuments.add(dashboard); } catch (Exception e) { System.out.println(ExceptionUtility.printStackTracesToString(e)); } } StatusDisplayer.getDefault().setStatusText(oldStatus); } private File[] getDashboardFiles() { List fileList = new ArrayList(); File dashboardDir = InstalledFileLocator.getDefault().locate("dashboards","org.mc4j.console",false); if (dashboardDir.exists() && dashboardDir.isDirectory()) { addDashboardFiles(dashboardDir, fileList); } return (File[]) fileList.toArray(new File[fileList.size()]); } private void addDashboardFiles(File directory, List fileList) { File[] directories = directory.listFiles( new FileFilter() { public boolean accept(File theFile) { return theFile.isDirectory(); } }); for (int i = 0; i < directories.length; i++) { File childDirectory = directories[i]; addDashboardFiles(childDirectory, fileList); } File[] dashboardFiles = directory.listFiles( new FilenameFilter() { public boolean accept(File dir, String name) { return (name.endsWith(".xml")); } }); for (int i = 0; i < dashboardFiles.length; i++) { File dashboardFile = dashboardFiles[i]; fileList.add(dashboardFile); } } } |