2006-02-07 Chris Toshok <toshok@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.UI / ControlBuilder.cs
old mode 100755 (executable)
new mode 100644 (file)
index 4c9abed..2f4c434
@@ -6,8 +6,7 @@
 //     Gonzalo Paniagua Javier (gonzalo@ximian.com)
 //
 // (C) 2002, 2003 Ximian, Inc. (http://www.ximian.com)
-//
-
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Collections;
 using System.CodeDom;
 using System.Reflection;
-using System.Web;
+using System.Security.Permissions;
 using System.Web.Compilation;
 
 namespace System.Web.UI {
 
+       // CAS
+       [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public class ControlBuilder
        {
                internal static BindingFlags flagsNoCase = BindingFlags.Public |
@@ -62,6 +63,7 @@ namespace System.Web.UI {
 
                internal bool haveParserVariable;
                internal CodeMemberMethod method;
+               internal CodeStatementCollection methodStatements;
                internal CodeMemberMethod renderMethod;
                internal int renderIndex;
                internal bool isProperty;
@@ -152,6 +154,41 @@ namespace System.Web.UI {
                        }
                }
 
+#if NET_2_0
+               public
+#else
+               internal
+#endif
+               Type BindingContainerType {
+                       get {
+                               if (parentBuilder == null)
+                                       return typeof (Control);
+                                       
+                               if (parentBuilder is TemplateBuilder && ((TemplateBuilder)parentBuilder).ContainerType != null)
+                                       return ((TemplateBuilder)parentBuilder).ContainerType;
+
+                               Type ptype = parentBuilder.ControlType;
+                               if (ptype == null)
+                                       return parentBuilder.BindingContainerType;
+
+                               if (!typeof (INamingContainer).IsAssignableFrom (ptype))
+                                       return parentBuilder.BindingContainerType;
+
+                               return ptype;
+                       }
+               }
+
+               internal TemplateBuilder ParentTemplateBuilder {
+                       get {
+                               if (parentBuilder == null)
+                                       return null;
+                               else if (parentBuilder is TemplateBuilder)
+                                       return (TemplateBuilder) parentBuilder;
+                               else
+                                       return parentBuilder.ParentTemplateBuilder;
+                       }
+               }
+
                protected TemplateParser Parser {
                        get { return parser; }
                }
@@ -313,7 +350,7 @@ namespace System.Web.UI {
                        if (typeof (ICollection).IsAssignableFrom (propType)) {
                                builder = new CollectionBuilder ();
                        } else if (typeof (ITemplate).IsAssignableFrom (propType)) {
-                               builder = new TemplateBuilder ();
+                               builder = new TemplateBuilder (prop);
                        } else {
                                builder = CreateBuilderFromType (parser, parentBuilder, propType, prop.Name,
                                                                 null, atts, line, fileName);
@@ -350,18 +387,17 @@ namespace System.Web.UI {
                        if (this is TemplateBuilder)
                                return;
 
-                       if (!typeof (IParserAccessor).IsAssignableFrom (type)) {
+                       object [] atts = type.GetCustomAttributes (typeof (ParseChildrenAttribute), true);
+                       
+                       if (!typeof (IParserAccessor).IsAssignableFrom (type) && atts.Length == 0) {
                                isIParserAccessor = false;
                                childrenAsProperties = true;
-                       } else {
-                               object [] atts = type.GetCustomAttributes (typeof (ParseChildrenAttribute), true);
-                               if (atts != null && atts.Length > 0) {
-                                       ParseChildrenAttribute att = (ParseChildrenAttribute) atts [0];
-                                       childrenAsProperties = att.ChildrenAsProperties;
-                                       if (childrenAsProperties && att.DefaultProperty != "") {
-                                               defaultPropertyBuilder = CreatePropertyBuilder (att.DefaultProperty,
-                                                                                               parser, null);
-                                       }
+                       } else if (atts.Length > 0) {
+                               ParseChildrenAttribute att = (ParseChildrenAttribute) atts [0];
+                               childrenAsProperties = att.ChildrenAsProperties;
+                               if (childrenAsProperties && att.DefaultProperty != "") {
+                                       defaultPropertyBuilder = CreatePropertyBuilder (att.DefaultProperty,
+                                                                                       parser, null);
                                }
                        }
                }
@@ -456,6 +492,25 @@ namespace System.Web.UI {
                                }
                        }
                }
+#if NET_2_0
+               [MonoTODO ("unsure, lack documentation")]
+               public virtual object BuildObject ()
+               {
+                       return CreateInstance ();
+               }
+
+               internal void ResetState()
+               {
+                       haveParserVariable = false;
+
+                       if (Children != null) {
+                               foreach (object child in Children) {
+                                       ControlBuilder cb = child as ControlBuilder;
+                                       if (cb != null)
+                                               cb.ResetState ();
+                               }
+                       }
+               }
+#endif
        }
 }
-