From 369eef5fcd8e6566d5f953db6a6b093cf674269c Mon Sep 17 00:00:00 2001
From: Mike Mazur
Date: Mon, 9 Feb 2009 00:33:44 +0000
Subject: The DataPluginFactory is now a set of generic methods instead of
multiple duplicates of the same code.
---
OpenSim/Data/DataPluginFactory.cs | 151 +++++++++++----------
.../Communications/InventoryServiceBase.cs | 2 +-
.../Framework/Communications/UserManagerBase.cs | 2 +-
OpenSim/Grid/AssetServer/Main.cs | 2 +-
OpenSim/Grid/GridServer/GridManager.cs | 4 +-
5 files changed, 87 insertions(+), 74 deletions(-)
diff --git a/OpenSim/Data/DataPluginFactory.cs b/OpenSim/Data/DataPluginFactory.cs
index 5293e94..2f60ae4 100644
--- a/OpenSim/Data/DataPluginFactory.cs
+++ b/OpenSim/Data/DataPluginFactory.cs
@@ -25,117 +25,130 @@
* 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 filename of the inventory server plugin DLL.
- ///
///
- /// The connection string for the storage backend.
+ /// The DB connection string used when creating a new
+ /// PluginInitialiserBase, returned in .
///
- public static List LoadInventoryDataPlugins(string provider, string connect)
- {
- PluginLoader loader = new PluginLoader (new InventoryDataInitialiser(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/InventoryData", 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.
- ///
- ///
- /// The filename of the user data plugin DLL.
+ ///
+ /// A reference to a PluginInitialiserBase object in which the proper
+ /// initialiser will be returned.
///
- ///
- /// The connection string for the storage backend.
+ ///
+ /// A string in which the proper extension point path will be returned.
///
- public static List LoadUserDataPlugins(string provider, string connect)
+ ///
+ /// 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
{
- 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;
+ 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 grid data plugins. Plugins will be requested
- /// in the order they were added.
+ /// Returns a list of new data plugins.
+ /// Plugins will be requested in the order they were added.
///
///
- /// 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 LoadGridDataPlugins(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 GridDataInitialiser(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/GridData", new PluginProviderFilter(provider));
+ loader.Add(extensionPointPath, 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.
+ /// 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 LoadLogDataPlugins(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 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;
+ List plugins = LoadDataPlugins(provider, connect);
+ return (plugins.Count == 1) ? plugins[0] : default(T);
}
-
}
}
diff --git a/OpenSim/Framework/Communications/InventoryServiceBase.cs b/OpenSim/Framework/Communications/InventoryServiceBase.cs
index a031bdf..8753c64 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 886900d..0af9652 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 c71e53f..4609ee8 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 3fc0393..f98809d 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);
}
///
--
cgit v1.1