diff --git a/OpenSim/Data/DataPluginFactory.cs b/OpenSim/Data/DataPluginFactory.cs index 5293e94cba..2f60ae4281 100644 --- a/OpenSim/Data/DataPluginFactory.cs +++ b/OpenSim/Data/DataPluginFactory.cs @@ -25,21 +25,80 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; using System.Collections.Generic; using OpenSim.Framework; namespace OpenSim.Data { /// - /// A static class containing a series of methods for obtaining handles to - /// database storage objects. + /// A static class containing methods for obtaining handles to database + /// storage objects. /// - // Yeah, it's not really a factory, but maybe it'll morph into one? public static class DataPluginFactory { /// - /// Returns a list of new inventory data plugins. Plugins will be - /// requested in the order they were added. + /// Based on , returns the appropriate + /// PluginInitialiserBase instance in and + /// extension point path in . + /// + /// + /// The DB connection string used when creating a new + /// PluginInitialiserBase, returned in . + /// + /// + /// A reference to a PluginInitialiserBase object in which the proper + /// initialiser will be returned. + /// + /// + /// A string in which the proper extension point path will be returned. + /// + /// + /// The type of data plugin requested. + /// + /// + /// Thrown if is not one of the expected data + /// interfaces. + /// + private static void PluginLoaderParamFactory(string connect, out PluginInitialiserBase init, out string path) where T : IPlugin + { + Type type = typeof(T); + + if (type == typeof(IInventoryDataPlugin)) + { + init = new InventoryDataInitialiser(connect); + path = "/OpenSim/InventoryData"; + } + else if (type == typeof(IUserDataPlugin)) + { + init = new UserDataInitialiser(connect); + path = "/OpenSim/UserData"; + } + else if (type == typeof(IGridDataPlugin)) + { + init = new GridDataInitialiser(connect); + path = "/OpenSim/GridData"; + } + else if (type == typeof(ILogDataPlugin)) + { + init = new LogDataInitialiser(connect); + path = "/OpenSim/LogData"; + } + else if (type == typeof(IAssetDataPlugin)) + { + init = new AssetDataInitialiser(connect); + path = "/OpenSim/AssetData"; + } + else + { + // We don't support this data plugin. + throw new NotImplementedException(String.Format("The type '{0}' is not a valid data plugin.", type)); + } + } + + /// + /// Returns a list of new data plugins. + /// Plugins will be requested in the order they were added. /// /// /// The filename of the inventory server plugin DLL. @@ -47,95 +106,49 @@ namespace OpenSim.Data /// /// The connection string for the storage backend. /// - public static List LoadInventoryDataPlugins(string provider, string connect) + /// + /// The type of data plugin requested. + /// + /// + /// A list of all loaded plugins matching . + /// + public static List LoadDataPlugins(string provider, string connect) where T : IPlugin { - PluginLoader loader = new PluginLoader (new InventoryDataInitialiser(connect)); + PluginInitialiserBase pluginInitialiser; + string extensionPointPath; + + PluginLoaderParamFactory(connect, out pluginInitialiser, out extensionPointPath); + + PluginLoader loader = new PluginLoader(pluginInitialiser); // loader will try to load all providers (MySQL, MSSQL, etc) // unless it is constrainted to the correct "Provider" entry in the addin.xml - loader.Add ("/OpenSim/InventoryData", new PluginProviderFilter(provider)); + loader.Add(extensionPointPath, new PluginProviderFilter(provider)); loader.Load(); return loader.Plugins; } /// - /// Returns a list of new user data plugins. Plugins will be requested - /// in the order they were added. + /// Returns a new data plugin instance if + /// only one was loaded, otherwise returns null (default(T)). /// /// - /// The filename of the user data plugin DLL. + /// The filename of the inventory server plugin DLL. /// /// /// The connection string for the storage backend. /// - public static List LoadUserDataPlugins(string provider, string connect) + /// + /// The type of data plugin requested. + /// + /// + /// A list of all loaded plugins matching . + /// + public static T LoadDataPlugin(string provider, string connect) where T : IPlugin { - PluginLoader loader = new PluginLoader(new UserDataInitialiser(connect)); - - // loader will try to load all providers (MySQL, MSSQL, etc) - // unless it is constrainted to the correct "Provider" entry in the addin.xml - loader.Add("/OpenSim/UserData", new PluginProviderFilter(provider)); - loader.Load(); - - return loader.Plugins; + List plugins = LoadDataPlugins(provider, connect); + return (plugins.Count == 1) ? plugins[0] : default(T); } - - /// - /// Returns a list of new grid data plugins. Plugins will be requested - /// in the order they were added. - /// - /// - /// The filename of the user data plugin DLL. - /// - /// - /// The connection string for the storage backend. - /// - public static List LoadGridDataPlugins(string provider, string connect) - { - PluginLoader loader = new PluginLoader(new GridDataInitialiser(connect)); - - // loader will try to load all providers (MySQL, MSSQL, etc) - // unless it is constrainted to the correct "Provider" entry in the addin.xml - loader.Add("/OpenSim/GridData", new PluginProviderFilter(provider)); - loader.Load(); - - return loader.Plugins; - } - - /// - /// Returns a list of new log data plugins. Plugins will be requested - /// in the order they were added. - /// - /// - /// The filename of the user data plugin DLL. - /// - /// - /// The connection string for the storage backend. - /// - public static List LoadLogDataPlugins(string provider, string connect) - { - PluginLoader loader = new PluginLoader(new LogDataInitialiser(connect)); - - // loader will try to load all providers (MySQL, MSSQL, etc) - // unless it is constrainted to the correct "Provider" entry in the addin.xml - loader.Add("/OpenSim/LogData", new PluginProviderFilter(provider)); - loader.Load(); - - return loader.Plugins; - } - - public static IAssetDataPlugin LoadAssetDataPlugin(string provider, string connect) - { - PluginLoader loader = new PluginLoader (new AssetDataInitialiser (connect)); - - // loader will try to load all providers (MySQL, MSSQL, etc) - // unless it is constrainted to the correct "Provider" entry in the addin.xml - loader.Add ("/OpenSim/AssetData", new PluginProviderFilter (provider)); - loader.Load(); - - return loader.Plugin; - } - } } diff --git a/OpenSim/Framework/Communications/InventoryServiceBase.cs b/OpenSim/Framework/Communications/InventoryServiceBase.cs index a031bdf4ba..8753c64a9d 100644 --- a/OpenSim/Framework/Communications/InventoryServiceBase.cs +++ b/OpenSim/Framework/Communications/InventoryServiceBase.cs @@ -70,7 +70,7 @@ namespace OpenSim.Framework.Communications /// public void AddPlugin(string provider, string connect) { - m_plugins.AddRange(DataPluginFactory.LoadInventoryDataPlugins(provider, connect)); + m_plugins.AddRange(DataPluginFactory.LoadDataPlugins(provider, connect)); } #endregion diff --git a/OpenSim/Framework/Communications/UserManagerBase.cs b/OpenSim/Framework/Communications/UserManagerBase.cs index 886900d568..0af96520c0 100644 --- a/OpenSim/Framework/Communications/UserManagerBase.cs +++ b/OpenSim/Framework/Communications/UserManagerBase.cs @@ -85,7 +85,7 @@ namespace OpenSim.Framework.Communications /// public void AddPlugin(string provider, string connect) { - _plugins.AddRange(DataPluginFactory.LoadUserDataPlugins(provider, connect)); + _plugins.AddRange(DataPluginFactory.LoadDataPlugins(provider, connect)); } #region Get UserProfile diff --git a/OpenSim/Grid/AssetServer/Main.cs b/OpenSim/Grid/AssetServer/Main.cs index c71e53f190..4609ee8c58 100644 --- a/OpenSim/Grid/AssetServer/Main.cs +++ b/OpenSim/Grid/AssetServer/Main.cs @@ -118,7 +118,7 @@ namespace OpenSim.Grid.AssetServer { try { - m_assetProvider = DataPluginFactory.LoadAssetDataPlugin(config.DatabaseProvider, config.DatabaseConnect); + m_assetProvider = DataPluginFactory.LoadDataPlugin(config.DatabaseProvider, config.DatabaseConnect); if (m_assetProvider == null) { m_log.Error("[ASSET]: Failed to load a database plugin, server halting"); diff --git a/OpenSim/Grid/GridServer/GridManager.cs b/OpenSim/Grid/GridServer/GridManager.cs index 3fc0393ad8..f98809d788 100644 --- a/OpenSim/Grid/GridServer/GridManager.cs +++ b/OpenSim/Grid/GridServer/GridManager.cs @@ -83,8 +83,8 @@ namespace OpenSim.Grid.GridServer /// public void AddPlugin(string provider, string connect) { - _plugins = DataPluginFactory.LoadGridDataPlugins(provider, connect); - _logplugins = DataPluginFactory.LoadLogDataPlugins(provider, connect); + _plugins = DataPluginFactory.LoadDataPlugins(provider, connect); + _logplugins = DataPluginFactory.LoadDataPlugins(provider, connect); } ///