2007-01-31 Igor Zelmanovich <igorz@mainsoft.com>
[mono.git] / mcs / class / System.Web / System.Web.Compilation / AspComponentFoundry.cs
index abc43a3e94bb113f9a95197c21d75433baecab1b..c05c719fd66ef6100662c052245a13af1f54b803 100644 (file)
-//\r
-// System.Web.Compilation.AspComponentFoundry\r
-//\r
-// Authors:\r
-//     Gonzalo Paniagua Javier (gonzalo@ximian.com)\r
-//\r
-// (C) 2002,2003 Ximian, Inc (http://www.ximian.com)\r
-//\r
-using System;\r
-using System.Collections;\r
-using System.IO;\r
-using System.Reflection;\r
-\r
-namespace System.Web.Compilation\r
-{\r
-       internal class AspComponentFoundry\r
-       {\r
-               private Hashtable foundries;\r
-\r
-               public AspComponentFoundry ()\r
-               {\r
-                       foundries = new Hashtable (CaseInsensitiveHashCodeProvider.Default,\r
-                                                  CaseInsensitiveComparer.Default);\r
-\r
-                       Assembly sw = typeof (AspComponentFoundry).Assembly;\r
-                       RegisterFoundry ("asp", sw, "System.Web.UI.WebControls");\r
-                       RegisterFoundry ("", "object", typeof (System.Web.UI.ObjectTag));\r
-               }\r
-\r
-               public Type GetComponentType (string foundryName, string tag)\r
-               {\r
-                       Foundry foundry = foundries [foundryName] as Foundry;\r
-                       if (foundry == null)\r
-                               return null;\r
-\r
-                       return foundry.GetType (tag);\r
-               }\r
-\r
-               public void RegisterFoundry (string foundryName,\r
-                                               Assembly assembly,\r
-                                               string nameSpace)\r
-               {\r
-                       AssemblyFoundry foundry = new AssemblyFoundry (assembly, nameSpace);\r
-                       InternalRegister (foundryName, foundry);\r
-               }\r
-\r
-               public void RegisterFoundry (string foundryName,\r
-                                               string tagName,\r
-                                               Type type)\r
-               {\r
-                       TagNameFoundry foundry = new TagNameFoundry (tagName, type);\r
-                       InternalRegister (foundryName, foundry);\r
-               }\r
-\r
-               void InternalRegister (string foundryName, Foundry foundry)\r
-               {\r
-                       object f = foundries [foundryName];\r
-                       if (f is CompoundFoundry) {\r
-                               ((CompoundFoundry) f).Add (foundry);\r
-                       } else if (f == null || (f is AssemblyFoundry && foundry is AssemblyFoundry)) {\r
-                               // If more than 1 namespace/assembly specified, the last one is used.\r
-                               foundries [foundryName] = foundry;\r
-                       } else if (f != null) {\r
-                               CompoundFoundry compound = new CompoundFoundry (foundryName);\r
-                               compound.Add ((Foundry) f);\r
-                               compound.Add (foundry);\r
-                               foundries [foundryName] = compound;\r
-                       }\r
-               }\r
-\r
-               public bool LookupFoundry (string foundryName)\r
-               {\r
-                       return foundries.Contains (foundryName);\r
-               }\r
-\r
-               abstract class Foundry\r
-               {\r
-                       public abstract Type GetType (string componentName);\r
-               }\r
-               \r
-\r
-               class TagNameFoundry : Foundry\r
-               {\r
-                       string tagName;\r
-                       Type type;\r
-\r
-                       public TagNameFoundry (string tagName, Type type)\r
-                       {\r
-                               this.tagName = tagName;\r
-                               this.type = type;\r
-                       }\r
-\r
-                       public override Type GetType (string componentName)\r
-                       {\r
-                               if (0 != String.Compare (componentName, tagName, true))\r
-                                       return null;\r
-                               \r
-                               return type;\r
-                       }\r
-\r
-                       public string TagName {\r
-                               get { return tagName; }\r
-                       }\r
-               }\r
-\r
-               class AssemblyFoundry : Foundry\r
-               {\r
-                       string nameSpace;\r
-                       Assembly assembly;\r
-\r
-                       public AssemblyFoundry (Assembly assembly, string nameSpace)\r
-                       {\r
-                               this.assembly = assembly;\r
-                               this.nameSpace = nameSpace;\r
-                       }\r
-\r
-                       public override Type GetType (string componentName)\r
-                       {\r
-                               return assembly.GetType (nameSpace + "." + componentName, true, true);\r
-                       }\r
-               }\r
-\r
-               class CompoundFoundry : Foundry\r
-               {\r
-                       AssemblyFoundry assemblyFoundry;\r
-                       Hashtable tagnames;\r
-                       string tagPrefix;\r
-\r
-                       public CompoundFoundry (string tagPrefix)\r
-                       {\r
-                               this.tagPrefix = tagPrefix;\r
-                               tagnames = new Hashtable (CaseInsensitiveHashCodeProvider.Default,\r
-                                                          CaseInsensitiveComparer.Default);\r
-                       }\r
-\r
-                       public void Add (Foundry foundry)\r
-                       {\r
-                               if (foundry is AssemblyFoundry) {\r
-                                       assemblyFoundry = (AssemblyFoundry) foundry;\r
-                                       return;\r
-                               }\r
-                               \r
-                               TagNameFoundry tn = (TagNameFoundry) foundry;\r
-                               string tagName = tn.TagName;\r
-                               if (tagnames.Contains (tagName)) {\r
-                                       string msg = String.Format ("{0}:{1} already registered.", tagPrefix, tagName);\r
-                                       throw new ApplicationException (msg);\r
-                               }\r
-                               tagnames.Add (tagName, foundry);\r
-                       }\r
-\r
-                       public override Type GetType (string componentName)\r
-                       {\r
-                               Type type = null;\r
-                               if (assemblyFoundry != null) {\r
-                                       try {\r
-                                               type = assemblyFoundry.GetType (componentName);\r
-                                               return type;\r
-                                       } catch { }\r
-                               }\r
-\r
-                               Foundry foundry = tagnames [componentName] as Foundry;\r
-                               if (foundry == null) {\r
-                                       string msg = String.Format ("Type {0} not registered for prefix {1}",\r
-                                                                    componentName, tagPrefix);\r
-                                       throw new ApplicationException (msg);\r
-                               }\r
-\r
-                               return foundry.GetType (componentName);\r
-                       }\r
-               }\r
-       }\r
-}\r
-\r
+//
+// System.Web.Compilation.AspComponentFoundry
+//
+// Authors:
+//     Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Collections;
+using System.IO;
+using System.Reflection;
+
+namespace System.Web.Compilation
+{
+       internal class AspComponentFoundry
+       {
+               private Hashtable foundries;
+
+               public AspComponentFoundry ()
+               {
+#if NET_2_0
+                       foundries = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
+#else
+                       foundries = new Hashtable (CaseInsensitiveHashCodeProvider.DefaultInvariant,
+                                                  CaseInsensitiveComparer.DefaultInvariant);
+#endif
+
+                       Assembly sw = typeof (AspComponentFoundry).Assembly;
+                       RegisterFoundry ("asp", sw, "System.Web.UI.WebControls");
+                       RegisterFoundry ("", "object", typeof (System.Web.UI.ObjectTag));
+               }
+
+               public Type GetComponentType (string foundryName, string tag)
+               {
+                       Foundry foundry = foundries [foundryName] as Foundry;
+                       if (foundry == null)
+                               return null;
+
+                       return foundry.GetType (tag);
+               }
+
+               public void RegisterFoundry (string foundryName,
+                                               Assembly assembly,
+                                               string nameSpace)
+               {
+                       AssemblyFoundry foundry = new AssemblyFoundry (assembly, nameSpace);
+                       InternalRegister (foundryName, foundry);
+               }
+
+               public void RegisterFoundry (string foundryName,
+                                               string tagName,
+                                               Type type)
+               {
+                       TagNameFoundry foundry = new TagNameFoundry (tagName, type);
+                       InternalRegister (foundryName, foundry);
+               }
+
+               void InternalRegister (string foundryName, Foundry foundry)
+               {
+                       object f = foundries [foundryName];
+                       if (f is CompoundFoundry) {
+                               ((CompoundFoundry) f).Add (foundry);
+                       } else if (f == null || (f is AssemblyFoundry && foundry is AssemblyFoundry)) {
+                               // If more than 1 namespace/assembly specified, the last one is used.
+                               foundries [foundryName] = foundry;
+                       } else if (f != null) {
+                               CompoundFoundry compound = new CompoundFoundry (foundryName);
+                               compound.Add ((Foundry) f);
+                               compound.Add (foundry);
+                               foundries [foundryName] = compound;
+                       }
+               }
+
+               public bool LookupFoundry (string foundryName)
+               {
+                       return foundries.Contains (foundryName);
+               }
+
+               abstract class Foundry
+               {
+                       public abstract Type GetType (string componentName);
+               }
+               
+
+               class TagNameFoundry : Foundry
+               {
+                       string tagName;
+                       Type type;
+
+                       public TagNameFoundry (string tagName, Type type)
+                       {
+                               this.tagName = tagName;
+                               this.type = type;
+                       }
+
+                       public override Type GetType (string componentName)
+                       {
+                               if (0 != String.Compare (componentName, tagName, true))
+                                       return null;
+                               
+                               return type;
+                       }
+
+                       public string TagName {
+                               get { return tagName; }
+                       }
+               }
+
+               class AssemblyFoundry : Foundry
+               {
+                       string nameSpace;
+                       Assembly assembly;
+
+                       public AssemblyFoundry (Assembly assembly, string nameSpace)
+                       {
+                               this.assembly = assembly;
+                               this.nameSpace = nameSpace;
+                       }
+
+                       public override Type GetType (string componentName)
+                       {
+                               return assembly.GetType (nameSpace + "." + componentName, true, true);
+                       }
+               }
+
+               class CompoundFoundry : Foundry
+               {
+                       AssemblyFoundry assemblyFoundry;
+                       Hashtable tagnames;
+                       string tagPrefix;
+
+                       public CompoundFoundry (string tagPrefix)
+                       {
+                               this.tagPrefix = tagPrefix;
+#if NET_2_0
+                               tagnames = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
+#else
+                               tagnames = new Hashtable (CaseInsensitiveHashCodeProvider.DefaultInvariant,
+                                                         CaseInsensitiveComparer.DefaultInvariant);
+#endif
+                       }
+
+                       public void Add (Foundry foundry)
+                       {
+                               if (foundry is AssemblyFoundry) {
+                                       assemblyFoundry = (AssemblyFoundry) foundry;
+                                       return;
+                               }
+                               
+                               TagNameFoundry tn = (TagNameFoundry) foundry;
+                               string tagName = tn.TagName;
+                               if (tagnames.Contains (tagName)) {
+                                       string msg = String.Format ("{0}:{1} already registered.", tagPrefix, tagName);
+                                       throw new ApplicationException (msg);
+                               }
+                               tagnames.Add (tagName, foundry);
+                       }
+
+                       public override Type GetType (string componentName)
+                       {
+                               Type type = null;
+                               Foundry foundry = tagnames [componentName] as Foundry;
+                               if (foundry != null)
+                                       return foundry.GetType (componentName);
+
+                               if (assemblyFoundry != null) {
+                                       try {
+                                               type = assemblyFoundry.GetType (componentName);
+                                               return type;
+                                       } catch { }
+                               }
+
+                               string msg = String.Format ("Type {0} not registered for prefix {1}",
+                                                                    componentName, tagPrefix);
+                               throw new ApplicationException (msg);
+                       }
+               }
+       }
+}
+