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
.MicroKernel
.SubSystems
.Configuration
18 using System
.Collections
;
19 using System
.Collections
.Specialized
;
20 using System
.Runtime
.CompilerServices
;
22 using Castle
.Core
.Configuration
;
23 using Castle
.Core
.Resource
;
24 using Castle
.MicroKernel
.SubSystems
.Resource
;
27 /// This implementation of <see cref="IConfigurationStore"/>
28 /// does not try to obtain an external configuration by any means.
29 /// Its only purpose is to serve as a base class for subclasses
30 /// that might obtain the configuration node from anywhere.
33 public class DefaultConfigurationStore
: AbstractSubSystem
, IConfigurationStore
35 private readonly IDictionary childContainers
= new HybridDictionary();
36 private readonly IDictionary facilities
= new HybridDictionary();
37 private readonly IDictionary components
= new HybridDictionary();
38 private readonly IDictionary bootstrapcomponents
= new HybridDictionary();
39 private readonly ArrayList childContainersList
= new ArrayList();
40 private readonly ArrayList facilitiesList
= new ArrayList();
41 private readonly ArrayList componentsList
= new ArrayList();
42 private readonly ArrayList bootstrapComponentsList
= new ArrayList();
45 /// Initializes a new instance of the <see cref="DefaultConfigurationStore"/> class.
47 public DefaultConfigurationStore()
52 /// Associates a configuration node with a facility key
54 /// <param name="key">item key</param>
55 /// <param name="config">Configuration node</param>
56 [MethodImpl(MethodImplOptions
.Synchronized
)]
57 public void AddFacilityConfiguration(String key
, IConfiguration config
)
59 facilitiesList
.Add(config
);
61 facilities
[key
] = config
;
65 /// Associates a configuration node with a component key
67 /// <param name="key">item key</param>
68 /// <param name="config">Configuration node</param>
69 [MethodImpl(MethodImplOptions
.Synchronized
)]
70 public void AddComponentConfiguration(String key
, IConfiguration config
)
72 componentsList
.Add(config
);
74 components
[key
] = config
;
78 /// Associates a configuration node with a bootstrap component key
80 [MethodImpl(MethodImplOptions
.Synchronized
)]
81 public void AddBootstrapComponentConfiguration(string key
, IConfiguration config
)
83 throw new NotImplementedException();
87 /// Adds the child container configuration.
89 /// <param name="key">The key.</param>
90 /// <param name="config">The config.</param>
91 [MethodImpl(MethodImplOptions
.Synchronized
)]
92 public void AddChildContainerConfiguration(String key
, IConfiguration config
)
94 childContainersList
.Add(config
);
96 childContainers
[key
] = config
;
100 /// Returns the configuration node associated with
101 /// the specified facility key. Should return null
102 /// if no association exists.
104 /// <param name="key">item key</param>
105 /// <returns></returns>
106 [MethodImpl(MethodImplOptions
.Synchronized
)]
107 public IConfiguration
GetFacilityConfiguration(String key
)
109 return facilities
[key
] as IConfiguration
;
113 /// Returns the configuration node associated with
114 /// the specified child container key. Should return null
115 /// if no association exists.
117 /// <param name="key">item key</param>
118 /// <returns></returns>
119 [MethodImpl(MethodImplOptions
.Synchronized
)]
120 public IConfiguration
GetChildContainerConfiguration(String key
)
122 return childContainers
[key
] as IConfiguration
;
126 /// Returns the configuration node associated with
127 /// the specified component key. Should return null
128 /// if no association exists.
130 /// <param name="key">item key</param>
131 /// <returns></returns>
132 [MethodImpl(MethodImplOptions
.Synchronized
)]
133 public IConfiguration
GetComponentConfiguration(String key
)
135 return components
[key
] as IConfiguration
;
139 /// Returns the configuration node associated with
140 /// the specified component key. Should return null
141 /// if no association exists.
143 /// <param name="key"></param>
144 /// <returns></returns>
145 [MethodImpl(MethodImplOptions
.Synchronized
)]
146 public IConfiguration
GetBootstrapComponentConfiguration(string key
)
148 return bootstrapcomponents
[key
] as IConfiguration
;
152 /// Returns all configuration nodes for facilities
154 /// <returns></returns>
155 [MethodImpl(MethodImplOptions
.Synchronized
)]
156 public IConfiguration
[] GetFacilities()
158 return (IConfiguration
[]) facilitiesList
.ToArray(typeof(IConfiguration
));
162 /// Returns all configuration nodes for bootstrap components
164 /// <returns></returns>
165 [MethodImpl(MethodImplOptions
.Synchronized
)]
166 public IConfiguration
[] GetBootstrapComponents()
168 return (IConfiguration
[]) bootstrapComponentsList
.ToArray(typeof(IConfiguration
));
172 /// Returns all configuration nodes for child containers
174 /// <returns></returns>
175 [MethodImpl(MethodImplOptions
.Synchronized
)]
176 public IConfiguration
[] GetConfigurationForChildContainers()
178 return (IConfiguration
[]) childContainersList
.ToArray(typeof(IConfiguration
));
182 /// Returns all configuration nodes for components
184 /// <returns></returns>
185 [MethodImpl(MethodImplOptions
.Synchronized
)]
186 public IConfiguration
[] GetComponents()
188 return (IConfiguration
[]) componentsList
.ToArray(typeof(IConfiguration
));
191 public IResource
GetResource(String resourceUri
, IResource resource
)
193 if (resourceUri
.IndexOf(Uri
.SchemeDelimiter
) == -1)
195 return resource
.CreateRelative(resourceUri
);
198 IResourceSubSystem subSystem
= (IResourceSubSystem
)
199 Kernel
.GetSubSystem(SubSystemConstants
.ResourceKey
);
201 return subSystem
.CreateResource(resourceUri
, resource
.FileBasePath
);