aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/General
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/General')
-rw-r--r--OpenSim/Framework/General/Configuration/ConfigurationMember.cs52
-rw-r--r--OpenSim/Framework/General/Configuration/Interfaces/IGenericConfig.cs3
-rw-r--r--OpenSim/Framework/General/Configuration/XmlConfiguration.cs123
3 files changed, 43 insertions, 135 deletions
diff --git a/OpenSim/Framework/General/Configuration/ConfigurationMember.cs b/OpenSim/Framework/General/Configuration/ConfigurationMember.cs
index e93a576..4546683 100644
--- a/OpenSim/Framework/General/Configuration/ConfigurationMember.cs
+++ b/OpenSim/Framework/General/Configuration/ConfigurationMember.cs
@@ -1,4 +1,5 @@
1using System; 1using System;
2using System.Reflection;
2using System.Collections; 3using System.Collections;
3using System.Collections.Generic; 4using System.Collections.Generic;
4using System.Text; 5using System.Text;
@@ -7,6 +8,7 @@ using System.Net;
7using libsecondlife; 8using libsecondlife;
8 9
9using OpenSim.Framework.Console; 10using OpenSim.Framework.Console;
11using OpenSim.Framework.Configuration.Interfaces;
10 12
11namespace OpenSim.Framework.Configuration 13namespace OpenSim.Framework.Configuration
12{ 14{
@@ -22,12 +24,14 @@ namespace OpenSim.Framework.Configuration
22 private ConfigurationOptionsLoad loadFunction; 24 private ConfigurationOptionsLoad loadFunction;
23 private ConfigurationOptionResult resultFunction; 25 private ConfigurationOptionResult resultFunction;
24 26
27 private IGenericConfig configurationPlugin = null;
25 public ConfigurationMember(string configuration_filename, string configuration_description, ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function) 28 public ConfigurationMember(string configuration_filename, string configuration_description, ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function)
26 { 29 {
27 this.configurationFilename = configuration_filename; 30 this.configurationFilename = configuration_filename;
28 this.configurationDescription = configuration_description; 31 this.configurationDescription = configuration_description;
29 this.loadFunction = load_function; 32 this.loadFunction = load_function;
30 this.resultFunction = result_function; 33 this.resultFunction = result_function;
34 this.configurationPlugin = this.LoadConfigDll("OpenSim.Framework.Configuration.XML.dll");
31 } 35 }
32 36
33 public void setConfigurationFilename(string filename) 37 public void setConfigurationFilename(string filename)
@@ -91,18 +95,19 @@ namespace OpenSim.Framework.Configuration
91 } 95 }
92 96
93 bool useFile = true; 97 bool useFile = true;
94 XmlConfiguration xmlConfig = null; 98 if (configurationPlugin == null)
95 if (configurationFilename.Trim() != "")
96 { 99 {
97 xmlConfig = new XmlConfiguration(configurationFilename); 100 MainLog.Instance.Error("Configuration Plugin NOT LOADED!");
98 101 return;
99 } 102 }
100 103
101 if(xmlConfig != null) 104 if (configurationFilename.Trim() != "")
102 { 105 {
103 xmlConfig.LoadData(); 106 configurationPlugin.SetFileName(configurationFilename);
107 configurationPlugin.LoadData();
104 useFile = true; 108 useFile = true;
105 } 109 }
110
106 else 111 else
107 { 112 {
108 MainLog.Instance.Notice("XML Configuration Filename is not valid; will not save to the file."); 113 MainLog.Instance.Notice("XML Configuration Filename is not valid; will not save to the file.");
@@ -124,7 +129,7 @@ namespace OpenSim.Framework.Configuration
124 { 129 {
125 if (!ignoreNextFromConfig) 130 if (!ignoreNextFromConfig)
126 { 131 {
127 attribute = xmlConfig.GetAttribute(configOption.configurationKey); 132 attribute = configurationPlugin.GetAttribute(configOption.configurationKey);
128 } 133 }
129 else 134 else
130 { 135 {
@@ -304,7 +309,7 @@ namespace OpenSim.Framework.Configuration
304 { 309 {
305 if (useFile) 310 if (useFile)
306 { 311 {
307 xmlConfig.SetAttribute(configOption.configurationKey, console_result); 312 configurationPlugin.SetAttribute(configOption.configurationKey, console_result);
308 } 313 }
309 314
310 315
@@ -333,9 +338,34 @@ namespace OpenSim.Framework.Configuration
333 338
334 if(useFile) 339 if(useFile)
335 { 340 {
336 xmlConfig.Commit(); 341 configurationPlugin.Commit();
337 xmlConfig.Close(); 342 configurationPlugin.Close();
338 } 343 }
339 } 344 }
345
346 private IGenericConfig LoadConfigDll(string dllName)
347 {
348 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
349 IGenericConfig plug = null;
350
351 foreach (Type pluginType in pluginAssembly.GetTypes())
352 {
353 if (pluginType.IsPublic)
354 {
355 if (!pluginType.IsAbstract)
356 {
357 Type typeInterface = pluginType.GetInterface("IGenericConfig", true);
358
359 if (typeInterface != null)
360 {
361 plug = (IGenericConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
362 }
363 }
364 }
365 }
366
367 pluginAssembly = null;
368 return plug;
369 }
340 } 370 }
341} 371}
diff --git a/OpenSim/Framework/General/Configuration/Interfaces/IGenericConfig.cs b/OpenSim/Framework/General/Configuration/Interfaces/IGenericConfig.cs
index 2c379dd..5a5a20e 100644
--- a/OpenSim/Framework/General/Configuration/Interfaces/IGenericConfig.cs
+++ b/OpenSim/Framework/General/Configuration/Interfaces/IGenericConfig.cs
@@ -25,10 +25,11 @@
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28namespace OpenSim.Framework.Interfaces 28namespace OpenSim.Framework.Configuration.Interfaces
29{ 29{
30 public interface IGenericConfig 30 public interface IGenericConfig
31 { 31 {
32 void SetFileName(string fileName);
32 void LoadData(); 33 void LoadData();
33 string GetAttribute(string attributeName); 34 string GetAttribute(string attributeName);
34 bool SetAttribute(string attributeName, string attributeValue); 35 bool SetAttribute(string attributeName, string attributeValue);
diff --git a/OpenSim/Framework/General/Configuration/XmlConfiguration.cs b/OpenSim/Framework/General/Configuration/XmlConfiguration.cs
deleted file mode 100644
index e1f3816..0000000
--- a/OpenSim/Framework/General/Configuration/XmlConfiguration.cs
+++ /dev/null
@@ -1,123 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.IO;
30using System.Xml;
31
32using OpenSim.Framework.Interfaces;
33
34namespace OpenSim.Framework.Configuration
35{
36 public class XmlConfiguration : IGenericConfig
37 {
38 private XmlDocument doc;
39 private XmlNode rootNode;
40 private XmlNode configNode;
41 private string fileName;
42 private bool createdFile = false;
43
44 public XmlConfiguration(string filename)
45 {
46 fileName = filename;
47 }
48
49 public void LoadData()
50 {
51 doc = new XmlDocument();
52
53 if (File.Exists(fileName))
54 {
55 XmlTextReader reader = new XmlTextReader(fileName);
56 reader.WhitespaceHandling = WhitespaceHandling.None;
57 doc.Load(reader);
58 reader.Close();
59 }
60 else
61 {
62 createdFile = true;
63 rootNode = doc.CreateNode(XmlNodeType.Element, "Root", "");
64 doc.AppendChild(rootNode);
65 configNode = doc.CreateNode(XmlNodeType.Element, "Config", "");
66 rootNode.AppendChild(configNode);
67 }
68
69
70 rootNode = doc.FirstChild;
71 if (rootNode.Name != "Root")
72 throw new Exception("Error: Invalid .xml File. Missing <Root>");
73
74 configNode = rootNode.FirstChild;
75 if (configNode.Name != "Config")
76 throw new Exception("Error: Invalid .xml File. <Root> first child should be <Config>");
77
78 if (createdFile)
79 {
80 this.Commit();
81 }
82 }
83
84 public string GetAttribute(string attributeName)
85 {
86 string result = null;
87 if (configNode.Attributes[attributeName] != null)
88 {
89 result = ((XmlAttribute)configNode.Attributes.GetNamedItem(attributeName)).Value;
90 }
91 return result;
92 }
93
94 public bool SetAttribute(string attributeName, string attributeValue)
95 {
96 if (configNode.Attributes[attributeName] != null)
97 {
98 ((XmlAttribute)configNode.Attributes.GetNamedItem(attributeName)).Value = attributeValue;
99 }
100 else
101 {
102 XmlAttribute attri;
103 attri = doc.CreateAttribute(attributeName);
104 attri.Value = attributeValue;
105 configNode.Attributes.Append(attri);
106 }
107 return true;
108 }
109
110 public void Commit()
111 {
112 doc.Save(fileName);
113 }
114
115 public void Close()
116 {
117 configNode = null;
118 rootNode = null;
119 doc = null;
120 }
121
122 }
123}