[Http]: Clear the 'SendChunked' flag when redirecting.
[mono.git] / mcs / class / System / System.CodeDom.Compiler / CompilerCollection.cs
1 //
2 // System.Web.Configuration.CompilerCollection
3 //
4 // Authors:
5 //      Chris Toshok (toshok@ximian.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if CONFIGURATION_DEP
32
33 using System;
34 using System.Collections.Generic;
35 using System.Configuration;
36
37 namespace System.CodeDom.Compiler
38 {
39         [ConfigurationCollection (typeof (Compiler), AddItemName = "compiler", CollectionType = ConfigurationElementCollectionType.BasicMap)]
40         internal sealed class CompilerCollection : ConfigurationElementCollection
41         {
42 #if NET_4_0
43                 static readonly string defaultCompilerVersion = "3.5";
44 #else
45                 static readonly string defaultCompilerVersion = "2.0";
46 #endif
47                 static ConfigurationPropertyCollection properties;
48                 static List <CompilerInfo> compiler_infos;
49                 static Dictionary <string, CompilerInfo> compiler_languages;
50                 static Dictionary <string, CompilerInfo> compiler_extensions;
51                 
52                 static CompilerCollection ()
53                 {
54                         properties = new ConfigurationPropertyCollection ();
55                         compiler_infos = new List <CompilerInfo> ();
56                         compiler_languages = new Dictionary <string, CompilerInfo> (16, StringComparer.OrdinalIgnoreCase);
57                         compiler_extensions = new Dictionary <string, CompilerInfo> (6, StringComparer.OrdinalIgnoreCase);
58                                 
59                         CompilerInfo compiler = new CompilerInfo ();
60                         compiler.Languages = "c#;cs;csharp";
61                         compiler.Extensions = ".cs";
62                         compiler.TypeName = "Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
63                         compiler.ProviderOptions = new Dictionary <string, string> (1);
64                         compiler.ProviderOptions ["CompilerVersion"] = defaultCompilerVersion;
65                         AddCompilerInfo (compiler);
66
67                         compiler = new CompilerInfo ();
68                         compiler.Languages = "vb;vbs;visualbasic;vbscript";
69                         compiler.Extensions = ".vb";
70                         compiler.TypeName = "Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
71                         compiler.ProviderOptions = new Dictionary <string, string> (1);
72                         compiler.ProviderOptions ["CompilerVersion"] = defaultCompilerVersion;
73                         AddCompilerInfo (compiler);
74
75                         compiler = new CompilerInfo ();
76                         compiler.Languages = "js;jscript;javascript";
77                         compiler.Extensions = ".js";
78                         compiler.TypeName = "Microsoft.JScript.JScriptCodeProvider, Microsoft.JScript, Version=8.0.1100.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
79                         compiler.ProviderOptions = new Dictionary <string, string> (1);
80                         compiler.ProviderOptions ["CompilerVersion"] = defaultCompilerVersion;
81                         AddCompilerInfo (compiler);
82
83                         compiler = new CompilerInfo ();
84                         compiler.Languages = "vj#;vjs;vjsharp";
85                         compiler.Extensions = ".jsl;.java";
86                         compiler.TypeName = "Microsoft.VJSharp.VJSharpCodeProvider, VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
87                         compiler.ProviderOptions = new Dictionary <string, string> (1);
88                         compiler.ProviderOptions ["CompilerVersion"] = defaultCompilerVersion;
89                         AddCompilerInfo (compiler);
90
91                         compiler = new CompilerInfo ();
92                         compiler.Languages = "c++;mc;cpp";
93                         compiler.Extensions = ".h";
94                         compiler.TypeName = "Microsoft.VisualC.CppCodeProvider, CppCodeProvider, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
95                         compiler.ProviderOptions = new Dictionary <string, string> (1);
96                         compiler.ProviderOptions ["CompilerVersion"] = defaultCompilerVersion;
97                         AddCompilerInfo (compiler);
98                 }
99
100                 public CompilerCollection ()
101                 {
102                 }
103
104                 static void AddCompilerInfo (CompilerInfo ci)
105                 {
106                         ci.Init ();
107                         compiler_infos.Add (ci);
108
109                         string[] languages = ci.GetLanguages ();
110                         if (languages != null)
111                                 foreach (string language in languages)
112                                         compiler_languages [language] = ci;
113                         
114                         string[] extensions = ci.GetExtensions ();
115                         if (extensions != null)
116                                 foreach (string extension in extensions)
117                                         compiler_extensions [extension] = ci;
118                 }
119
120                 static void AddCompilerInfo (Compiler compiler)
121                 {
122                         CompilerInfo ci = new CompilerInfo ();
123                         ci.Languages = compiler.Language;
124                         ci.Extensions = compiler.Extension;
125                         ci.TypeName = compiler.Type;
126                         ci.ProviderOptions = compiler.ProviderOptionsDictionary;
127                         ci.CompilerOptions = compiler.CompilerOptions;
128                         ci.WarningLevel = compiler.WarningLevel;
129                         AddCompilerInfo (ci);
130                 }
131                 
132                 protected override void BaseAdd (ConfigurationElement element)
133                 {
134                         Compiler compiler = element as Compiler;
135                         if (compiler != null)
136                                 AddCompilerInfo (compiler);
137                         base.BaseAdd (element);
138                 }
139                 
140                 protected override bool ThrowOnDuplicate {
141                         get { return false; }
142                 }
143                 
144                 protected override ConfigurationElement CreateNewElement ()
145                 {
146                         return new Compiler ();
147                 }
148
149                 public CompilerInfo GetCompilerInfoForLanguage (string language)
150                 {
151                         if (compiler_languages.Count == 0)
152                                 return null;
153                         
154                         CompilerInfo ci;
155                         if (compiler_languages.TryGetValue (language, out ci))
156                                 return ci;
157                         
158                         return null;
159                 }
160
161                 public CompilerInfo GetCompilerInfoForExtension (string extension)
162                 {
163                         if (compiler_extensions.Count == 0)
164                                 return null;
165                         
166                         CompilerInfo ci;
167                         if (compiler_extensions.TryGetValue (extension, out ci))
168                                 return ci;
169                         
170                         return null;
171                 }
172
173                 public string GetLanguageFromExtension (string extension)
174                 {
175                         CompilerInfo ci = GetCompilerInfoForExtension (extension);
176                         if (ci == null)
177                                 return null;
178                         string[] languages = ci.GetLanguages ();
179                         if (languages != null && languages.Length > 0)
180                                 return languages [0];
181                         return null;
182                 }
183                 
184                 public Compiler Get (int index)
185                 {
186                         return (Compiler) BaseGet (index);
187                 }
188
189                 public Compiler Get (string language)
190                 {
191                         return (Compiler) BaseGet (language);
192                 }
193
194                 protected override object GetElementKey (ConfigurationElement element)
195                 {
196                         return ((Compiler)element).Language;
197                 }
198
199                 public string GetKey (int index)
200                 {
201                         return (string)BaseGetKey (index);
202                 }
203
204                 public string[ ] AllKeys {
205                         get {
206                                 string[] keys = new string[compiler_infos.Count];
207                                 for (int i = 0; i < Count; i++)
208                                         keys[i] = compiler_infos[i].Languages;
209                                 return keys;
210                         }
211                 }
212                 
213                 public override ConfigurationElementCollectionType CollectionType {
214                         get { return ConfigurationElementCollectionType.BasicMap; }
215                 }
216
217                 protected override string ElementName {
218                         get { return "compiler"; }
219                 }
220
221                 protected override ConfigurationPropertyCollection Properties {
222                         get { return properties; }
223                 }
224
225                 public Compiler this[int index] {
226                         get { return (Compiler) BaseGet (index); }
227                 }
228
229                 public new CompilerInfo this[string language] {
230                         get {
231                                 return GetCompilerInfoForLanguage (language);
232                         }
233                 }
234
235                 public CompilerInfo[] CompilerInfos {
236                         get {
237                                 return compiler_infos.ToArray ();
238                         }
239                 }
240         }
241 }
242 #endif