From b2111f6a19235f38c90dad26c7bf041b950b0bd7 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sun, 10 May 2009 22:31:10 +0000 Subject: Enhance the submodule loader and port the enhancements to the services base --- OpenSim/Servers/Base/ServerUtils.cs | 19 +++++++++++++++++++ OpenSim/Services/Base/ServiceBase.cs | 29 ++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 3 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Servers/Base/ServerUtils.cs b/OpenSim/Servers/Base/ServerUtils.cs index 4e8f472..834576b 100644 --- a/OpenSim/Servers/Base/ServerUtils.cs +++ b/OpenSim/Servers/Base/ServerUtils.cs @@ -96,6 +96,20 @@ namespace OpenSim.Servers.Base public static T LoadPlugin(string dllName, Object[] args) where T:class { + string[] parts = dllName.Split(new char[] {':'}); + + dllName = parts[0]; + + string className = String.Empty; + + if (parts.Length > 1) + className = parts[1]; + + return LoadPlugin(dllName, className, args); + } + + public static T LoadPlugin(string dllName, string className, Object[] args) where T:class + { string interfaceName = typeof(T).ToString(); try @@ -106,6 +120,11 @@ namespace OpenSim.Servers.Base { if (pluginType.IsPublic) { + if (className != String.Empty && + pluginType.ToString() != + pluginType.Namespace + "." + className) + continue; + Type typeInterface = pluginType.GetInterface(interfaceName, true); if (typeInterface != null) diff --git a/OpenSim/Services/Base/ServiceBase.cs b/OpenSim/Services/Base/ServiceBase.cs index 800b172..c8a924b 100644 --- a/OpenSim/Services/Base/ServiceBase.cs +++ b/OpenSim/Services/Base/ServiceBase.cs @@ -36,6 +36,25 @@ namespace OpenSim.Services.Base { public T LoadPlugin(string dllName) where T:class { + return LoadPlugin(dllName, new Object[0]); + } + + public T LoadPlugin(string dllName, Object[] args) where T:class + { + string[] parts = dllName.Split(new char[] {':'}); + + dllName = parts[0]; + + string className = String.Empty; + + if (parts.Length > 1) + className = parts[1]; + + return LoadPlugin(dllName, className, args); + } + + public T LoadPlugin(string dllName, string className, Object[] args) where T:class + { string interfaceName = typeof(T).ToString(); try @@ -46,13 +65,17 @@ namespace OpenSim.Services.Base { if (pluginType.IsPublic) { + if (className != String.Empty && + pluginType.ToString() != + pluginType.Namespace + "." + className) + continue; + Type typeInterface = pluginType.GetInterface(interfaceName, true); if (typeInterface != null) { - T plug = (T)Activator.CreateInstance( - pluginAssembly.GetType( - pluginType.ToString())); + T plug = (T)Activator.CreateInstance(pluginType, + args); return plug; } -- cgit v1.1