1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
|
|
22
|
|
#endregion
|
23
|
|
|
24
|
|
using System.Collections;
|
25
|
|
using System.Xml;
|
26
|
|
using ShowX.Model.XmlModel;
|
27
|
|
using log4net;
|
28
|
|
|
29
|
|
namespace ShowX.Config
|
30
|
|
{
|
31
|
|
|
32
|
|
|
33
|
|
|
34
|
|
public class XmlConfigurationReader
|
35
|
|
{
|
36
|
|
private static readonly ILog log = LogManager.GetLogger(
|
37
|
|
typeof(XmlConfigurationReader));
|
38
|
|
|
39
|
|
|
40
|
|
|
41
|
|
|
42
|
|
|
43
|
|
protected static string configSchemeEmbeddedPath =
|
44
|
|
"ShowX.Model.XmlModel.Schema.showx-config.xsd";
|
45
|
|
|
46
|
|
|
47
|
|
|
48
|
|
|
49
|
|
|
50
|
|
|
51
|
|
|
52
|
8
|
protected static bool validate(XmlNode section)
|
53
|
|
{
|
54
|
8
|
return new XmlFileValidator().Validate(section,configSchemeEmbeddedPath);
|
55
|
|
}
|
56
|
|
|
57
|
|
|
58
|
|
|
59
|
|
|
60
|
|
|
61
|
|
|
62
|
11
|
public static ConfigurationSectionInfo Read(XmlNode section)
|
63
|
|
{
|
64
|
11
|
if (section == null) {
|
65
|
|
|
66
|
2
|
string errorMsg = "Configuration section xml node cannot be null";
|
67
|
|
|
68
|
2
|
log.Fatal(errorMsg);
|
69
|
2
|
throw new ConfigurationException(errorMsg);
|
70
|
|
}
|
71
|
|
|
72
|
9
|
if (section.Name != XmlConfigurationConst.rootTag) {
|
73
|
|
|
74
|
1
|
string errorMsg = string.Format(
|
75
|
|
"Configuration settings does not start with the '{0}' tag",
|
76
|
|
XmlConfigurationConst.rootTag);
|
77
|
|
|
78
|
1
|
log.Fatal(errorMsg);
|
79
|
1
|
throw new ConfigurationException(errorMsg);
|
80
|
|
}
|
81
|
|
|
82
|
8
|
if (!validate(section)) {
|
83
|
|
|
84
|
1
|
string errorMsg = "Error validating config file";
|
85
|
|
|
86
|
1
|
log.Fatal(errorMsg);
|
87
|
1
|
throw new ConfigurationException(errorMsg);
|
88
|
|
}
|
89
|
|
|
90
|
7
|
ConfigurationSectionInfo result = new ConfigurationSectionInfo();
|
91
|
|
|
92
|
7
|
string mappingModeValue = section
|
93
|
|
.Attributes[XmlConfigurationConst.mappingModeAttr].Value;
|
94
|
|
|
95
|
7
|
CaseInsensitiveComparer comparer = new CaseInsensitiveComparer();
|
96
|
|
|
97
|
7
|
if (comparer.Compare(mappingModeValue,
|
98
|
|
XmlConfigurationConst.modelAttrStr) == 0) {
|
99
|
|
|
100
|
1
|
result.MappingModel = MappingModel.Attribute;
|
101
|
|
}
|
102
|
6
|
else if (comparer.Compare(mappingModeValue,
|
103
|
|
XmlConfigurationConst.modelXMLStr) == 0) {
|
104
|
|
|
105
|
5
|
result.MappingModel = MappingModel.Xml;
|
106
|
|
}
|
107
|
|
else {
|
108
|
|
|
109
|
1
|
string errorMsg = string.Format("Unknown mapping model '{0}'.",
|
110
|
|
mappingModeValue);
|
111
|
|
|
112
|
1
|
log.Fatal(errorMsg);
|
113
|
1
|
throw new ConfigurationException(errorMsg);
|
114
|
|
}
|
115
|
|
|
116
|
6
|
foreach (XmlNode mapping in section
|
117
|
|
.SelectNodes("//"
|
118
|
|
+ XmlConfigurationConst.classMappingsTag + "/"
|
119
|
|
+ XmlConfigurationConst.mappingTag)) {
|
120
|
|
|
121
|
2
|
result.XmlMappingFiles[mapping
|
122
|
|
.Attributes[XmlConfigurationConst.mappingClassNameAttr]
|
123
|
|
.Value] = mapping.Attributes[XmlConfigurationConst
|
124
|
|
.mappingMappingFileAttr].Value;
|
125
|
|
}
|
126
|
|
|
127
|
6
|
return result;
|
128
|
|
}
|
129
|
|
}
|
130
|
|
}
|
131
|
|
|