Added RedirectUsingNamedRoute
[castle.git] / InversionOfControl / Castle.MicroKernel / SubSystems / Naming / NamingPartsSubSystem.cs
blobf565c2e3b9623b0d60086830390224eb10492c6a
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.Naming
17 using System;
19 /// <summary>
20 /// Alternative <see cref="INamingSubSystem"/> implementation.
21 /// Extends the default implementation replacing the
22 /// key support with a more complete ComponentName. Supports
23 /// queries.
24 /// </summary>
25 /// <example>
26 /// The user must register components using the following construction
27 /// <code>
28 /// service:properties
29 /// </code>
30 /// Where properties is a list of key value pairs (comma separated). Example:
31 /// <code>
32 /// protocol:secure=true,version=1.2
33 /// </code>
34 /// The user can then query for components using the same construction:
35 /// <code>
36 /// protocol:secure=true
37 /// </code>
38 /// Or to return all:
39 /// <code>
40 /// protocol:*
41 /// </code>
42 /// </example>
43 [Serializable]
44 public class NamingPartsSubSystem : DefaultNamingSubSystem
46 private BinaryTreeComponentName tree;
48 public NamingPartsSubSystem()
50 tree = new BinaryTreeComponentName();
53 private ComponentName ToComponentName(String key)
55 return new ComponentName(key);
58 public override bool Contains(String key)
60 return tree.Contains(ToComponentName(key));
63 public override void UnRegister(String key)
65 tree.Remove(ToComponentName(key));
68 public override IHandler GetHandler(String key)
70 return tree.GetHandler(ToComponentName(key));
73 public override IHandler[] GetHandlers(String query)
75 return tree.GetHandlers(ToComponentName(query));
78 public override IHandler[] GetHandlers()
80 return tree.Handlers;
83 public override IHandler this[String key]
85 set { tree.Add(ToComponentName(key), value); }
88 public override int ComponentCount
90 get { return tree.Count; }