01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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;
22:
23: import javax.swing.ImageIcon;
24:
25: import org.apache.jmeter.gui.GUIFactory;
26: import org.apache.jorphan.logging.LoggingManager;
27: import org.apache.log.Logger;
28:
29: /**
30: * @author Oliver Rossmueller
31: * @version $Revision: 493779 $
32: */
33: public final class PluginManager {
34: private static final PluginManager instance = new PluginManager();
35:
36: private static final Logger log = LoggingManager
37: .getLoggerForClass();
38:
39: private PluginManager() {
40: }
41:
42: /**
43: * Installs a plugin.
44: *
45: * @param plugin
46: * the plugin to install
47: * @param useGui
48: * indication of whether or not the gui will be used
49: */
50: public static void install(JMeterPlugin plugin, boolean useGui) {
51: if (useGui) {
52: instance.installPlugin(plugin);
53: }
54: }
55:
56: private void installPlugin(JMeterPlugin plugin) {
57: String[][] icons = plugin.getIconMappings();
58: ClassLoader classloader = plugin.getClass().getClassLoader();
59:
60: for (int i = 0; i < icons.length; i++) {
61: URL resource = classloader.getResource(icons[i][1].trim());
62:
63: if (resource == null) {
64: log.warn("Can't find icon for " + icons[i][0] + " - "
65: + icons[i][1]);
66: } else {
67: GUIFactory.registerIcon(icons[i][0], new ImageIcon(
68: resource));
69: if (icons[i].length > 2 && icons[i][2] != null) {
70: URL resource2 = classloader.getResource(icons[i][2]
71: .trim());
72: if (resource2 == null) {
73: log.info("Can't find disabled icon for "
74: + icons[i][0] + " - " + icons[i][2]);
75: } else {
76: GUIFactory.registerDisabledIcon(icons[i][0],
77: new ImageIcon(resource2));
78: }
79: }
80: }
81: }
82: }
83: }
|