Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Configuration / JSGeneratorConfiguration.cs
blob911f8e4363e7277fed568a42659378a2cd4bf621
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.MonoRail.Framework.Configuration
17 using System;
18 using System.Collections.Generic;
20 /// <summary>
21 /// Pendent
22 /// </summary>
23 public class JSGeneratorConfiguration
25 private readonly List<LibraryConfiguration> libraries = new List<LibraryConfiguration>();
26 private LibraryConfiguration defaultLibrary;
28 /// <summary>
29 /// Adds the library.
30 /// </summary>
31 /// <param name="name">The name.</param>
32 /// <param name="mainGenerator">The main generator.</param>
33 /// <returns></returns>
34 public LibraryConfigurationBuilder AddLibrary(string name, Type mainGenerator)
36 LibraryConfiguration config = new LibraryConfiguration(name, mainGenerator);
37 libraries.Add(config);
39 return new LibraryConfigurationBuilder(this, config);
42 /// <summary>
43 /// Gets the libraries configuration.
44 /// </summary>
45 /// <value>The libraries.</value>
46 public List<LibraryConfiguration> Libraries
48 get { return libraries; }
51 /// <summary>
52 /// Gets the default library configuration.
53 /// </summary>
54 /// <value>The default library.</value>
55 public LibraryConfiguration DefaultLibrary
57 get { return defaultLibrary; }
60 /// <summary>
61 /// Configures a JS generator for specific JS library
62 /// </summary>
63 public class LibraryConfigurationBuilder
65 private readonly JSGeneratorConfiguration configuration;
66 private readonly LibraryConfiguration config;
67 private readonly ElementGeneratorConfigBuilder elementConfig;
69 /// <summary>
70 /// Initializes a new instance of the <see cref="LibraryConfigurationBuilder"/> class.
71 /// </summary>
72 /// <param name="configuration">The configuration.</param>
73 /// <param name="config">The config.</param>
74 public LibraryConfigurationBuilder(JSGeneratorConfiguration configuration, LibraryConfiguration config)
76 this.configuration = configuration;
77 this.config = config;
78 elementConfig = new ElementGeneratorConfigBuilder(this);
81 /// <summary>
82 /// Adds an extension.
83 /// </summary>
84 /// <param name="extensionType">Type of the extension.</param>
85 /// <returns></returns>
86 public LibraryConfigurationBuilder AddExtension(Type extensionType)
88 config.MainExtensions.Add(extensionType);
89 return this;
92 /// <summary>
93 /// Sets the browser validator provider for the library
94 /// </summary>
95 /// <param name="browserValidatorProvider">The browser validator provider.</param>
96 public LibraryConfigurationBuilder BrowserValidatorIs(Type browserValidatorProvider)
98 config.BrowserValidatorProvider = browserValidatorProvider;
99 return this;
102 /// <summary>
103 /// Gets the element generator.
104 /// </summary>
105 /// <value>The element generator.</value>
106 public ElementGeneratorConfigBuilder ElementGenerator
108 get { return elementConfig; }
111 /// <summary>
112 /// Sets this JS library as the default one.
113 /// </summary>
114 public void SetAsDefault()
116 configuration.defaultLibrary = config;
119 /// <summary>
120 /// Configures the element section of the library config
121 /// </summary>
122 public class ElementGeneratorConfigBuilder
124 private readonly LibraryConfigurationBuilder builder;
126 /// <summary>
127 /// Initializes a new instance of the <see cref="ElementGeneratorConfigBuilder"/> class.
128 /// </summary>
129 /// <param name="builder">The builder.</param>
130 public ElementGeneratorConfigBuilder(LibraryConfigurationBuilder builder)
132 this.builder = builder;
135 /// <summary>
136 /// Adds an element only extension.
137 /// </summary>
138 /// <param name="extensionType">Type of the extension.</param>
139 /// <returns></returns>
140 public ElementGeneratorConfigBuilder AddExtension(Type extensionType)
142 builder.config.ElementExtension.Add(extensionType);
143 return this;
146 /// <summary>
147 /// Go back to the main library configuration
148 /// </summary>
149 public LibraryConfigurationBuilder Done
151 get { return builder; }
157 /// <summary>
158 /// Configuration for JS generation for an specific JS library
159 /// </summary>
160 public class LibraryConfiguration
162 private readonly string name;
163 private readonly Type mainGenerator;
164 private readonly List<Type> mainExtensions = new List<Type>();
165 private readonly List<Type> elementExtension = new List<Type>();
166 private Type browserValidatorProvider;
168 /// <summary>
169 /// Initializes a new instance of the <see cref="LibraryConfiguration"/> class.
170 /// </summary>
171 /// <param name="name">The name.</param>
172 /// <param name="mainGenerator">The main generator.</param>
173 public LibraryConfiguration(string name, Type mainGenerator)
175 if (string.IsNullOrEmpty(name))
177 throw new ArgumentNullException("name");
179 if (mainGenerator == null)
181 throw new ArgumentNullException("mainGenerator");
184 this.name = name;
185 this.mainGenerator = mainGenerator;
188 /// <summary>
189 /// Gets the name.
190 /// </summary>
191 /// <value>The name.</value>
192 public string Name
194 get { return name; }
197 /// <summary>
198 /// Gets the main generator.
199 /// </summary>
200 /// <value>The main generator.</value>
201 public Type MainGenerator
203 get { return mainGenerator; }
206 /// <summary>
207 /// Gets the main extensions.
208 /// </summary>
209 /// <value>The main extensions.</value>
210 public List<Type> MainExtensions
212 get { return mainExtensions; }
215 /// <summary>
216 /// Gets the element extension.
217 /// </summary>
218 /// <value>The element extension.</value>
219 public List<Type> ElementExtension
221 get { return elementExtension; }
224 /// <summary>
225 /// Gets or sets the browser validator provider.
226 /// </summary>
227 /// <value>The browser validator provider.</value>
228 public Type BrowserValidatorProvider
230 get { return browserValidatorProvider; }
231 set { browserValidatorProvider = value; }