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;
|
25
|
|
using System.Xml;
|
26
|
|
using System.Collections;
|
27
|
|
using System.Reflection;
|
28
|
|
using ShowX.Model.XmlModel;
|
29
|
|
using log4net;
|
30
|
|
|
31
|
|
namespace ShowX.Model.XmlModel
|
32
|
|
{
|
33
|
|
|
34
|
|
|
35
|
|
|
36
|
|
public class XmlPropertyMap : IPropertyMap
|
37
|
|
{
|
38
|
|
private static readonly ILog log = LogManager.GetLogger(
|
39
|
|
typeof(XmlPropertyMap));
|
40
|
|
|
41
|
|
#region Protected fields
|
42
|
|
|
43
|
|
|
44
|
|
|
45
|
|
|
46
|
|
protected PropertyInfo propertyInfo;
|
47
|
|
|
48
|
|
|
49
|
|
|
50
|
|
|
51
|
|
protected string name ="";
|
52
|
|
|
53
|
|
|
54
|
|
|
55
|
|
|
56
|
|
protected string heading = "";
|
57
|
|
|
58
|
|
|
59
|
|
|
60
|
|
|
61
|
|
|
62
|
|
protected bool readOnly = false;
|
63
|
|
|
64
|
|
|
65
|
|
|
66
|
|
|
67
|
|
|
68
|
|
protected bool show = true;
|
69
|
|
|
70
|
|
|
71
|
|
|
72
|
|
|
73
|
|
|
74
|
|
protected bool editOnInsert = true;
|
75
|
|
|
76
|
|
|
77
|
|
|
78
|
|
|
79
|
|
protected bool isPassword = false;
|
80
|
|
|
81
|
|
|
82
|
|
|
83
|
|
|
84
|
|
protected ArrayList validators;
|
85
|
|
|
86
|
|
|
87
|
|
|
88
|
|
|
89
|
|
protected ItemStyle itemStyle = ItemStyle.None;
|
90
|
|
|
91
|
|
|
92
|
|
|
93
|
|
|
94
|
|
protected ITranslator translator;
|
95
|
|
|
96
|
|
#endregion
|
97
|
|
|
98
|
|
|
99
|
|
|
100
|
|
|
101
|
|
|
102
|
|
|
103
|
|
|
104
|
|
|
105
|
|
|
106
|
480
|
public static string LoadValueFromAttribute(XmlAttribute attribute,
|
107
|
|
string defaultValue)
|
108
|
|
{
|
109
|
480
|
return (attribute == null) ? defaultValue : attribute.Value;
|
110
|
|
}
|
111
|
|
|
112
|
|
|
113
|
|
|
114
|
|
|
115
|
|
|
116
|
|
|
117
|
|
|
118
|
|
|
119
|
|
|
120
|
|
|
121
|
|
|
122
|
590
|
public static bool LoadValueFromAttribute(XmlAttribute attribute,
|
123
|
|
bool defaultValue)
|
124
|
|
{
|
125
|
590
|
return (attribute == null) ? defaultValue : Boolean.Parse(attribute.Value);
|
126
|
|
}
|
127
|
|
|
128
|
|
|
129
|
|
|
130
|
|
|
131
|
|
|
132
|
|
|
133
|
|
|
134
|
147
|
public XmlPropertyMap(Type t, XmlNode propertyNode)
|
135
|
|
{
|
136
|
|
|
137
|
147
|
this.name = propertyNode.Attributes[
|
138
|
|
XmlMappingFileConst.propertyMappingNameAttr].Value;
|
139
|
|
|
140
|
|
|
141
|
147
|
this.heading = LoadValueFromAttribute(
|
142
|
|
propertyNode.Attributes[XmlMappingFileConst.propertyHeadingAttr]
|
143
|
|
,this.name);
|
144
|
|
|
145
|
147
|
this.readOnly = LoadValueFromAttribute(
|
146
|
|
propertyNode.Attributes[XmlMappingFileConst.propertyReadOnlyAttr]
|
147
|
|
,this.readOnly);
|
148
|
|
|
149
|
147
|
this.show = LoadValueFromAttribute(
|
150
|
|
propertyNode.Attributes[XmlMappingFileConst.propertyShowAttr]
|
151
|
|
,this.show);
|
152
|
|
|
153
|
147
|
this.editOnInsert = LoadValueFromAttribute(
|
154
|
|
propertyNode.Attributes[XmlMappingFileConst.propertyEditOnInsertAttr]
|
155
|
|
,this.editOnInsert);
|
156
|
|
|
157
|
147
|
this.isPassword = LoadValueFromAttribute(
|
158
|
|
propertyNode.Attributes[XmlMappingFileConst.propertyIsPasswordAttr]
|
159
|
|
,this.isPassword);
|
160
|
|
|
161
|
147
|
string itemStyleStr = LoadValueFromAttribute(
|
162
|
|
propertyNode.Attributes[XmlMappingFileConst.propertyItemStyleAttr]
|
163
|
|
,"none");
|
164
|
|
|
165
|
147
|
string translatorStr = LoadValueFromAttribute(
|
166
|
|
propertyNode.Attributes[XmlMappingFileConst.propertyTranslatorAttr]
|
167
|
|
,"");
|
168
|
|
|
169
|
147
|
this.itemStyle = (ItemStyle)Enum.Parse(typeof(ItemStyle),itemStyleStr,true);
|
170
|
|
|
171
|
147
|
if (translatorStr != "") {
|
172
|
|
|
173
|
0
|
string[] asmAndType = translatorStr.Split(new char[]{','},2);
|
174
|
|
|
175
|
0
|
Assembly asm = Assembly.LoadWithPartialName(asmAndType[0]);
|
176
|
|
|
177
|
0
|
Type trans = asm.GetType(asmAndType[1],false);
|
178
|
|
|
179
|
0
|
if (trans == null) {
|
180
|
|
|
181
|
|
string errorMsg = string.Format(
|
182
|
|
"Unable to load translator class '{0}' "
|
183
|
|
+ "for property '{1}'.",translatorStr,this.name);
|
184
|
|
|
185
|
|
log.Fatal(errorMsg);
|
186
|
|
throw new ModelException(errorMsg);
|
187
|
|
}
|
188
|
|
|
189
|
0
|
this.translator = trans.InvokeMember("",BindingFlags.CreateInstance,
|
190
|
|
null,null,null) as ITranslator;
|
191
|
|
}
|
192
|
|
|
193
|
147
|
this.propertyInfo = t.GetProperty(this.name);
|
194
|
|
|
195
|
147
|
if (this.propertyInfo == null) {
|
196
|
|
|
197
|
0
|
string errorMsg = string.Format(
|
198
|
|
"Cannot load property '{0}' for type '{1}'",
|
199
|
|
this.name,t.UnderlyingSystemType.FullName);
|
200
|
|
|
201
|
0
|
log.Fatal(errorMsg);
|
202
|
0
|
new ModelException(errorMsg);
|
203
|
|
}
|
204
|
|
|
205
|
|
|
206
|
147
|
validators = new ArrayList();
|
207
|
|
|
208
|
147
|
foreach (XmlNode val in propertyNode.ChildNodes) {
|
209
|
|
|
210
|
118
|
validators.Add(new XmlValidateMap(this.propertyInfo,val));
|
211
|
|
}
|
212
|
|
}
|
213
|
|
|
214
|
|
|
215
|
|
#region Public properties
|
216
|
|
|
217
|
|
|
218
|
|
|
219
|
|
|
220
|
|
public PropertyInfo PropertyInfo
|
221
|
|
{
|
222
|
11174
|
get { return this.propertyInfo; }
|
223
|
0
|
set { this.propertyInfo = value; }
|
224
|
|
}
|
225
|
|
|
226
|
|
|
227
|
|
|
228
|
|
|
229
|
|
public string Name
|
230
|
|
{
|
231
|
302
|
get { return name; }
|
232
|
0
|
set { this.name = value; }
|
233
|
|
}
|
234
|
|
|
235
|
|
|
236
|
|
|
237
|
|
|
238
|
|
public virtual bool ReadOnly
|
239
|
|
{
|
240
|
175
|
get { return readOnly; }
|
241
|
0
|
set { this.readOnly = value; }
|
242
|
|
}
|
243
|
|
|
244
|
|
|
245
|
|
|
246
|
|
|
247
|
|
public virtual bool EditOnInsert
|
248
|
|
{
|
249
|
175
|
get { return editOnInsert; }
|
250
|
0
|
set { this.editOnInsert = value; }
|
251
|
|
}
|
252
|
|
|
253
|
|
|
254
|
|
|
255
|
|
|
256
|
|
public virtual bool IsPassword
|
257
|
|
{
|
258
|
960
|
get { return isPassword; }
|
259
|
0
|
set { this.isPassword = value; }
|
260
|
|
}
|
261
|
|
|
262
|
|
|
263
|
|
|
264
|
|
|
265
|
|
public bool Show
|
266
|
|
{
|
267
|
245
|
get { return show; }
|
268
|
0
|
set { this.show = value; }
|
269
|
|
}
|
270
|
|
|
271
|
|
|
272
|
|
|
273
|
|
|
274
|
|
public ArrayList Validators
|
275
|
|
{
|
276
|
141
|
get { return this.validators; }
|
277
|
|
}
|
278
|
|
|
279
|
|
|
280
|
|
|
281
|
|
|
282
|
|
public ItemStyle ItemStyle
|
283
|
|
{
|
284
|
713
|
get { return this.itemStyle; }
|
285
|
0
|
set { this.itemStyle = value; }
|
286
|
|
}
|
287
|
|
|
288
|
|
|
289
|
|
|
290
|
|
|
291
|
0
|
public ITranslator Translator
|
292
|
|
{
|
293
|
|
get { return this.translator; }
|
294
|
|
set { this.translator = value; }
|
295
|
|
}
|
296
|
|
|
297
|
|
|
298
|
|
|
299
|
|
|
300
|
|
public string Heading
|
301
|
|
{
|
302
|
595
|
get { return this.heading; }
|
303
|
0
|
set { this.heading = value; }
|
304
|
|
}
|
305
|
|
|
306
|
|
#endregion
|
307
|
|
}
|
308
|
|
}
|
309
|
|
|