Commit b9b98fed authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[JM-761] Misc fixes.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@4508 b35dd754-fafc-0310-a699-88a17e54d16e
parent 87e55847
...@@ -47,20 +47,28 @@ public abstract class BaseTransport implements Component { ...@@ -47,20 +47,28 @@ public abstract class BaseTransport implements Component {
/** /**
* Create a new BaseTransport instance. * Create a new BaseTransport instance.
*/
public BaseTransport() {
// We've got nothing to do here.
}
/**
* Set up the transport instance.
* *
* @param jid JID associated with the transport.
* @param description Description of the transport (for Disco).
* @param type Type of the transport. * @param type Type of the transport.
* @param description Description of the transport (for Disco).
*/ */
public BaseTransport(JID jid, String description, TransportType type) { public void setup(TransportType type, String description) {
this.jid = jid;
this.description = description; this.description = description;
this.transportType = type; this.transportType = type;
} }
// TODO: Why do I need this? /**
public BaseTransport() { * Handles initialization of the transport.
// I don't understand why I need this. */
public void initialize(JID jid, ComponentManager componentManager) {
this.jid = jid;
this.componentManager = componentManager;
} }
/** /**
...@@ -451,13 +459,6 @@ public abstract class BaseTransport implements Component { ...@@ -451,13 +459,6 @@ public abstract class BaseTransport implements Component {
return new JID(username, this.jid.getDomain(), null); return new JID(username, this.jid.getDomain(), null);
} }
/**
* Handles initialization of the transport.
*/
public void initialize(JID jid, ComponentManager componentManager) {
this.componentManager = componentManager;
}
/** /**
* Handles startup of the transport. * Handles startup of the transport.
*/ */
......
...@@ -56,22 +56,18 @@ public class GatewayPlugin implements Plugin { ...@@ -56,22 +56,18 @@ public class GatewayPlugin implements Plugin {
picoContainer.start(); picoContainer.start();
transports = new Hashtable<String,TransportInstance>(); transports = new Hashtable<String,TransportInstance>();
componentManager = ComponentManagerFactory.getComponentManager(); componentManager = ComponentManagerFactory.getComponentManager();
/* Set up AIM transport. */ /* Set up AIM transport. */
transports.put("aim", new TransportInstance("aim", transports.put("aim", new TransportInstance(TransportType.aim, "AIM Transport", "org.jivesoftware.wildfire.gateway.protocols.oscar.OSCARGateway", componentManager));
"org.jivesoftware.wildfire.gateway.protocols.oscar.OSCARGateway", componentManager));
maybeStartService("aim"); maybeStartService("aim");
/* Set up ICQ transport. */ /* Set up ICQ transport. */
transports.put("icq", new TransportInstance("icq", transports.put("icq", new TransportInstance(TransportType.icq, "ICQ Transport", "org.jivesoftware.wildfire.gateway.protocols.oscar.OSCARGateway", componentManager));
"org.jivesoftware.wildfire.gateway.protocols.oscar.OSCARGateway", componentManager));
maybeStartService("icq"); maybeStartService("icq");
/* Set up Yahoo transport. */ /* Set up Yahoo transport. */
transports.put("yahoo", new TransportInstance("yahoo", transports.put("yahoo", new TransportInstance(TransportType.yahoo, "Yahoo! Transport", "org.jivesoftware.wildfire.gateway.protocols.yahoo.YahooGateway", componentManager));
"org.jivesoftware.wildfire.gateway.protocols.yahoo.YahooGateway", componentManager));
maybeStartService("yahoo"); maybeStartService("yahoo");
} }
......
...@@ -10,11 +10,12 @@ ...@@ -10,11 +10,12 @@
package org.jivesoftware.wildfire.gateway; package org.jivesoftware.wildfire.gateway;
import org.jivesoftware.util.Log;
import org.xmpp.component.ComponentManager;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.wildfire.gateway.BaseTransport; import org.jivesoftware.util.Log;
import org.jivesoftware.util.PropertyEventDispatcher; import org.jivesoftware.util.PropertyEventDispatcher;
import org.jivesoftware.wildfire.gateway.BaseTransport;
import org.xmpp.component.ComponentManager;
import org.xmpp.packet.JID;
/** /**
* Transport Instance * Transport Instance
...@@ -26,24 +27,29 @@ import org.jivesoftware.util.PropertyEventDispatcher; ...@@ -26,24 +27,29 @@ import org.jivesoftware.util.PropertyEventDispatcher;
public class TransportInstance { public class TransportInstance {
private ComponentManager componentManager; private ComponentManager componentManager;
private String serviceName = null; private JID jid = null;
private String description = null;
private String nameOfClass = null; private String nameOfClass = null;
private BaseTransport transport = null; private BaseTransport transport = null;
private TransportType type = null;
private Boolean enabled = false; private Boolean enabled = false;
private Boolean running = false; private Boolean running = false;
/** /**
* Creates a new transport instance. * Creates a new transport instance.
* *
* @param subdomain Part of transport domain prepended to server domain. * @param jid Full jabber id of the transport.
* @param description Short description of transport.
* @param type Type of transport.
* @param classname Full name/path of class associated with instance. * @param classname Full name/path of class associated with instance.
* @param componentManager Component manager managing this instance. * @param componentManager Component manager managing this instance.
*/ */
public TransportInstance(String subdomain, String classname, ComponentManager componentManager) { public TransportInstance(TransportType type, String description, String classname, ComponentManager componentManager) {
this.serviceName = subdomain; this.description = description;
this.type = type;
this.nameOfClass = classname; this.nameOfClass = classname;
this.componentManager = componentManager; this.componentManager = componentManager;
enabled = JiveGlobals.getBooleanProperty("plugin.gateway."+serviceName+"Enabled", false); enabled = JiveGlobals.getBooleanProperty("plugin.gateway."+this.type.toString()+"Enabled", false);
} }
/** /**
...@@ -52,7 +58,7 @@ public class TransportInstance { ...@@ -52,7 +58,7 @@ public class TransportInstance {
* @return name of the service * @return name of the service
*/ */
public String getName() { public String getName() {
return serviceName; return this.type.toString();
} }
/** /**
...@@ -78,7 +84,7 @@ public class TransportInstance { ...@@ -78,7 +84,7 @@ public class TransportInstance {
*/ */
public void enable() { public void enable() {
enabled = true; enabled = true;
JiveGlobals.setProperty("plugin.gateway."+serviceName+"Enabled", "true"); JiveGlobals.setProperty("plugin.gateway."+this.type.toString()+"Enabled", "true");
if (!running) { if (!running) {
startInstance(); startInstance();
} }
...@@ -89,7 +95,7 @@ public class TransportInstance { ...@@ -89,7 +95,7 @@ public class TransportInstance {
*/ */
public void disable() { public void disable() {
enabled = false; enabled = false;
JiveGlobals.setProperty("plugin.gateway."+serviceName+"Enabled", "false"); JiveGlobals.setProperty("plugin.gateway."+this.type.toString()+"Enabled", "false");
if (running) { if (running) {
stopInstance(); stopInstance();
} }
...@@ -109,6 +115,7 @@ public class TransportInstance { ...@@ -109,6 +115,7 @@ public class TransportInstance {
try { try {
transport = (BaseTransport)Class.forName(nameOfClass).newInstance(); transport = (BaseTransport)Class.forName(nameOfClass).newInstance();
transport.setup(this.type, this.description);
} }
catch (ClassNotFoundException e) { catch (ClassNotFoundException e) {
Log.error("Unable to find class: "+nameOfClass); Log.error("Unable to find class: "+nameOfClass);
...@@ -119,11 +126,9 @@ public class TransportInstance { ...@@ -119,11 +126,9 @@ public class TransportInstance {
catch (IllegalAccessException e) { catch (IllegalAccessException e) {
Log.error("Unable to access class: "+nameOfClass); Log.error("Unable to access class: "+nameOfClass);
} }
//transport.setName(serviceName);
//componentManager = ComponentManagerFactory.getComponentManager();
try { try {
componentManager.addComponent(serviceName, transport); componentManager.addComponent(this.type.toString(), transport);
//PropertyEventDispatcher.addListener(transport); //PropertyEventDispatcher.addListener(transport);
running = true; running = true;
} }
...@@ -142,8 +147,7 @@ public class TransportInstance { ...@@ -142,8 +147,7 @@ public class TransportInstance {
//PropertyEventDispatcher.removeListener(transport); //PropertyEventDispatcher.removeListener(transport);
try { try {
componentManager.removeComponent(serviceName); componentManager.removeComponent(this.type.toString());
//componentManager = null;
} }
catch (Exception e) { catch (Exception e) {
componentManager.getLog().error(e); componentManager.getLog().error(e);
......
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