⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pluginrepository.java

📁 nutch0.8源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
          if (LOG.isWarnEnabled()) { LOG.warn(mde.getMessage()); }        } catch (CircularDependencyException cde) {          // Simply ignore this plugin          if (LOG.isWarnEnabled()) { LOG.warn(cde.getMessage()); }        }      }      return new ArrayList(checked.values());    }    /**     * Returns all registed plugin descriptors.     *      * @return PluginDescriptor[]     */    public PluginDescriptor[] getPluginDescriptors() {        return (PluginDescriptor[]) fRegisteredPlugins                .toArray(new PluginDescriptor[fRegisteredPlugins.size()]);    }    /**     * Returns the descriptor of one plugin identified by a plugin id.     *      * @param pPluginId     * @return PluginDescriptor     */    public PluginDescriptor getPluginDescriptor(String pPluginId) {        for (int i = 0; i < fRegisteredPlugins.size(); i++) {            PluginDescriptor descriptor = (PluginDescriptor) fRegisteredPlugins                    .get(i);            if (descriptor.getPluginId().equals(pPluginId))                return descriptor;        }        return null;    }    /**     * Returns a extension point indentified by a extension point id.     *      * @param pXpId     * @return a extentsion point     */    public ExtensionPoint getExtensionPoint(String pXpId) {        return (ExtensionPoint) this.fExtensionPoints.get(pXpId);    }    /**     * Returns a instance of a plugin. Plugin instances are cached. So a plugin     * exist only as one instance. This allow a central management of plugin own     * resources.     *      * After creating the plugin instance the startUp() method is invoked. The     * plugin use a own classloader that is used as well by all instance of     * extensions of the same plugin. This class loader use all exported     * libraries from the dependend plugins and all plugin libraries.     *      * @param pDescriptor     * @return Plugin     * @throws PluginRuntimeException     */    public Plugin getPluginInstance(PluginDescriptor pDescriptor)            throws PluginRuntimeException {        if (fActivatedPlugins.containsKey(pDescriptor.getPluginId()))            return (Plugin) fActivatedPlugins.get(pDescriptor.getPluginId());        try {            // Must synchronize here to make sure creation and initialization            // of a plugin instance are done by one and only one thread.            // The same is in Extension.getExtensionInstance().            // Suggested by Stefan Groschupf <sg@media-style.com>            synchronized (pDescriptor) {                PluginClassLoader loader = pDescriptor.getClassLoader();                Class pluginClass = loader.loadClass(pDescriptor                        .getPluginClass());                Constructor constructor = pluginClass                        .getConstructor(new Class[] { PluginDescriptor.class, Configuration.class });                Plugin plugin = (Plugin) constructor                        .newInstance(new Object[] { pDescriptor, this.conf });                plugin.startUp();                fActivatedPlugins.put(pDescriptor.getPluginId(), plugin);                return plugin;            }        } catch (ClassNotFoundException e) {            throw new PluginRuntimeException(e);        } catch (InstantiationException e) {            throw new PluginRuntimeException(e);        } catch (IllegalAccessException e) {            throw new PluginRuntimeException(e);        } catch (NoSuchMethodException e) {            throw new PluginRuntimeException(e);        } catch (InvocationTargetException e) {            throw new PluginRuntimeException(e);        }    }    /*     * (non-Javadoc)     *      * @see java.lang.Object#finalize()     */    public void finalize() throws Throwable {        shotDownActivatedPlugins();    }    /**     * @throws PluginRuntimeException     */    private void shotDownActivatedPlugins() throws PluginRuntimeException {        Iterator iterator = fActivatedPlugins.keySet().iterator();        while (iterator.hasNext()) {            String pluginId = (String) iterator.next();            Plugin object = (Plugin) fActivatedPlugins.get(pluginId);            object.shutDown();        }    }        private void displayStatus() {      if (!LOG.isInfoEnabled()) { return; }            LOG.info("Plugin Auto-activation mode: [" + this.auto + "]");      LOG.info("Registered Plugins:");      if ((fRegisteredPlugins == null) || (fRegisteredPlugins.size() == 0)) {        LOG.info("\tNONE");      } else {        for (int i=0; i<fRegisteredPlugins.size(); i++) {          PluginDescriptor plugin = (PluginDescriptor) fRegisteredPlugins.get(i);          LOG.info("\t" + plugin.getName() + " (" + plugin.getPluginId() + ")");        }      }      LOG.info("Registered Extension-Points:");      if ((fExtensionPoints == null) || (fExtensionPoints.size() == 0)) {        LOG.info("\tNONE");      } else {        Iterator iter = fExtensionPoints.values().iterator();        while (iter.hasNext()) {          ExtensionPoint ep = (ExtensionPoint) iter.next();          LOG.info("\t" + ep.getName() + " (" + ep.getId() + ")");        }      }    }    /**     * Filters a list of plugins.     * The list of plugins is filtered regarding the configuration     * properties <code>plugin.excludes</code> and <code>plugin.includes</code>.     */    private Map filter(Pattern excludes, Pattern includes, Map plugins) {      Map map = new HashMap();      if (plugins == null) { return map; }      Iterator iter = plugins.values().iterator();      while (iter.hasNext()) {        PluginDescriptor plugin = (PluginDescriptor) iter.next();        if (plugin == null) { continue; }        String id = plugin.getPluginId();        if (id == null) { continue; }                if (!includes.matcher(id).matches()) {          if (LOG.isDebugEnabled()) { LOG.debug("not including: " + id); }          continue;        }        if (excludes.matcher(id).matches()) {          if (LOG.isDebugEnabled()) { LOG.debug("excluding: " + id); }          continue;        }        map.put(plugin.getPluginId(), plugin);      }      return map;    }    /**     * Loads all necessary dependencies for a selected plugin, and then     * runs one of the classes' main() method.     * @param args plugin ID (needs to be activated in the configuration), and     * the class name. The rest of arguments is passed to the main method of the     * selected class.     * @throws Exception     */    public static void main(String[] args) throws Exception {      if (args.length < 2) {        System.err.println("Usage: PluginRepository pluginId className [arg1 arg2 ...]");        return;      }      Configuration conf = NutchConfiguration.create();      PluginRepository repo = new PluginRepository(conf);      // args[0] - plugin ID      PluginDescriptor d = repo.getPluginDescriptor(args[0]);      if (d == null) {        System.err.println("Plugin '" + args[0] + "' not present or inactive.");        return;      }      ClassLoader cl = d.getClassLoader();      // args[1] - class name      Class clazz = null;      try {        clazz = Class.forName(args[1], true, cl);      } catch (Exception e) {        System.err.println("Could not load the class '" + args[1] + ": " + e.getMessage());        return;      }      Method m = null;      try {        m = clazz.getMethod("main", new Class[]{args.getClass()});      } catch (Exception e) {        System.err.println("Could not find the 'main(String[])' method in class " + args[1] + ": " + e.getMessage());        return;      }      String[] subargs = new String[args.length - 2];      System.arraycopy(args, 2, subargs, 0, subargs.length);      m.invoke(null, new Object[]{subargs});    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -