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
.Registration
18 using Castle
.Core
.Configuration
;
23 /// Represents a configuration child.
25 public abstract class Node
27 private readonly String name
;
29 protected Node(String name
)
40 /// Applies the configuration node.
42 /// <param name="configuration">The configuration.</param>
43 public abstract void ApplyTo(IConfiguration configuration
);
51 /// Represents a configuration attribute.
53 public class Attribute
: Node
55 private readonly String
value;
57 internal Attribute(String name
, String
value)
64 /// Applies the configuration node.
66 /// <param name="configuration">The configuration.</param>
67 public override void ApplyTo(IConfiguration configuration
)
69 configuration
.Attributes
.Add(Name
, value);
73 /// Create a <see cref="NamedAttribute"/> with name.
75 /// <param name="name">The attribute name.</param>
76 /// <returns>The new <see cref="NamedAttribute"/></returns>
77 public static NamedAttribute
ForName(String name
)
79 return new NamedAttribute(name
);
88 /// Represents a named attribute.
90 public class NamedAttribute
92 private readonly String name
;
94 internal NamedAttribute(String name
)
100 /// Builds the <see cref="Attribute"/> with name/value.
102 /// <param name="value">The attribute value.</param>
103 /// <returns>The new <see cref="SimpleChild"/></returns>
104 public Attribute
Eq(String
value)
106 return new Attribute(name
, value);
115 /// Represents a configuration child.
117 public abstract class Child
120 /// Create a <see cref="NamedChild"/> with name.
122 /// <param name="name">The child name.</param>
123 /// <returns>The new <see cref="NamedChild"/></returns>
124 public static NamedChild
ForName(String name
)
126 return new NamedChild(name
);
135 /// Represents a named child.
137 public class NamedChild
: Node
139 internal NamedChild(String name
)
145 /// Builds the <see cref="SimpleChild"/> with name/value.
147 /// <param name="value">The child value.</param>
148 /// <returns>The new <see cref="SimpleChild"/></returns>
149 public SimpleChild
Eq(String
value)
151 return new SimpleChild(Name
, value);
155 /// Builds the <see cref="ComplexChild"/> with name/config.
157 /// <param name="configNode">The child configuration.</param>
158 /// <returns>The new <see cref="ComplexChild"/></returns>
159 public ComplexChild
Eq(IConfiguration configNode
)
161 return new ComplexChild(Name
, configNode
);
165 /// Builds the <see cref="Child"/> with name/config.
167 /// <param name="childNodes">The child nodes.</param>
168 /// <returns>The new <see cref="CompoundChild"/></returns>
169 public CompoundChild
Eq(params Node
[] childNodes
)
171 return new CompoundChild(Name
, childNodes
);
175 /// Applies the configuration node.
177 /// <param name="configuration">The configuration.</param>
178 public override void ApplyTo(IConfiguration configuration
)
180 MutableConfiguration node
= new MutableConfiguration(Name
);
181 configuration
.Children
.Add(node
);
190 /// Represents a simple child node.
192 public class SimpleChild
: Node
194 private readonly String
value;
196 internal SimpleChild(String name
, String
value)
203 /// Applies the configuration node.
205 /// <param name="configuration">The configuration.</param>
206 public override void ApplyTo(IConfiguration configuration
)
208 MutableConfiguration node
= new MutableConfiguration(Name
, value);
209 configuration
.Children
.Add(node
);
218 /// Represents a complex child node.
220 public class ComplexChild
: Node
222 private readonly IConfiguration configNode
;
224 internal ComplexChild(String name
, IConfiguration configNode
)
227 this.configNode
= configNode
;
231 /// Applies the configuration node.
233 /// <param name="configuration">The configuration.</param>
234 public override void ApplyTo(IConfiguration configuration
)
236 MutableConfiguration node
= new MutableConfiguration(Name
);
237 node
.Children
.Add(configNode
);
238 configuration
.Children
.Add(node
);
244 #region CompoundChild
247 /// Represents a compound child node.
249 public class CompoundChild
: Node
251 private readonly Node
[] childNodes
;
253 internal CompoundChild(String name
, Node
[] childNodes
)
256 this.childNodes
= childNodes
;
260 /// Applies the configuration node.
262 /// <param name="configuration">The configuration.</param>
263 public override void ApplyTo(IConfiguration configuration
)
265 MutableConfiguration node
= new MutableConfiguration(Name
);
266 foreach (Node childNode
in childNodes
)
268 childNode
.ApplyTo( node
);
270 configuration
.Children
.Add(node
);