Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / Core / Castle.Core / Resource / ConfigResource.cs
bloba51a9627c89d869f6745e9e6b2e4a24f2f97911b
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Core.Resource
17 using System;
18 using System.Configuration;
19 using System.IO;
20 using System.Text;
21 using System.Xml;
23 public class ConfigResource : AbstractResource
25 private readonly XmlNode configSectionNode;
26 private string sectionName;
28 public ConfigResource() : this("castle")
32 public ConfigResource(CustomUri uri) : this(uri.Host)
36 public ConfigResource(String sectionName)
38 this.sectionName = sectionName;
40 XmlNode node = (XmlNode) ConfigurationManager.GetSection(sectionName);
42 if (node == null)
44 String message = String.Format(
45 "Could not find section '{0}' in the configuration file associated with this domain.", sectionName);
46 throw new ConfigurationErrorsException(message);
49 // TODO: Check whether it's CData section
50 configSectionNode = node;
53 public override TextReader GetStreamReader()
55 return new StringReader(configSectionNode.OuterXml);
58 public override TextReader GetStreamReader(Encoding encoding)
60 throw new NotSupportedException("Encoding is not supported");
63 public override IResource CreateRelative(String relativePath)
65 return new ConfigResource(relativePath);
68 public override void Dispose()
72 public override string ToString()
74 return String.Format("ConfigResource: [{0}]", sectionName);