Clover.NET coverage report - Coverage

Coverage timestamp: viernes, 12 de agosto de 2005 12:53:38 PM

File Stats: LOC: 131   Methods: 2
NCLOC: 68 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Config\XmlConfigurationReader.cs 100,0 % 100,0 % 100,0 % 100,0 %
coverage
1   #region Copyright
2   /*
3   ShowX. Maps business objects into presentation layer.
4   Copyright (C) 2005 Jesus Diaz.
5  
6   This library is free software; you can redistribute it and/or
7   modify it under the terms of the GNU Lesser General Public
8   License as published by the Free Software Foundation; either
9   version 2.1 of the License, or (at your option) any later version.
10  
11   This library is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14   Lesser General Public License for more details.
15  
16   You should have received a copy of the GNU Lesser General Public
17   License along with this library; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19  
20   For project details see: http://showx.sourceforge.net
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   /// <summary>
32   /// XmlConfigurationReader read the configuration from an Xml node.
33   /// </summary>
34   public class XmlConfigurationReader
35   {
36   private static readonly ILog log = LogManager.GetLogger(
37   typeof(XmlConfigurationReader));
38  
39   /// <summary>
40   /// Define the path to the embedded resource showx-config.xsd, wich is
41   /// used to validate configuration section.
42   /// </summary>
43   protected static string configSchemeEmbeddedPath =
44   "ShowX.Model.XmlModel.Schema.showx-config.xsd";
45  
46   /// <summary>
47   /// Validate a certain Xml structure, against the showx configuration
48   /// definition.
49   /// </summary>
50   /// <param name="section">XmlNode to validate.</param>
51   /// <returns>True if the section is validated, false otherwise.</returns>
52 8 protected static bool validate(XmlNode section)
53   {
54 8 return new XmlFileValidator().Validate(section,configSchemeEmbeddedPath);
55   }
56  
57   /// <summary>
58   /// Read configuration data from an XmlNode.
59   /// </summary>
60   /// <param name="section">XmlNode to read configuration from.</param>
61   /// <returns>An instance of ConfigurationSectionInfo class.</returns>
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