Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.plugin » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  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;
   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   public final class PluginManager {
   30       private static final PluginManager instance = new PluginManager();
   31   
   32       private static final Logger log = LoggingManager.getLoggerForClass();
   33   
   34       private PluginManager() {
   35       }
   36   
   37       /**
   38        * Installs a plugin.
   39        *
   40        * @param plugin
   41        *            the plugin to install
   42        * @param useGui
   43        *            indication of whether or not the gui will be used
   44        */
   45       public static void install(JMeterPlugin plugin, boolean useGui) {
   46           if (useGui) {
   47               instance.installPlugin(plugin);
   48           }
   49       }
   50   
   51       private void installPlugin(JMeterPlugin plugin) {
   52           String[][] icons = plugin.getIconMappings();
   53           ClassLoader classloader = plugin.getClass().getClassLoader();
   54   
   55           for (int i = 0; i < icons.length; i++) {
   56               URL resource = classloader.getResource(icons[i][1].trim());
   57   
   58               if (resource == null) {
   59                   log.warn("Can't find icon for " + icons[i][0] + " - " + icons[i][1]);
   60               } else {
   61                   GUIFactory.registerIcon(icons[i][0], new ImageIcon(resource));
   62                   if (icons[i].length > 2 && icons[i][2] != null) {
   63                       URL resource2 = classloader.getResource(icons[i][2].trim());
   64                       if (resource2 == null) {
   65                           log.info("Can't find disabled icon for " + icons[i][0] + " - " + icons[i][2]);
   66                       } else {
   67                           GUIFactory.registerDisabledIcon(icons[i][0], new ImageIcon(resource2));
   68                       }
   69                   }
   70               }
   71           }
   72       }
   73   }

Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.plugin » [javadoc | source]