List of usage examples for org.apache.commons.digester.plugins PluginConfigurationException PluginConfigurationException
public PluginConfigurationException(String msg)
From source file:de.knurt.fam.plugin.DefaultPluginResolver.java
private void initPlugins() { File pluginDirectory = new File(FamConnector.me().getPluginDirectory()); if (pluginDirectory.exists() && pluginDirectory.isDirectory() && pluginDirectory.canRead()) { File[] files = pluginDirectory.listFiles(); ClassLoader currentThreadClassLoader = Thread.currentThread().getContextClassLoader(); for (File file : files) { if (file.isFile() && file.getName().toLowerCase().endsWith("jar")) { JarFile jar = null; try { jar = new JarFile(file.getAbsoluteFile().toString()); Enumeration<JarEntry> jarEntries = jar.entries(); while (jarEntries.hasMoreElements()) { JarEntry entry = jarEntries.nextElement(); if (entry.getName().toLowerCase().endsWith("class")) { String className = entry.getName().replaceAll("/", ".").replaceAll("\\.class$", ""); // @SuppressWarnings("resource") // classLoader must not be closed, getting an "IllegalStateException: zip file closed" otherwise URLClassLoader classLoader = new URLClassLoader(new URL[] { file.toURI().toURL() }, currentThreadClassLoader); Class<?> cl = classLoader.loadClass(className); if (this.isPlugin(cl)) { Plugin plugin = (Plugin) cl.newInstance(); this.plugins.add(plugin); }//from w ww .j a v a 2 s . c om } } } catch (IllegalAccessException e) { e.printStackTrace(); FamLog.logException(this.getClass(), e, "failed to load plugin", 201010091426l); } catch (InstantiationException e) { e.printStackTrace(); FamLog.logException(this.getClass(), e, "failed to load plugin", 201010091424l); } catch (ClassNotFoundException e) { e.printStackTrace(); FamLog.logException(this.getClass(), e, "failed to load plugin", 201010091425l); } catch (IOException e) { e.printStackTrace(); FamLog.logException(this.getClass(), e, "failed to load plugin", 201010091351l); } finally { try { jar.close(); } catch (Exception e) { } } } } for (Plugin plugin : this.plugins) { boolean found = false; if (this.implementz(plugin.getClass(), RegisterSubmission.class)) { if (found == true) { throw new PluginConfigurationException("Found more than one RegisterSubmission classes"); // TODO #19 supply a solution Ticket } this.registerSubmission = (RegisterSubmission) plugin; found = true; } } for (Plugin plugin : this.plugins) { plugin.start(); } } // search plugin if (this.registerSubmission == null) { this.registerSubmission = new DefaultRegisterSubmission(); } }