1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using System
.Configuration
;
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
);
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
);