Commit 1f4cf0db authored by Matt Tucker's avatar Matt Tucker Committed by matt

Adding PicoContainer.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@4502 b35dd754-fafc-0310-a699-88a17e54d16e
parent 5144b608
Name | Version Name | Version
--------------------------------------------- ---------------------------------------------
joscar.jar | 0.9.3 (patched) joscar.jar | 0.9.3 (patched)
ymsg_network.jar | 0.61 picocontainer | 1.2.0
ymsg_network.jar | 0.61
\ No newline at end of file
...@@ -16,6 +16,8 @@ import org.jivesoftware.wildfire.container.PluginManager; ...@@ -16,6 +16,8 @@ import org.jivesoftware.wildfire.container.PluginManager;
import org.jivesoftware.wildfire.gateway.util.GatewayInstance; import org.jivesoftware.wildfire.gateway.util.GatewayInstance;
import org.xmpp.component.ComponentManager; import org.xmpp.component.ComponentManager;
import org.xmpp.component.ComponentManagerFactory; import org.xmpp.component.ComponentManagerFactory;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.defaults.DefaultPicoContainer;
import java.io.File; import java.io.File;
...@@ -29,6 +31,8 @@ import java.util.Hashtable; ...@@ -29,6 +31,8 @@ import java.util.Hashtable;
*/ */
public class GatewayPlugin implements Plugin { public class GatewayPlugin implements Plugin {
private MutablePicoContainer picoContainer;
/** /**
* Represents all configured gateway handlers. * Represents all configured gateway handlers.
*/ */
...@@ -39,10 +43,15 @@ public class GatewayPlugin implements Plugin { ...@@ -39,10 +43,15 @@ public class GatewayPlugin implements Plugin {
*/ */
private ComponentManager componentManager; private ComponentManager componentManager;
/** public GatewayPlugin() {
* Configures and starts the plugin. picoContainer = new DefaultPicoContainer();
*/
picoContainer.registerComponentImplementation(RegistrationManager.class);
}
public void initializePlugin(PluginManager manager, File pluginDirectory) { public void initializePlugin(PluginManager manager, File pluginDirectory) {
picoContainer.start();
gateways = new Hashtable<String,GatewayInstance>(); gateways = new Hashtable<String,GatewayInstance>();
componentManager = ComponentManagerFactory.getComponentManager(); componentManager = ComponentManagerFactory.getComponentManager();
...@@ -63,6 +72,25 @@ public class GatewayPlugin implements Plugin { ...@@ -63,6 +72,25 @@ public class GatewayPlugin implements Plugin {
maybeStartService("yahoo"); maybeStartService("yahoo");
} }
public void destroyPlugin() {
for (GatewayInstance gwInstance : gateways.values()) {
gwInstance.stopInstance();
}
picoContainer.stop();
picoContainer.dispose();
picoContainer = null;
}
/**
* Returns the instance of a module registered with the plugin.
*
* @param clazz the module class.
* @return the instance of the module.
*/
public Object getModule(Class clazz) {
return picoContainer.getComponentInstanceOfType(clazz);
}
/** /**
* Starts a gateway service, identified by subdomain. The gateway * Starts a gateway service, identified by subdomain. The gateway
* service will only start if it is enabled. * service will only start if it is enabled.
...@@ -98,14 +126,4 @@ public class GatewayPlugin implements Plugin { ...@@ -98,14 +126,4 @@ public class GatewayPlugin implements Plugin {
GatewayInstance gwInstance = gateways.get(serviceName); GatewayInstance gwInstance = gateways.get(serviceName);
return gwInstance.isEnabled(); return gwInstance.isEnabled();
} }
}
/** \ No newline at end of file
* Shuts down the plugin.
*/
public void destroyPlugin() {
for (GatewayInstance gwInstance : gateways.values()) {
gwInstance.stopInstance();
}
}
}
...@@ -14,6 +14,7 @@ import org.xmpp.packet.JID; ...@@ -14,6 +14,7 @@ import org.xmpp.packet.JID;
import org.jivesoftware.database.DbConnectionManager; import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.NotFoundException; import org.jivesoftware.util.NotFoundException;
import org.picocontainer.Startable;
import java.util.*; import java.util.*;
import java.sql.Connection; import java.sql.Connection;
...@@ -27,7 +28,7 @@ import java.sql.ResultSet; ...@@ -27,7 +28,7 @@ import java.sql.ResultSet;
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
public class RegistrationManager { public class RegistrationManager implements Startable {
private static final String DELETE_REGISTRATION = private static final String DELETE_REGISTRATION =
"DELETE FROM gatewayRegistration WHERE registrationID=?"; "DELETE FROM gatewayRegistration WHERE registrationID=?";
...@@ -45,6 +46,14 @@ public class RegistrationManager { ...@@ -45,6 +46,14 @@ public class RegistrationManager {
private static final String USER_GATEWAY_REGISTRATIONS = private static final String USER_GATEWAY_REGISTRATIONS =
"SELECT registrationID FROM gatewayRegistration WHERE jid=? AND gatewayType=?"; "SELECT registrationID FROM gatewayRegistration WHERE jid=? AND gatewayType=?";
public void start() {
}
public void stop() {
}
/** /**
* Creates a new registration. * Creates a new registration.
* *
...@@ -89,7 +98,7 @@ public class RegistrationManager { ...@@ -89,7 +98,7 @@ public class RegistrationManager {
* @param gatewayType the gateway type. * @param gatewayType the gateway type.
* @return all registrations for the gateway type. * @return all registrations for the gateway type.
*/ */
Collection<Registration> getRegistrations(GatewayType gatewayType) { public Collection<Registration> getRegistrations(GatewayType gatewayType) {
List<Long> registrationIDs = new ArrayList<Long>(); List<Long> registrationIDs = new ArrayList<Long>();
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
...@@ -123,7 +132,7 @@ public class RegistrationManager { ...@@ -123,7 +132,7 @@ public class RegistrationManager {
* @param jid the JID of the user. * @param jid the JID of the user.
* @return all registrations for the JID. * @return all registrations for the JID.
*/ */
Collection<Registration> getRegistrations(JID jid) { public Collection<Registration> getRegistrations(JID jid) {
List<Long> registrationIDs = new ArrayList<Long>(); List<Long> registrationIDs = new ArrayList<Long>();
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
...@@ -163,7 +172,7 @@ public class RegistrationManager { ...@@ -163,7 +172,7 @@ public class RegistrationManager {
* @param gatewayType the type of the gateway. * @param gatewayType the type of the gateway.
* @return all registrations for the JID of a particular gateway type. * @return all registrations for the JID of a particular gateway type.
*/ */
Collection<Registration> getRegistrations(JID jid, GatewayType gatewayType) { public Collection<Registration> getRegistrations(JID jid, GatewayType gatewayType) {
List<Long> registrationIDs = new ArrayList<Long>(); List<Long> registrationIDs = new ArrayList<Long>();
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
...@@ -193,7 +202,16 @@ public class RegistrationManager { ...@@ -193,7 +202,16 @@ public class RegistrationManager {
} }
} }
Registration getRegistration(JID jid, GatewayType gatewayType, String username) /**
* Returns a registration given a JID, gateway type, and username.
*
* @param jid the JID of the user.
* @param gatewayType the gateway type.
* @param username the username on the gateway service.
* @return the registration.
* @throws NotFoundException if the registration could not be found.
*/
public Registration getRegistration(JID jid, GatewayType gatewayType, String username)
throws NotFoundException throws NotFoundException
{ {
long registrationID = -1; long registrationID = -1;
......
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