Fixing an issue with output parameters that are of type IntPtr
[castle.git] / InversionOfControl / Castle.MicroKernel / SubSystems / Configuration / DefaultConfigurationStore.cs
blobd87625ae98418e517f15e38113a752e7186e747d
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.MicroKernel.SubSystems.Configuration
17 using System;
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;
26 /// <summary>
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.
31 /// </summary>
32 [Serializable]
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();
44 /// <summary>
45 /// Initializes a new instance of the <see cref="DefaultConfigurationStore"/> class.
46 /// </summary>
47 public DefaultConfigurationStore()
51 /// <summary>
52 /// Associates a configuration node with a facility key
53 /// </summary>
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;
64 /// <summary>
65 /// Associates a configuration node with a component key
66 /// </summary>
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;
77 /// <summary>
78 /// Associates a configuration node with a bootstrap component key
79 /// </summary>
80 [MethodImpl(MethodImplOptions.Synchronized)]
81 public void AddBootstrapComponentConfiguration(string key, IConfiguration config)
83 throw new NotImplementedException();
86 /// <summary>
87 /// Adds the child container configuration.
88 /// </summary>
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;
99 /// <summary>
100 /// Returns the configuration node associated with
101 /// the specified facility key. Should return null
102 /// if no association exists.
103 /// </summary>
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;
112 /// <summary>
113 /// Returns the configuration node associated with
114 /// the specified child container key. Should return null
115 /// if no association exists.
116 /// </summary>
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;
125 /// <summary>
126 /// Returns the configuration node associated with
127 /// the specified component key. Should return null
128 /// if no association exists.
129 /// </summary>
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;
138 /// <summary>
139 /// Returns the configuration node associated with
140 /// the specified component key. Should return null
141 /// if no association exists.
142 /// </summary>
143 /// <param name="key"></param>
144 /// <returns></returns>
145 [MethodImpl(MethodImplOptions.Synchronized)]
146 public IConfiguration GetBootstrapComponentConfiguration(string key)
148 return bootstrapcomponents[key] as IConfiguration;
151 /// <summary>
152 /// Returns all configuration nodes for facilities
153 /// </summary>
154 /// <returns></returns>
155 [MethodImpl(MethodImplOptions.Synchronized)]
156 public IConfiguration[] GetFacilities()
158 return (IConfiguration[]) facilitiesList.ToArray(typeof(IConfiguration));
161 /// <summary>
162 /// Returns all configuration nodes for bootstrap components
163 /// </summary>
164 /// <returns></returns>
165 [MethodImpl(MethodImplOptions.Synchronized)]
166 public IConfiguration[] GetBootstrapComponents()
168 return (IConfiguration[]) bootstrapComponentsList.ToArray(typeof(IConfiguration));
171 /// <summary>
172 /// Returns all configuration nodes for child containers
173 /// </summary>
174 /// <returns></returns>
175 [MethodImpl(MethodImplOptions.Synchronized)]
176 public IConfiguration[] GetConfigurationForChildContainers()
178 return (IConfiguration[]) childContainersList.ToArray(typeof(IConfiguration));
181 /// <summary>
182 /// Returns all configuration nodes for components
183 /// </summary>
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);