Clover.NET coverage report - Coverage

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

File Stats: LOC: 210   Methods: 7
NCLOC: 108 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Config\Configuration.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;
25   using System.Configuration;
26   using System.IO;
27   using System.Xml;
28   using ShowX.Session;
29   using log4net;
30  
31   namespace ShowX.Config
32   {
33   /// <summary>
34   /// Configuration class provides access to global constants and current session
35   /// object. It initialize showx system, by loading class-mapping, from
36   /// configuration file .config, or from embedded XML resources.
37   /// </summary>
38   public class Configuration
39   {
40   private static readonly ILog log = LogManager.GetLogger(
41   typeof(Configuration));
42  
43   /// <summary>
44   /// ISession instance to keep track of showX session.
45   /// </summary>
46   static private ISession session;
47  
48   static private MappingModel mappingModel;
49  
50   /// <summary>
51   /// Create a session according to parameters specified in showx config section.
52   /// </summary>
53   /// <param name="settings">Showx config section info.</param>
54 28 public static void createSession(ConfigurationSectionInfo settings)
55   {
56 28 switch(settings.MappingModel) {
57  
58   case MappingModel.Attribute:
59  
60 4 log.Debug("Creating attribute session.");
61  
62 4 session = new AttributeSession();
63 4 mappingModel = MappingModel.Attribute;
64 4 break;
65  
66   case MappingModel.Xml:
67  
68 23 log.Debug("Creating xml mapping session.");
69  
70 23 session = new XmlSession();
71 23 mappingModel = MappingModel.Xml;
72 23 (session as XmlSession).XmlMappingFiles = settings.XmlMappingFiles;
73  
74 23 break;
75   }
76   }
77  
78   /// <summary>
79   /// Initialize ShowX mapping system by loading configuration from application
80   /// .config file.
81   /// </summary>
82 10 public static void Configure()
83   {
84 10 try {
85  
86 10 ConfigurationSectionInfo settings = ConfigurationSettings
87   .GetConfig(XmlConfigurationConst.rootTag) as ConfigurationSectionInfo;
88  
89 10 createSession(settings);
90   }
91   catch (Exception e){
92  
93 1 log.Fatal("Error configuring ShowX from .config section",e);
94  
95 1 throw new ConfigurationException("Exception configuring ShowX "
96   + " from .config section.",e);
97   }
98   }
99  
100   /// <summary>
101   /// Initialize ShowX mapping system by loading configuration from a separate
102   /// ShowX configuration file.
103   /// </summary>
104 7 public static void Configure(string configFileName)
105   {
106 7 try {
107  
108 7 log.Info(string.Format("Configuring ShowX from '{0}'",configFileName));
109  
110 7 XmlDocument config = new XmlDocument();
111 7 config.Load(configFileName);
112  
113 5 XmlNode rootConfigTag = config
114   .SelectSingleNode("//" + XmlConfigurationConst.rootTag);
115  
116 5 ConfigurationSectionInfo settings = XmlConfigurationReader
117   .Read(rootConfigTag);
118  
119 3 createSession(settings);
120   }
121   catch(FileNotFoundException e) {
122  
123 1 string errorMsg = string.Format(
124   "Exception configuring ShowX from file '{0}'.",configFileName);
125  
126 1 log.Fatal(errorMsg,e);
127  
128 1 throw new ConfigurationException(errorMsg,e);
129   }
130   catch (XmlException e) {
131  
132 1 string errorMsg = string.Format(
133   "Exception loading or parsing configuration file '{0}'."
134   ,configFileName);
135  
136 1 log.Fatal(errorMsg,e);
137  
138 1 throw new ConfigurationException(errorMsg,e);
139   }
140   catch (Exception e) {
141  
142 2 log.Fatal("Unexpected configuration exception.",e);
143 2 throw new ConfigurationException("Configuration exception.",e);
144   }
145   }
146  
147  
148   /// <summary>
149   /// Abandon a certain session. After executing this method, a call to
150   /// Configure is needed in order to use ShowX system.
151   /// </summary>
152 16 public static void Abandon()
153   {
154 16 session = null;
155   }
156  
157   /// <summary>
158   /// <p>
159   /// Register a certain type on the XML Session runtime.
160   /// </p>
161   /// <p>
162   /// On the contrary of Attribute session (in wich mapping information is
163   /// obtaining taking as starting point the class itself), ShowX types mapped
164   /// by using XML mapping files need to be registered, in order to be usable.
165   /// This registration should be done only once in the application lifetime.
166   /// Nevetheless, already registered types are ignored by <c>registerClass</c>.
167   /// </p>
168   /// </summary>
169   /// <param name="t">Type to register on XML Session runtime.</param>
170 31 public static void RegisterClass(Type t)
171   {
172 31 if (session is AttributeSession) return;
173  
174 29 try
175   {
176 29 (session as XmlSession).RegisterClass(t);
177   }
178   catch (Exception e) {
179  
180 1 throw new ConfigurationException(String.Format(
181   "Exception registering class '{0}'.",t.Name),e);
182   }
183   }
184  
185   /// <summary>
186   /// Property to retrieve current session.
187   /// </summary>
188   static public ISession Session
189   {
190 3059 get
191   {
192 3059 if (session == null)
193 1 throw new ConfigurationException("Session instance is null."
194   + " You should initialize ShowX session first by using"
195   + " 'Configuration.Configure' method.");
196  
197 3058 return session;
198   }
199   }
200  
201   /// <summary>
202   /// Current mapping model being used by ShowX runtime.
203   /// </summary>
204   public static MappingModel MappingModel
205   {
206 2 get { return mappingModel; }
207   }
208   }
209   }
210