From b2111f6a19235f38c90dad26c7bf041b950b0bd7 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sun, 10 May 2009 22:31:10 +0000 Subject: [PATCH] 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(-) diff --git a/OpenSim/Servers/Base/ServerUtils.cs b/OpenSim/Servers/Base/ServerUtils.cs index 4e8f472105..834576bdea 100644 --- a/OpenSim/Servers/Base/ServerUtils.cs +++ b/OpenSim/Servers/Base/ServerUtils.cs @@ -95,6 +95,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(); @@ -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 800b172af4..c8a924ba85 100644 --- a/OpenSim/Services/Base/ServiceBase.cs +++ b/OpenSim/Services/Base/ServiceBase.cs @@ -35,6 +35,25 @@ namespace OpenSim.Services.Base public class ServiceBase { 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(); @@ -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; }