Commit ebd6c472 authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

First functional version of Guice, inside PluginManager. Will now be working...

First functional version of Guice, inside PluginManager. Will now be working on making functionality more robust.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8587 b35dd754-fafc-0310-a699-88a17e54d16e
parent a7d40b6e
......@@ -453,6 +453,15 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/dist/guice.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntryProperties />
</component>
</module>
......
/**
* $Revision:$
* $Date:$
*
* Copyright (C) 2007 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.container;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import java.io.File;
import org.xmpp.component.ComponentManager;
/**
*
*/
public abstract class AbstractPlugin implements Plugin {
protected ComponentManager componentManager;
@Inject
public void setComponentManager(ComponentManager componentManager) {
this.componentManager = componentManager;
}
public void initializePlugin(PluginManager manager, File pluginDirectory) {
initializePlugin();
}
public abstract void initializePlugin();
public void destroyPlugin() {
}
}
......@@ -31,6 +31,9 @@ import java.util.jar.JarOutputStream;
import java.util.jar.Pack200;
import java.util.zip.ZipFile;
import com.google.inject.Guice;
import com.google.inject.AbstractModule;
/**
* Loads and manages plugins. The <tt>plugins</tt> directory is monitored for any
* new plugins, and they are dynamically loaded.<p/>
......@@ -372,7 +375,34 @@ public class PluginManager {
}
String className = pluginXML.selectSingleNode("/plugin/class").getText();
plugin = (Plugin)pluginLoader.loadClass(className).newInstance();
Class pluginClazz = pluginLoader.loadClass(className);
if(AbstractPlugin.class.isAssignableFrom(pluginClazz)) {
String moduleClassName;
try {
moduleClassName = pluginXML.selectSingleNode("/plugin/module/class")
.getText();
}
catch (NullPointerException npe) {
moduleClassName = null;
}
Class moduleClazz;
try {
if (moduleClassName != null) {
moduleClazz = pluginLoader.loadClass(moduleClassName);
}
else {
moduleClazz = null;
}
}
catch (ClassNotFoundException cnfe) {
moduleClazz = null;
}
//noinspection unchecked
plugin = instantiateAbstractPlugin(pluginLoader, pluginClazz, moduleClazz);
}
else {
plugin = (Plugin) pluginClazz.newInstance();
}
if (parentPluginNode != null) {
String parentPlugin = parentPluginNode.getTextTrim();
// See if the parent is already loaded.
......@@ -496,6 +526,36 @@ public class PluginManager {
}
}
private Plugin instantiateAbstractPlugin(PluginClassLoader pluginLoader,
final Class<? extends AbstractPlugin> pluginClazz,
Class<? extends com.google.inject.Module> moduleClazz)
throws IllegalAccessException, InstantiationException
{
// Init the plugin.
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(pluginLoader);
final PluginModule module = new PluginModule();
com.google.inject.Module tempModule;
if(moduleClazz == null) {
tempModule = null;
}
else {
tempModule = moduleClazz.newInstance();
}
final com.google.inject.Module pluginModule = tempModule;
AbstractPlugin plugin = Guice.createInjector(new AbstractModule() {
protected void configure() {
install(module);
if (pluginModule != null) {
install(pluginModule);
}
bind(pluginClazz);
}
}).getInstance(pluginClazz);
Thread.currentThread().setContextClassLoader(oldLoader);
return plugin;
}
private void firePluginCreatedEvent(String name, Plugin plugin) {
for(PluginListener listener : pluginListeners) {
listener.pluginCreated(name, plugin);
......
/**
* $Revision:$
* $Date:$
*
* Copyright (C) 2007 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.container;
import com.google.inject.*;
import org.jivesoftware.openfire.*;
import org.jivesoftware.openfire.session.RemoteSessionLocator;
import org.jivesoftware.openfire.vcard.VCardManager;
import org.jivesoftware.openfire.stun.STUNService;
import org.jivesoftware.openfire.mediaproxy.MediaProxyService;
import org.jivesoftware.openfire.filetransfer.proxy.FileTransferProxy;
import org.jivesoftware.openfire.filetransfer.FileTransferManager;
import org.jivesoftware.openfire.commands.AdHocCommandHandler;
import org.jivesoftware.openfire.muc.MultiUserChatServer;
import org.jivesoftware.openfire.disco.IQDiscoItemsHandler;
import org.jivesoftware.openfire.audit.AuditManager;
import org.jivesoftware.openfire.update.UpdateManager;
import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.pubsub.PubSubModule;
import org.jivesoftware.openfire.handler.IQRegisterHandler;
import org.jivesoftware.openfire.handler.IQAuthHandler;
import org.jivesoftware.openfire.handler.PresenceUpdateHandler;
import org.jivesoftware.openfire.handler.PresenceSubscribeHandler;
import org.jivesoftware.openfire.roster.RosterManager;
import org.xmpp.component.ComponentManager;
import org.xmpp.component.ComponentManagerFactory;
/**
*
*/
public class PluginModule extends AbstractModule {
protected void configure() {
XMPPServer server = XMPPServer.getInstance();
bind(XMPPServer.class).toInstance(server);
bind(ConnectionManager.class).toInstance(server.getConnectionManager());
bind(RoutingTable.class).toInstance(server.getRoutingTable());
bind(PacketDeliverer.class).toInstance(server.getPacketDeliverer());
bind(RosterManager.class).toInstance(server.getRosterManager());
bind(PresenceManager.class).toInstance(server.getPresenceManager());
bind(OfflineMessageStore.class).toInstance(server.getOfflineMessageStore());
bind(OfflineMessageStrategy.class).toInstance(server.getOfflineMessageStrategy());
bind(PacketRouter.class).toInstance(server.getPacketRouter());
bind(IQRegisterHandler.class).toInstance(server.getIQRegisterHandler());
bind(IQAuthHandler.class).toInstance(server.getIQAuthHandler());
bind(PluginManager.class).toInstance(server.getPluginManager());
bind(PubSubModule.class).toInstance(server.getPubSubModule());
bind(SessionManager.class).toInstance(server.getSessionManager());
bind(PresenceUpdateHandler.class).toInstance(server.getPresenceUpdateHandler());
bind(PresenceSubscribeHandler.class).toInstance(server.getPresenceSubscribeHandler());
bind(IQRouter.class).toInstance(server.getIQRouter());
bind(MessageRouter.class).toInstance(server.getMessageRouter());
bind(PresenceRouter.class).toInstance(server.getPresenceRouter());
bind(MulticastRouter.class).toInstance(server.getMulticastRouter());
bind(UserManager.class).toInstance(server.getUserManager());
bind(UpdateManager.class).toInstance(server.getUpdateManager());
bind(AuditManager.class).toInstance(server.getAuditManager());
bind(IQDiscoItemsHandler.class).toInstance(server.getIQDiscoItemsHandler());
bind(PrivateStorage.class).toInstance(server.getPrivateStorage());
bind(MultiUserChatServer.class).toInstance(server.getMultiUserChatServer());
bind(AdHocCommandHandler.class).toInstance(server.getAdHocCommandHandler());
bind(FileTransferProxy.class).toInstance(server.getFileTransferProxy());
bind(FileTransferManager.class).toInstance(server.getFileTransferManager());
bind(MediaProxyService.class).toInstance(server.getMediaProxyService());
bind(STUNService.class).toInstance(server.getSTUNService());
bind(VCardManager.class).toInstance(server.getVCardManager());
bind(RemoteSessionLocator.class).toProvider(new Provider<RemoteSessionLocator>() {
private XMPPServer xmppServer;
@Inject
public void setXMPPServer(XMPPServer xmppServer) {
this.xmppServer = xmppServer;
}
public RemoteSessionLocator get() {
return xmppServer.getRemoteSessionLocator();
}
});
bind(ComponentManager.class).toProvider(new Provider<ComponentManager>() {
public ComponentManager get() {
return ComponentManagerFactory.getComponentManager();
}
});
}
}
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