* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Web / System.Web.UI / TemplateControl.cs
old mode 100755 (executable)
new mode 100644 (file)
index 937eb29..fc3aea5
@@ -7,20 +7,45 @@
 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
 //
 // (C) 2002 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
+// "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.ComponentModel;
 using System.Reflection;
-using System.Web;
+using System.Security.Permissions;
 using System.Web.Compilation;
 using System.Web.Util;
 
 namespace System.Web.UI {
 
-       public abstract class TemplateControl : Control, INamingContainer
-       {
+       // CAS
+       [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+#if NET_2_0
+       public abstract class TemplateControl : Control, INamingContainer, IFilterResolutionService {
+#else
+       public abstract class TemplateControl : Control, INamingContainer {
+#endif
                static object abortTransaction = new object ();
                static object commitTransaction = new object ();
                static object error = new object ();
@@ -28,8 +53,11 @@ namespace System.Web.UI {
                                                 "Page_Load",
                                                 "Page_DataBind",
                                                 "Page_PreRender",
-                                                "Page_Dispose",
-                                                "Page_Error" };
+                                                "Page_Disposed",
+                                                "Page_Error",
+                                                "Page_Unload",
+                                                "Page_AbortTransaction",
+                                                "Page_CommitTransaction" };
 
                const BindingFlags bflags = BindingFlags.Public |
                                            BindingFlags.NonPublic |
@@ -44,12 +72,16 @@ namespace System.Web.UI {
                #endregion
 
                #region Properties
-
+               [EditorBrowsable (EditorBrowsableState.Never)]
+#if NET_2_0
+               [Obsolete]
+#endif
                protected virtual int AutoHandlers {
                        get { return 0; }
                        set { }
                }
 
+               [EditorBrowsable (EditorBrowsableState.Never)]
                protected virtual bool SupportAutoEvents {
                        get { return true; }
                }
@@ -76,15 +108,16 @@ namespace System.Web.UI {
                                return;
 
                        Type type = GetType ();
-                       foreach (MethodInfo method in type.GetMethods (bflags)) {
-                               int pos = Array.IndexOf (methodNames, method.Name);
-                               if (pos == -1)
+                       foreach (string methodName in methodNames) {
+                               MethodInfo method = type.GetMethod (methodName, bflags);
+                               if (method == null)
                                        continue;
 
-                               string name = methodNames [pos];
-                               pos = name.IndexOf ("_");
-                               if (pos == -1 || pos + 1 == name.Length)
-                                       continue;
+                               if (method.DeclaringType != type) {
+                                       if (!method.IsPublic && !method.IsFamilyOrAssembly &&
+                                           !method.IsFamilyAndAssembly && !method.IsFamily)
+                                               continue;
+                               }
 
                                if (method.ReturnType != typeof (void))
                                        continue;
@@ -92,22 +125,25 @@ namespace System.Web.UI {
                                ParameterInfo [] parms = method.GetParameters ();
                                int length = parms.Length;
                                bool noParams = (length == 0);
-                               if (!noParams && (parms.Length != 2 ||
+                               if (!noParams && (length != 2 ||
                                    parms [0].ParameterType != typeof (object) ||
                                    parms [1].ParameterType != typeof (EventArgs)))
                                    continue;
 
-                               string eventName = name.Substring (pos + 1);
+                               int pos = methodName.IndexOf ("_");
+                               string eventName = methodName.Substring (pos + 1);
                                EventInfo evt = type.GetEvent (eventName);
-                               if (evt == null)
+                               if (evt == null) {
+                                       /* This should never happen */
                                        continue;
+                               }
 
                                if (noParams) {
-                                       NoParamsInvoker npi = new NoParamsInvoker (this, method.Name);
+                                       NoParamsInvoker npi = new NoParamsInvoker (this, methodName);
                                        evt.AddEventHandler (this, npi.FakeDelegate);
                                } else {
                                        evt.AddEventHandler (this, Delegate.CreateDelegate (
-                                                       typeof (EventHandler), this, method.Name));
+                                                       typeof (EventHandler), this, methodName));
                                }
                        }
                }
@@ -129,7 +165,25 @@ namespace System.Web.UI {
 
                public Control LoadControl (string virtualPath)
                {
-                       object control = Activator.CreateInstance (GetTypeFromControlPath (virtualPath));
+#if NET_2_0
+                       if (virtualPath == null)
+                               throw new ArgumentNullException ("virtualPath");
+#else
+                       if (virtualPath == null)
+                               throw new HttpException ("virtualPath is null");
+#endif
+                       Type type = GetTypeFromControlPath (virtualPath);
+                       object [] attrs = type.GetCustomAttributes (typeof (PartialCachingAttribute), true);
+                       if (attrs != null && attrs.Length == 1) {
+                               PartialCachingAttribute attr = (PartialCachingAttribute) attrs [0];
+                               PartialCachingControl ctrl = new PartialCachingControl (type);
+                               ctrl.VaryByParams = attr.VaryByParams;
+                               ctrl.VaryByControls = attr.VaryByControls;
+                               ctrl.VaryByCustom = attr.VaryByCustom;
+                               return ctrl;
+                       }
+
+                       object control = Activator.CreateInstance (type);
                        if (control is UserControl)
                                ((UserControl) control).InitializeAsUserControl (Page);
 
@@ -138,13 +192,20 @@ namespace System.Web.UI {
 
                public ITemplate LoadTemplate (string virtualPath)
                {
+#if NET_2_0
+                       if (virtualPath == null)
+                               throw new ArgumentNullException ("virtualPath");
+#else
+                       if (virtualPath == null)
+                               throw new HttpException ("virtualPath is null");
+#endif
                        Type t = GetTypeFromControlPath (virtualPath);
                        return new SimpleTemplate (t);
                }
 
                protected virtual void OnAbortTransaction (EventArgs e)
                {
-                       EventHandler eh = Events [error] as EventHandler;
+                       EventHandler eh = Events [abortTransaction] as EventHandler;
                        if (eh != null)
                                eh (this, e);
                }
@@ -158,7 +219,7 @@ namespace System.Web.UI {
 
                protected virtual void OnError (EventArgs e)
                {
-                       EventHandler eh = Events [abortTransaction] as EventHandler;
+                       EventHandler eh = Events [error] as EventHandler;
                        if (eh != null)
                                eh (this, e);
                }
@@ -166,14 +227,26 @@ namespace System.Web.UI {
                [MonoTODO]
                public Control ParseControl (string content)
                {
+                       if (content == null)
+                               throw new ArgumentNullException ("content");
+
                        return null;
                }
 
-               [MonoTODO]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               public 
+#if !NET_2_0
+               static
+#endif
+               object ReadStringResource ()
+               {
+                       throw new NotSupportedException ();
+               }
+
                [EditorBrowsable (EditorBrowsableState.Never)]
                public static object ReadStringResource (Type t)
                {
-                       return null;
+                       throw new NotSupportedException ();
                }
 
                [MonoTODO]
@@ -231,5 +304,45 @@ namespace System.Web.UI {
                        }
                }
 
+#if NET_2_0
+               protected object Eval (string expression)
+               {
+                       return DataBinder.Eval (Page.GetDataItem(), expression);
+               }
+       
+               protected string Eval (string expression, string format)
+               {
+                       return DataBinder.Eval (Page.GetDataItem(), expression, format);
+               }
+       
+               protected object XPath (string xpathexpression)
+               {
+                       return XPathBinder.Eval (Page.GetDataItem(), xpathexpression);
+               }
+       
+               protected string XPath (string xpathexpression, string format)
+               {
+                       return XPathBinder.Eval (Page.GetDataItem(), xpathexpression, format);
+               }
+       
+               protected IEnumerable XPathSelect (string xpathexpression)
+               {
+                       return XPathBinder.Select (Page.GetDataItem(), xpathexpression);
+               }
+
+               // IFilterResolutionService
+
+               [MonoTODO]
+               int IFilterResolutionService.CompareFilters (string filter1, string filter2)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               bool IFilterResolutionService.EvaluateFilter (string filterName)
+               {
+                       throw new NotImplementedException ();
+               }
+#endif
        }
 }