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 +++++++++++++++++++++-----------------
1 file changed, 82 insertions(+), 69 deletions(-)
(limited to 'OpenSim/Data')
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);
}
-
}
}
--
cgit v1.1