1 /*------------------------------------------------------------------------------
  2 Name:      ProtocolPluginManager.java
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 ------------------------------------------------------------------------------*/
  6 package org.xmlBlaster.client.protocol;
  7 
  8 import java.util.logging.Logger;
  9 import java.util.logging.Level;
 10 import org.xmlBlaster.util.plugin.PluginManagerBase;
 11 import org.xmlBlaster.util.plugin.PluginInfo;
 12 import org.xmlBlaster.util.plugin.I_Plugin;
 13 import org.xmlBlaster.util.Global;
 14 import org.xmlBlaster.util.XmlBlasterException;
 15 import org.xmlBlaster.client.protocol.I_XmlBlasterConnection;
 16 
 17 /**
 18  * ProtocolPluginManager loads the protocol plugins like CORBA/RMI/XmlRpc on client side
 19  * to access xmlBlaster. 
 20  * <p />
 21  * <pre>
 22  * A typical xmlBlaster.properties entry:
 23  *
 24  * ClientProtocolPlugin[IOR][1.0]=org.xmlBlaster.client.protocol.corba.CorbaConnection
 25  * </pre>
 26  * @author <a href="mailto:xmlBlaster@marcelruff.info">Marcel Ruff</a>.
 27  * @see <a href="http://www.xmlblaster.org/xmlBlaster/doc/requirements/protocol.html" target="others">protocol</a>
 28  */
 29 public class ProtocolPluginManager extends PluginManagerBase
 30 {
 31    private final String ME;
 32    private final Global glob;
 33    private static Logger log = Logger.getLogger(ProtocolPluginManager.class.getName());
 34    private static final String defaultPluginName = "org.xmlBlaster.client.protocol.corba.CorbaConnection";
 35    public static final String pluginPropertyName = "ClientProtocolPlugin";
 36 
 37    public ProtocolPluginManager(Global glob) {
 38       super(glob);
 39       this.glob = glob;
 40 
 41       this.ME = "ProtocolPluginManager" + this.glob.getLogPrefixDashed();
 42       if (log.isLoggable(Level.FINER)) log.finer("Constructor ProtocolPluginManager");
 43    }
 44 
 45    /**
 46     * Enforced by PluginManagerBase. 
 47     * @return The name of the property in xmlBlaster.property "LoadBalancerPlugin"
 48     * for "LoadBalancerPlugin[RoundRobin][1.0]"
 49     */
 50    protected String getPluginPropertyName() {
 51       return pluginPropertyName;
 52    }
 53 
 54    /**
 55     * @return please return your default plugin classname or null if not specified
 56     */
 57    public String getDefaultPluginName(String type, String version) {
 58       return defaultPluginName;
 59    }
 60 
 61    /**
 62     * Creates a new instance of the given protocol driver type. 
 63     * <p />
 64     * You need to call clientDriver.init(glob, address) on it.
 65     * @param driverType e.g. "RMI"
 66     * @return The uninitialized driver, never null
 67     * @exception XmlBlasterException on problems
 68     */
 69    public final I_XmlBlasterConnection getNewProtocolDriverInstance(String driverType) throws XmlBlasterException {
 70       return getPlugin(driverType, "1.0");
 71    }
 72 
 73    /**
 74     * Return a specific plugin, every call will create a new plugin instance. 
 75     * <p/>
 76     * @param String The type of the requested plugin.
 77     * @param String The version of the requested plugin.
 78     * @return The plugin for this type and version or null if none is specified
 79     */
 80    public I_XmlBlasterConnection getPlugin(String type, String version) throws XmlBlasterException {
 81       if (log.isLoggable(Level.FINER)) log.finer("Creating instance of " + createPluginPropertyKey(type, version));
 82 
 83       // We need a new instance every time! (no caching in base class)
 84       PluginInfo pluginInfo = new PluginInfo(glob, this, type, version);
 85       I_XmlBlasterConnection driver = (I_XmlBlasterConnection)super.instantiatePlugin(pluginInfo, false);
 86       if (driver == null) {
 87          log.warning("Creating instance of " + createPluginPropertyKey(type, version) + " failed, no such plugin found.");
 88       }
 89       return driver;
 90    }
 91 
 92    public void postInstantiate(I_Plugin plugin, PluginInfo pluginInfo) {}
 93 
 94    public void activateDrivers() throws XmlBlasterException {
 95       if (log.isLoggable(Level.FINE)) log.fine("Don't know how to activate the protocol drivers, they are created for each client and session separately");
 96    }
 97 
 98    public final void deactivateDrivers(boolean force) {
 99       if (log.isLoggable(Level.FINE)) log.fine("Don't know how to deactivate the protocol drivers, they are created for each client and session separately");
100    }
101 
102    public void shutdownDrivers(boolean force) throws XmlBlasterException {
103       if (log.isLoggable(Level.FINE)) log.fine("Don't know how to shutdown the protocol drivers, they are created for each client and session separately");
104    }
105 }


syntax highlighted by Code2HTML, v. 0.9.1