Merge pull request #2781 from alexanderkyte/inflated_method_header_leak
[mono.git] / mcs / class / System.Web / System.Web.Compilation / PageBuildProvider.cs
index 7f64c4826d43d63fc10eecaf2cf042f3cb52c74b..66d84380667375436c7006591ced6b4c32d9a40e 100644 (file)
@@ -3,8 +3,9 @@
 //
 // Authors:
 //     Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//      Marek Habersack (mhabersack@novell.com)
 //
-// (C) 2006 Novell, Inc (http://www.novell.com)
+// (C) 2006-2009 Novell, Inc (http://www.novell.com)
 //
 
 //
@@ -28,7 +29,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 
 using System;
 using System.CodeDom;
@@ -37,50 +37,53 @@ using System.Collections;
 using System.IO;
 using System.Reflection;
 using System.Web.UI;
+using System.Web.Util;
 
 namespace System.Web.Compilation {
 
-       sealed class PageBuildProvider : BuildProvider {
-               PageCompiler pcompiler;
-               CompilerType compiler_type;
-
+       [BuildProviderAppliesTo (BuildProviderAppliesTo.Web)]
+       sealed class PageBuildProvider : TemplateBuildProvider {
+               
                public PageBuildProvider()
                {
                }
 
-               public override void GenerateCode (AssemblyBuilder assemblyBuilder)
+               protected override string MapPath (VirtualPath virtualPath)
                {
-                       HttpContext context = HttpContext.Current;
-                       PageParser parser = new PageParser (VirtualPath, OpenReader (), context);
-                       pcompiler = new PageCompiler (parser);
-                       pcompiler.CreateMethods ();
-                       compiler_type = GetDefaultCompilerTypeForLanguage (parser.Language);
-                       using (TextWriter writer = assemblyBuilder.CreateCodeFile (this)) {
-                               CodeDomProvider provider = pcompiler.Provider;
-                               CodeCompileUnit unit = pcompiler.CompileUnit;
-                               provider.CreateGenerator().GenerateCodeFromCompileUnit (unit, writer, null);
-                       }
-               }
+                       // We need this hack to support out-of-application wsdl helpers
+                       if (virtualPath.IsFake)
+                               return virtualPath.PhysicalPath;
 
-               public override Type GetGeneratedType (CompilerResults results)
+                       return base.MapPath (virtualPath);
+               }               
+
+               protected override TextReader SpecialOpenReader (VirtualPath virtualPath, out string physicalPath)
                {
-                       // This is not called if compilation failed.
-                       // Returning null makes the caller throw an InvalidCastException
-                       Assembly assembly = results.CompiledAssembly;
-                       return assembly.GetType (pcompiler.Parser.ClassName);
+                       // We need this hack to support out-of-application wsdl helpers
+                       if (virtualPath.IsFake) {
+                               physicalPath = virtualPath.PhysicalPath;
+                               return new StreamReader (physicalPath);
+                       } else
+                               physicalPath = null;
+                       
+                       return base.SpecialOpenReader (virtualPath, out physicalPath);
                }
-
-               public override CompilerType CodeCompilerType {
-                       get { return compiler_type; }
+               
+               protected override BaseCompiler CreateCompiler (TemplateParser parser)
+               {
+                       return new PageCompiler (parser as PageParser);
                }
 
-               // FIXME: figure this out.
-               public override ICollection VirtualPathDependencies {
-                       get {
-                               return pcompiler.Parser.Dependencies;
-                       }
+               protected override TemplateParser CreateParser (VirtualPath virtualPath, string physicalPath, HttpContext context)
+               {       
+                       return CreateParser (virtualPath, physicalPath, OpenReader (virtualPath.Original), context);
+               }
+               
+               protected override TemplateParser CreateParser (VirtualPath virtualPath, string physicalPath, TextReader reader, HttpContext context)
+               {
+                       return new PageParser (virtualPath, physicalPath, reader, context);
                }
        }
 }
-#endif
+