Commit 0685be33 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Attempted plugin fixes.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@474 b35dd754-fafc-0310-a699-88a17e54d16e
parent 2370055a
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
package org.jivesoftware.messenger.container; package org.jivesoftware.messenger.container;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.XMLProperties;
import org.jivesoftware.messenger.JiveGlobals; import org.jivesoftware.messenger.JiveGlobals;
import org.jivesoftware.admin.AdminConsole; import org.jivesoftware.admin.AdminConsole;
import org.dom4j.Document; import org.dom4j.Document;
...@@ -39,6 +38,7 @@ public class PluginManager { ...@@ -39,6 +38,7 @@ public class PluginManager {
private File pluginDirectory; private File pluginDirectory;
private Map<String,Plugin> plugins; private Map<String,Plugin> plugins;
private Map<Plugin,PluginClassLoader> classloaders;
private boolean setupMode = !(Boolean.valueOf(JiveGlobals.getXMLProperty("setup")).booleanValue()); private boolean setupMode = !(Boolean.valueOf(JiveGlobals.getXMLProperty("setup")).booleanValue());
private ScheduledExecutorService executor = null; private ScheduledExecutorService executor = null;
...@@ -50,6 +50,7 @@ public class PluginManager { ...@@ -50,6 +50,7 @@ public class PluginManager {
public PluginManager(File pluginDir) { public PluginManager(File pluginDir) {
this.pluginDirectory = pluginDir; this.pluginDirectory = pluginDir;
plugins = new HashMap<String,Plugin>(); plugins = new HashMap<String,Plugin>();
classloaders = new HashMap<Plugin,PluginClassLoader>();
} }
/** /**
...@@ -114,10 +115,11 @@ public class PluginManager { ...@@ -114,10 +115,11 @@ public class PluginManager {
plugin = (Plugin)pluginLoader.loadClass(className).newInstance(); plugin = (Plugin)pluginLoader.loadClass(className).newInstance();
plugin.initialize(this, pluginDir); plugin.initialize(this, pluginDir);
plugins.put(pluginDir.getName(), plugin); plugins.put(pluginDir.getName(), plugin);
classloaders.put(plugin, pluginLoader);
// Load any JSP's defined by the plugin. // Load any JSP's defined by the plugin.
File webXML = new File(pluginDir, "web" + File.separator + "web.xml"); File webXML = new File(pluginDir, "web" + File.separator + "web.xml");
if (webXML.exists()) { if (webXML.exists()) {
PluginServlet.registerServlets(plugin, webXML); PluginServlet.registerServlets(this, plugin, webXML);
} }
// If there a <adminconsole> section defined, register it. // If there a <adminconsole> section defined, register it.
Element adminElement = (Element)pluginXML.selectSingleNode("/plugin/adminconsole"); Element adminElement = (Element)pluginXML.selectSingleNode("/plugin/adminconsole");
...@@ -141,6 +143,13 @@ public class PluginManager { ...@@ -141,6 +143,13 @@ public class PluginManager {
} }
} }
public Class loadClass(String className, Plugin plugin) throws ClassNotFoundException,
IllegalAccessException, InstantiationException
{
PluginClassLoader loader = classloaders.get(plugin);
return loader.loadClass(className);
}
/** /**
* A service that monitors the plugin directory for plugins. It periodically * A service that monitors the plugin directory for plugins. It periodically
* checks for new plugin JAR files and extracts them if they haven't already * checks for new plugin JAR files and extracts them if they haven't already
......
...@@ -93,7 +93,7 @@ public class PluginServlet extends HttpServlet { ...@@ -93,7 +93,7 @@ public class PluginServlet extends HttpServlet {
* @param webXML the web.xml file containing JSP page names to servlet class file * @param webXML the web.xml file containing JSP page names to servlet class file
* mappings. * mappings.
*/ */
public static void registerServlets(Plugin plugin, File webXML) { public static void registerServlets(PluginManager manager, Plugin plugin, File webXML) {
if (!webXML.exists()) { if (!webXML.exists()) {
Log.error("Could not register plugin servlets, file " + webXML.getAbsolutePath() + Log.error("Could not register plugin servlets, file " + webXML.getAbsolutePath() +
" does not exist."); " does not exist.");
...@@ -112,7 +112,7 @@ public class PluginServlet extends HttpServlet { ...@@ -112,7 +112,7 @@ public class PluginServlet extends HttpServlet {
Element servletElement = (Element)classes.get(i); Element servletElement = (Element)classes.get(i);
String name = servletElement.element("servlet-name").getTextTrim(); String name = servletElement.element("servlet-name").getTextTrim();
String className = servletElement.element("servlet-class").getTextTrim(); String className = servletElement.element("servlet-class").getTextTrim();
classMap.put(name, plugin.getClass().getClassLoader().loadClass(className)); classMap.put(name, manager.loadClass(className, plugin));
} }
// Find all <servelt-mapping> entries to discover name to URL mapping. // Find all <servelt-mapping> entries to discover name to URL mapping.
List names = doc.selectNodes("//servlet-mapping"); List names = doc.selectNodes("//servlet-mapping");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment