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
;
25 public class ConfigResource
: AbstractResource
27 private readonly XmlNode configSectionNode
;
28 private string sectionName
;
30 public ConfigResource() : this("castle")
34 public ConfigResource(CustomUri uri
) : this(uri
.Host
)
38 public ConfigResource(String sectionName
)
40 this.sectionName
= sectionName
;
42 XmlNode node
= (XmlNode
) ConfigurationManager
.GetSection(sectionName
);
46 String message
= String
.Format(
47 "Could not find section '{0}' in the configuration file associated with this domain.", sectionName
);
48 throw new ConfigurationErrorsException(message
);
51 // TODO: Check whether it's CData section
52 configSectionNode
= node
;
55 public override TextReader
GetStreamReader()
57 return new StringReader(configSectionNode
.OuterXml
);
60 public override TextReader
GetStreamReader(Encoding encoding
)
62 throw new NotSupportedException("Encoding is not supported");
65 public override IResource
CreateRelative(String relativePath
)
67 return new ConfigResource(relativePath
);
70 public override void Dispose()
74 public override string ToString()
76 return String
.Format("ConfigResource: [{0}]", sectionName
);