KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > plugin > PluginManager


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/plugin/PluginManager.java,v 1.7 2004/02/13 02:40:54 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.plugin;
20
21 import java.net.URL JavaDoc;
22
23 import javax.swing.ImageIcon JavaDoc;
24
25 import org.apache.jmeter.gui.GUIFactory;
26
27 /**
28  * @author Oliver Rossmueller
29  * @version $Revision: 1.7 $
30  */

31 public final class PluginManager
32 {
33     private static final PluginManager instance = new PluginManager();
34
35     private PluginManager()
36     {
37     }
38
39     /**
40      * Installs a plugin.
41      * @param plugin the plugin to install
42      * @param useGui indication of whether or not the gui will be used
43      */

44     public static void install(JMeterPlugin plugin, boolean useGui)
45     {
46         if (useGui)
47         {
48             instance.installPlugin(plugin);
49         }
50     }
51
52     private void installPlugin(JMeterPlugin plugin)
53     {
54         String JavaDoc[][] icons = plugin.getIconMappings();
55         ClassLoader JavaDoc classloader = plugin.getClass().getClassLoader();
56
57         for (int i = 0; i < icons.length; i++)
58         {
59             URL JavaDoc resource = classloader.getResource(icons[i][1].trim());
60
61             if (resource == null)
62             {
63                 // todo: log or throw exception
64
}
65             else
66             {
67                 GUIFactory.registerIcon(icons[i][0], new ImageIcon JavaDoc(resource));
68             }
69         }
70     }
71 }
72
Popular Tags