Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>2003-04-15 07:00:06 +0400
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>2003-04-15 07:00:06 +0400
commitf9e281c5178b6cd491b8e39fff8198d6dd7078ff (patch)
treef71e12e4ccbd3b65516cd47752470e454673a256 /mcs/class/System.Web/System.Web.UI
parentfb27acfda0ee35f9e37fe62f8a76d60a5b3d7d00 (diff)
2003-04-15 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* list: added CollectionBuilder and TemplateBuilder. * System.Web.UI/CollectionBuilder.cs: * System.Web.UI/TemplateBuilder.cs: new classes derived from ControlBuilder that represent a property or a ITemplate. * System.Web.UI/ControlBuilder.cs: implemented all the missing bits. * System.Web.UI/TemplateParser.cs: added mapping from tag name to Type feature. svn path=/trunk/mcs/; revision=13632
Diffstat (limited to 'mcs/class/System.Web/System.Web.UI')
-rw-r--r--mcs/class/System.Web/System.Web.UI/ChangeLog9
-rw-r--r--mcs/class/System.Web/System.Web.UI/CollectionBuilder.cs57
-rwxr-xr-xmcs/class/System.Web/System.Web.UI/ControlBuilder.cs216
-rw-r--r--mcs/class/System.Web/System.Web.UI/TemplateBuilder.cs55
-rwxr-xr-xmcs/class/System.Web/System.Web.UI/TemplateParser.cs16
5 files changed, 308 insertions, 45 deletions
diff --git a/mcs/class/System.Web/System.Web.UI/ChangeLog b/mcs/class/System.Web/System.Web.UI/ChangeLog
index c6dbbe157ff..b14139e6267 100644
--- a/mcs/class/System.Web/System.Web.UI/ChangeLog
+++ b/mcs/class/System.Web/System.Web.UI/ChangeLog
@@ -1,3 +1,12 @@
+2003-04-15 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * CollectionBuilder.cs:
+ * TemplateBuilder.cs: new classes derived from ControlBuilder that
+ represent a property or a ITemplate.
+
+ * ControlBuilder.cs: implemented all the missing bits.
+ * TemplateParser.cs: added mapping from tag name to Type feature.
+
2003-02-15 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* Control.cs: have i definitely fixed naming container stuff this time?
diff --git a/mcs/class/System.Web/System.Web.UI/CollectionBuilder.cs b/mcs/class/System.Web/System.Web.UI/CollectionBuilder.cs
new file mode 100644
index 00000000000..e494ce07c47
--- /dev/null
+++ b/mcs/class/System.Web/System.Web.UI/CollectionBuilder.cs
@@ -0,0 +1,57 @@
+//
+// System.Web.UI.CollectionBuilder.cs
+//
+// Authors:
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (c) 2003 Ximian, Inc. (http://www.ximian.com)
+//
+
+using System;
+using System.Collections;
+using System.Reflection;
+
+namespace System.Web.UI
+{
+ class CollectionBuilder : ControlBuilder
+ {
+ Type elementType;
+
+ internal CollectionBuilder ()
+ {
+ }
+
+ public override void AppendLiteralString (string s)
+ {
+ if (s != null && s.Trim () != "")
+ throw new HttpException ("Literal content not allowed for " + ControlType);
+ }
+
+ public override Type GetChildControlType (string tagName, IDictionary attribs)
+ {
+ Type t = Parser.GetTypeFromTag (tagName);
+ if (elementType != null && !(elementType.IsAssignableFrom (t)))
+ throw new HttpException ("Cannot add a " + t + " to " + elementType);
+
+ return t;
+ }
+
+ public override void Init (TemplateParser parser,
+ ControlBuilder parentBuilder,
+ Type type,
+ string tagName,
+ string id,
+ IDictionary attribs)
+ {
+ base.Init (parser, parentBuilder, type, tagName, id, attribs);
+
+ PropertyInfo prop = parentBuilder.ControlType.GetProperty (tagName, flagsNoCase);
+ SetControlType (prop.PropertyType);
+
+ prop = ControlType.GetProperty ("Item", flagsNoCase & ~BindingFlags.IgnoreCase);
+ if (prop != null)
+ elementType = prop.PropertyType;
+ }
+ }
+}
+
diff --git a/mcs/class/System.Web/System.Web.UI/ControlBuilder.cs b/mcs/class/System.Web/System.Web.UI/ControlBuilder.cs
index 7acb206a3a3..4cbb8fffd45 100755
--- a/mcs/class/System.Web/System.Web.UI/ControlBuilder.cs
+++ b/mcs/class/System.Web/System.Web.UI/ControlBuilder.cs
@@ -1,18 +1,26 @@
//
// System.Web.UI.ControlBuilder.cs
//
-// Duncan Mak (duncan@ximian.com)
+// Authors:
+// Duncan Mak (duncan@ximian.com)
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
-// (C) Ximian, Inc.
+// (C) 2002, 2003 Ximian, Inc. (http://www.ximian.com)
//
using System;
using System.Collections;
+using System.Reflection;
namespace System.Web.UI {
public class ControlBuilder
{
+ internal static BindingFlags flagsNoCase = BindingFlags.Public |
+ BindingFlags.Instance |
+ BindingFlags.Static |
+ BindingFlags.IgnoreCase;
+
TemplateParser parser;
ControlBuilder parentBuilder;
Type type;
@@ -21,16 +29,24 @@ namespace System.Web.UI {
IDictionary attribs;
int line;
string fileName;
+ bool childrenAsProperties;
+ bool isIParserAccessor;
+ bool hasAspCode;
+ ControlBuilder defaultPropertyBuilder;
+ ArrayList children;
public ControlBuilder ()
{
}
-
- internal ControlBuilder (
- TemplateParser parser, ControlBuilder parentBuilder,
- Type type, string tagName, string id,
- IDictionary attribs, int line, string sourceFileName)
+ internal ControlBuilder (TemplateParser parser,
+ ControlBuilder parentBuilder,
+ Type type,
+ string tagName,
+ string id,
+ IDictionary attribs,
+ int line,
+ string sourceFileName)
{
this.parser = parser;
@@ -47,35 +63,47 @@ namespace System.Web.UI {
get { return type; }
}
- [MonoTODO]
public bool FChildrenAsProperties {
- get { return false; }
+ get { return childrenAsProperties; }
}
- [MonoTODO]
public bool FIsNonParserAccessor {
- get { return false; }
+ get { return isIParserAccessor; }
}
- [MonoTODO]
public bool HasAspCode {
- get { return false; }
+ get { return hasAspCode; }
}
public string ID {
get { return id; }
-
set { id = value; }
}
+ protected void SetControlType (Type t)
+ {
+ type = t;
+ }
+
[MonoTODO]
public bool InDesigner {
get { return false; }
}
- [MonoTODO]
public Type NamingContainerType {
- get { return null; }
+ get {
+ if (parentBuilder == null)
+ return typeof (Control);
+
+ Type ptype = parentBuilder.ControlType;
+ if (ptype == null)
+ return typeof (Control);
+
+ if (!typeof (INamingContainer).IsAssignableFrom (type))
+ return parentBuilder.NamingContainerType;
+
+ return type;
+ }
}
protected TemplateParser Parser {
@@ -86,10 +114,9 @@ namespace System.Web.UI {
get { return tagName; }
}
- [MonoTODO]
public virtual bool AllowWhitespaceLiterals ()
{
- return false;
+ return true;
}
[MonoTODO]
@@ -98,69 +125,168 @@ namespace System.Web.UI {
throw new NotImplementedException ();
}
- [MonoTODO]
public virtual void AppendSubBuilder (ControlBuilder subBuilder)
{
- throw new NotImplementedException ();
+ if (children == null)
+ children = new ArrayList ();
+
+ subBuilder.OnAppendToParentBuilder (this);
+ children.Add (subBuilder);
}
- [MonoTODO]
public virtual void CloseControl ()
{
}
- [MonoTODO]
- public static ControlBuilder CreateBuilderFromType (
- TemplateParser parser, ControlBuilder parentBuilder,
- Type type, string tagName, string id,
- IDictionary attribs, int line, string sourceFileName)
+ public static ControlBuilder CreateBuilderFromType (TemplateParser parser,
+ ControlBuilder parentBuilder,
+ Type type,
+ string tagName,
+ string id,
+ IDictionary attribs,
+ int line,
+ string sourceFileName)
{
- return new ControlBuilder (parser, parentBuilder, type,
- tagName, id, attribs, line, sourceFileName);
+ ControlBuilder builder;
+ object [] atts = type.GetCustomAttributes (typeof (ControlBuilderAttribute), true);
+ if (atts != null && atts.Length > 0) {
+ ControlBuilderAttribute att = (ControlBuilderAttribute) atts [0];
+ builder = (ControlBuilder) Activator.CreateInstance (att.BuilderType);
+ } else {
+ builder = new ControlBuilder ();
+ }
+
+ builder.Init (parser, parentBuilder, type, tagName, id, attribs);
+ builder.line = line;
+ builder.fileName = sourceFileName;
+ return builder;
}
- [MonoTODO]
public virtual Type GetChildControlType (string tagName, IDictionary attribs)
{
- return attribs [tagName] as Type;
+ return null;
}
- [MonoTODO]
public virtual bool HasBody ()
{
- return false;
+ return true;
}
- [MonoTODO]
public virtual bool HtmlDecodeLiterals ()
{
return false;
}
- [MonoTODO]
- public virtual void Init (
- TemplateParser parser, ControlBuilder parentBuilder,
- Type type, string tagName, string id, IDictionary attribs)
+ ControlBuilder CreatePropertyBuilder (string propName, TemplateParser parser)
{
- throw new NotImplementedException ();
+ PropertyInfo prop = type.GetProperty (propName, flagsNoCase);
+ if (prop == null) {
+ string msg = String.Format ("Property {0} not found in type {1}", propName, type);
+ throw new HttpException (msg);
+ }
+
+ Type propType = prop.PropertyType;
+ ControlBuilder builder = null;
+ if (typeof (ICollection).IsAssignableFrom (propType))
+ builder = new CollectionBuilder ();
+ else if (typeof (ITemplate).IsAssignableFrom (propType))
+ builder = new TemplateBuilder ();
+ else
+ return CreateBuilderFromType (parser,
+ parentBuilder,
+ propType,
+ propName,
+ null,
+ null,
+ line,
+ fileName);
+
+ builder.Init (parser, this, null, tagName, null, null);
+ builder.fileName = fileName;
+ builder.line = line;
+ return builder;
+ }
+
+ public virtual void Init (TemplateParser parser,
+ ControlBuilder parentBuilder,
+ Type type,
+ string tagName,
+ string id,
+ IDictionary attribs)
+ {
+ this.parser = parser;
+ this.parentBuilder = parentBuilder;
+ this.type = type;
+ this.tagName = tagName;
+ this.id = id;
+ this.attribs = attribs;
+ if (type == null)
+ return;
+
+ if (!typeof (IParserAccessor).IsAssignableFrom (type)) {
+ 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);
+ }
+ }
}
- [MonoTODO]
public virtual bool NeedsTagInnerText ()
{
- throw new NotImplementedException ();
+ return false;
}
- [MonoTODO]
- public virtual void OnAppendToParentBuilder ()
+ public virtual void OnAppendToParentBuilder (ControlBuilder parentBuilder)
{
- throw new NotImplementedException ();
+ if (parentBuilder.defaultPropertyBuilder == null)
+ return;
+
+ ControlBuilder old = parentBuilder.defaultPropertyBuilder;
+ defaultPropertyBuilder = null;
+ AppendSubBuilder (old);
}
- [MonoTODO]
public virtual void SetTagInnerText (string text)
{
- throw new NotImplementedException ();
+ }
+
+ internal virtual object CreateInstance ()
+ {
+ // HtmlGenericControl, HtmlTableCell...
+ object [] atts = type.GetCustomAttributes (typeof (ConstructorNeedsTagAttribute), true);
+ object [] args = null;
+ if (atts != null && atts.Length > 0) {
+ ConstructorNeedsTagAttribute att = (ConstructorNeedsTagAttribute) atts [0];
+ if (att.NeedsTag)
+ args = new object [] {tagName};
+ }
+
+ return Activator.CreateInstance (type, args);
+ }
+
+ internal virtual void CreateChildren (object parent)
+ {
+ if (children == null || children.Count == 0)
+ return;
+
+ IParserAccessor parser = parent as IParserAccessor;
+ if (parser == null)
+ return;
+
+ foreach (object o in children) {
+ if (o is string) {
+ parser.AddParsedSubObject (new LiteralControl ((string) o));
+ } else {
+ parser.AddParsedSubObject (((ControlBuilder) o).CreateInstance ());
+ }
+ }
}
}
}
diff --git a/mcs/class/System.Web/System.Web.UI/TemplateBuilder.cs b/mcs/class/System.Web/System.Web.UI/TemplateBuilder.cs
new file mode 100644
index 00000000000..02fbe3dbda4
--- /dev/null
+++ b/mcs/class/System.Web/System.Web.UI/TemplateBuilder.cs
@@ -0,0 +1,55 @@
+//
+// System.Web.UI.TemplateBuilder
+//
+// Authors:
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (C) 2003 Ximian, Inc. (http://www.ximian.com)
+//
+
+using System;
+using System.Collections;
+
+namespace System.Web.UI
+{
+ public class TemplateBuilder : ControlBuilder, ITemplate
+ {
+ string text;
+
+ public TemplateBuilder ()
+ {
+ }
+
+ public virtual string Text {
+ get { return text; }
+ set { text = value; }
+ }
+
+ public override void Init (TemplateParser parser,
+ ControlBuilder parentBuilder,
+ Type type,
+ string tagName,
+ string ID,
+ IDictionary attribs)
+ {
+ // enough?
+ base.Init (parser, parentBuilder, type, tagName, ID, attribs);
+ }
+
+ public virtual void InstantiateIn (Control container)
+ {
+ CreateChildren (container);
+ }
+
+ public override bool NeedsTagInnerText ()
+ {
+ return false;
+ }
+
+ public override void SetTagInnerText (string text)
+ {
+ this.text = text;
+ }
+ }
+}
+
diff --git a/mcs/class/System.Web/System.Web.UI/TemplateParser.cs b/mcs/class/System.Web/System.Web.UI/TemplateParser.cs
index b52d2f46719..7640c668642 100755
--- a/mcs/class/System.Web/System.Web.UI/TemplateParser.cs
+++ b/mcs/class/System.Web/System.Web.UI/TemplateParser.cs
@@ -13,11 +13,14 @@ using System.Web;
namespace System.Web.UI
{
+ internal delegate Type TagMapper (string tag);
+
public abstract class TemplateParser : BaseParser
{
string inputFile;
string text;
Hashtable options;
+ TagMapper mapper;
protected abstract Type CompileIntoType ();
@@ -25,6 +28,19 @@ namespace System.Web.UI
{
}
+ internal void SetTagMapper (TagMapper mapper)
+ {
+ this.mapper = mapper;
+ }
+
+ internal Type GetTypeFromTag (string tag)
+ {
+ if (mapper == null)
+ throw new HttpException ("No tag mapper set!");
+
+ return mapper (tag);
+ }
+
protected abstract Type DefaultBaseType { get; }
protected abstract string DefaultDirectiveName { get; }