Clover.NET coverage report - Coverage for s2container.net

Coverage timestamp: 2006年5月30日 11:21:29

File Stats: LOC: 131   Methods: 6
NCLOC: 104 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Framework.Container\Factory\S2ContainerFactory.cs 50.0% 78.0% 83.3% 72.9%
coverage coverage
1   #region Copyright
2   /*
3   * Copyright 2005 the Seasar Foundation and the Others.
4   *
5   * Licensed under the Apache License, Version 2.0 (the "License");
6   * you may not use this file except in compliance with the License.
7   * You may obtain a copy of the License at
8   *
9   * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14   * either express or implied. See the License for the specific language
15   * governing permissions and limitations under the License.
16   */
17   #endregion
18  
19   using System;
20   using System.Collections;
21   using System.Globalization;
22   using System.Reflection;
23   using System.Resources;
24   using Seasar.Framework.Util;
25   using Seasar.Framework.Xml;
26  
27   namespace Seasar.Framework.Container.Factory
28   {
29   /// <summary>
30   /// S2ContainerFactory の概要の説明です。
31   /// </summary>
32   public sealed class S2ContainerFactory
33   {
34   public const string PUBLIC_ID = "-//SEASAR//DTD S2Container//EN";
35   public const string DTD_PATH = "components.dtd";
36   public const string BUILDER_CONFIG_PATH = "s2containerbuilder";
37   private static ResourceSet builderProps_;
38   private static Hashtable builders_ = new Hashtable();
39   private static IS2ContainerBuilder defaultBuilder_ =
40   new XmlS2ContainerBuilder();
41  
42 1 static S2ContainerFactory()
43   {
44 1 try
45   {
46 1 builderProps_ = new ResourceManager(BUILDER_CONFIG_PATH,
47   Assembly.GetExecutingAssembly()).GetResourceSet(
48   CultureInfo.CurrentCulture,true,true);
49   }
50   catch(MissingManifestResourceException)
51   {
52   }
53 1 builders_.Add("xml",defaultBuilder_);
54 1 builders_.Add("dicon",defaultBuilder_);
55   }
56  
57 0 private S2ContainerFactory()
58   {
59   }
60  
61 76 public static IS2Container Create(string path)
62   {
63 76 string ext = GetExtension(path);
64 76 S2Section config = S2SectionHandler.GetS2Section();
65 76 if(config != null)
66   {
67 76 IList assemblys = config.Assemblys;
68 76 foreach(string assembly in assemblys)
69   {
70 228 if(!StringUtil.IsEmpty(assembly)) AppDomain.CurrentDomain.Load(assembly);
71   }
72   }
73 76 IS2Container container = GetBuilder(ext).Build(path);
74 76 return container;
75   }
76  
77 68 public static IS2Container Include(IS2Container parent,string path)
78   {
79 68 IS2Container root = parent.Root;
80 68 IS2Container child = null;
81 68 lock(root)
82   {
83 68 if(root.HasDescendant(path))
84   {
85 4 child = root.GetDescendant(path);
86 4 parent.Include(child);
87   }
88   else
89   {
90 64 string ext = GetExtension(path);
91 64 IS2ContainerBuilder builder = GetBuilder(ext);
92 64 child = builder.Include(parent,path);
93 64 root.RegisterDescendant(child);
94   }
95   }
96 68 return child;
97   }
98  
99 140 private static string GetExtension(string path)
100   {
101 140 string ext = ResourceUtil.GetExtension(path);
102 0 if(ext == null) throw new ExtensionNotFoundRuntimeException(path);
103 140 return ext;
104   }
105  
106 140 private static IS2ContainerBuilder GetBuilder(string ext)
107   {
108 140 IS2ContainerBuilder builder = null;
109 140 lock(builders_)
110   {
111 140 builder = (IS2ContainerBuilder) builders_[ext];
112 140 if(builder != null) return builder;
113 0 string className = builderProps_.GetString(ext);
114 0 if(className != null)
115   {
116   Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies();
117   Type type = ClassUtil.ForName(className, asms);
118   builder = (IS2ContainerBuilder)
119   ClassUtil.NewInstance(type);
120   builders_[ext] = builder;
121   }
122   else
123   {
124   builder = defaultBuilder_;
125   }
126   }
127 0 return builder;
128   }
129   }
130   }
131