aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs
diff options
context:
space:
mode:
authorTedd Hansen2008-11-09 10:30:46 +0000
committerTedd Hansen2008-11-09 10:30:46 +0000
commit853ba745b517f8dfb5c5b955637454e4c7d25507 (patch)
treea11ac849bcf4f80c91e87c4fb72a32f7d591e486 /OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs
parentUpdate svn properties. Add copyright headers. Minor formatting cleanup. (diff)
downloadopensim-SC_OLD-853ba745b517f8dfb5c5b955637454e4c7d25507.zip
opensim-SC_OLD-853ba745b517f8dfb5c5b955637454e4c7d25507.tar.gz
opensim-SC_OLD-853ba745b517f8dfb5c5b955637454e4c7d25507.tar.bz2
opensim-SC_OLD-853ba745b517f8dfb5c5b955637454e4c7d25507.tar.xz
Refactoring: Moved component creation to "ComponentFactory" as dictated by convention
Diffstat (limited to '')
-rw-r--r--OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs99
1 files changed, 1 insertions, 98 deletions
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs b/OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs
index f81b848..ae4e2f9 100644
--- a/OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs
+++ b/OpenSim/ApplicationPlugins/ScriptEngine/ScriptEnginePlugin.cs
@@ -26,11 +26,7 @@
26 */ 26 */
27using System; 27using System;
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.IO;
30using System.Reflection; 29using System.Reflection;
31using System.Text;
32using System.Threading;
33using OpenSim.ScriptEngine.Shared;
34using log4net; 30using log4net;
35 31
36namespace OpenSim.ApplicationPlugins.ScriptEngine 32namespace OpenSim.ApplicationPlugins.ScriptEngine
@@ -43,10 +39,6 @@ namespace OpenSim.ApplicationPlugins.ScriptEngine
43 internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 39 internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 internal OpenSimBase m_OpenSim; 40 internal OpenSimBase m_OpenSim;
45 41
46 // Component providers are registered here wit a name (string)
47 // When a script engine is created the components are instanciated
48 public static Dictionary<string, Type> providers = new Dictionary<string, Type>();
49 public static Dictionary<string, Type> scriptEngines = new Dictionary<string, Type>();
50 42
51 43
52 public ScriptEnginePlugin() 44 public ScriptEnginePlugin()
@@ -62,7 +54,7 @@ namespace OpenSim.ApplicationPlugins.ScriptEngine
62 54
63 // Load all modules from current directory 55 // Load all modules from current directory
64 // We only want files named OpenSim.ScriptEngine.*.dll 56 // We only want files named OpenSim.ScriptEngine.*.dll
65 Load(".", "OpenSim.ScriptEngine.*.dll"); 57 ComponentFactory.Load(".", "OpenSim.ScriptEngine.*.dll");
66 } 58 }
67 59
68 public void Initialise(OpenSimBase openSim) 60 public void Initialise(OpenSimBase openSim)
@@ -73,95 +65,6 @@ namespace OpenSim.ApplicationPlugins.ScriptEngine
73 //m_OpenSim.Shutdown(); 65 //m_OpenSim.Shutdown();
74 } 66 }
75 67
76 private readonly static string nameIScriptEngineComponent = typeof(IScriptEngineComponent).Name; // keep interface name in managed code
77 private readonly static string nameIScriptEngine = typeof(IScriptEngine).Name; // keep interface name in managed code
78 /// <summary>
79 /// Load components from directory
80 /// </summary>
81 /// <param name="directory"></param>
82 public void Load(string directory, string filter)
83 {
84 // We may want to change how this functions as currently it required unique class names for each component
85
86 foreach (string file in Directory.GetFiles(directory, filter))
87 {
88 //m_log.DebugFormat("[ScriptEngine]: Loading: [{0}].", file);
89 Assembly componentAssembly = null;
90 try
91 {
92 componentAssembly = Assembly.LoadFrom(file);
93 } catch (Exception e)
94 {
95 m_log.ErrorFormat("[{0}] Error loading: \"{1}\".", Name, file);
96 }
97 if (componentAssembly != null)
98 {
99 try
100 {
101 // Go through all types in the assembly
102 foreach (Type componentType in componentAssembly.GetTypes())
103 {
104 if (componentType.IsPublic
105 && !componentType.IsAbstract)
106 {
107 //if (componentType.IsSubclassOf(typeof(ComponentBase)))
108 if (componentType.GetInterface(nameIScriptEngineComponent) != null)
109 {
110 // We have found an type which is derived from ProdiverBase, add it to provider list
111 m_log.InfoFormat("[{0}] Adding component: {1}", Name, componentType.Name);
112 lock (providers)
113 {
114 providers.Add(componentType.Name, componentType);
115 }
116 }
117 //if (componentType.IsSubclassOf(typeof(ScriptEngineBase)))
118 if (componentType.GetInterface(nameIScriptEngine) != null)
119 {
120 // We have found an type which is derived from RegionScriptEngineBase, add it to engine list
121 m_log.InfoFormat("[{0}] Adding script engine: {1}", Name, componentType.Name);
122 lock (scriptEngines)
123 {
124 scriptEngines.Add(componentType.Name, componentType);
125 }
126 }
127 }
128 }
129 }
130 catch
131 (ReflectionTypeLoadException re)
132 {
133 m_log.ErrorFormat("[{0}] Could not load component \"{1}\": {2}", Name, componentAssembly.FullName, re.ToString());
134 int c = 0;
135 foreach (Exception e in re.LoaderExceptions)
136 {
137 c++;
138 m_log.ErrorFormat("[{0}] LoaderException {1}: {2}", Name, c, e.ToString());
139 }
140 }
141 } //if
142 } //foreach
143 }
144
145 public static IScriptEngineComponent GetComponentInstance(string name, params Object[] args)
146 {
147 if (!providers.ContainsKey(name))
148 throw new Exception("ScriptEngine requested component named \"" + name +
149 "\" that does not exist.");
150
151 return Activator.CreateInstance(providers[name], args) as IScriptEngineComponent;
152 }
153
154 private readonly static string nameIScriptEngineRegionComponent = typeof(IScriptEngineRegionComponent).Name; // keep interface name in managed code
155 public static IScriptEngineComponent GetComponentInstance(RegionInfoStructure info, string name, params Object[] args)
156 {
157 IScriptEngineComponent c = GetComponentInstance(name, args);
158
159 // If module is IScriptEngineRegionComponent then it will have one instance per region and we will initialize it
160 if (c.GetType().GetInterface(nameIScriptEngineRegionComponent) != null)
161 ((IScriptEngineRegionComponent)c).Initialize(info);
162
163 return c;
164 }
165 68
166 #region IApplicationPlugin stuff 69 #region IApplicationPlugin stuff
167 /// <summary> 70 /// <summary>