2 // System.Web.UI.WebControls.XmlHierarchyData
5 // Ben Maurer (bmaurer@users.sourceforge.net)
11 using System.Collections;
12 using System.Collections.Specialized;
15 using System.ComponentModel;
16 using AC = System.ComponentModel.AttributeCollection;
18 namespace System.Web.UI.WebControls {
19 public class XmlHierarchyData : IHierarchyData, ICustomTypeDescriptor {
20 internal XmlHierarchyData (XmlNode item)
25 public override string ToString ()
30 #region ICustomTypeDescriptor
31 AC ICustomTypeDescriptor.GetAttributes ()
36 string ICustomTypeDescriptor.GetClassName ()
38 return "XmlHierarchyData";
41 string ICustomTypeDescriptor.GetComponentName ()
46 TypeConverter ICustomTypeDescriptor.GetConverter ()
51 EventDescriptor ICustomTypeDescriptor.GetDefaultEvent ()
56 PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty ()
58 return new XmlHierarchyDataPropertyDescriptor (item, "##Name##");
61 object ICustomTypeDescriptor.GetEditor (Type editorBaseType)
66 EventDescriptorCollection ICustomTypeDescriptor.GetEvents ()
71 EventDescriptorCollection ICustomTypeDescriptor.GetEvents (Attribute [] attrs)
76 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties ()
78 return ((ICustomTypeDescriptor)this).GetProperties (null);
81 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties (Attribute [] attrFilter)
83 ArrayList ret = new ArrayList ();
84 ret.Add (new XmlHierarchyDataPropertyDescriptor (item, "##Name##"));
85 ret.Add (new XmlHierarchyDataPropertyDescriptor (item, "##Value##"));
86 ret.Add (new XmlHierarchyDataPropertyDescriptor (item, "##InnerText##"));
88 if (item.Attributes != null)
89 foreach (XmlAttribute a in item.Attributes)
90 ret.Add (new XmlHierarchyDataPropertyDescriptor (item, a.Name));
92 return new PropertyDescriptorCollection ((PropertyDescriptor[]) ret.ToArray (typeof (PropertyDescriptor)));
95 object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
97 if (pd is XmlHierarchyDataPropertyDescriptor)
103 #region IHierarchyData
104 IHierarchicalEnumerable IHierarchyData.GetChildren ()
106 return new XmlHierarchicalEnumerable (item.ChildNodes);
109 IHierarchicalEnumerable IHierarchyData.GetParent ()
111 if (item.ParentNode == null)
113 return new XmlHierarchicalEnumerable (item.ParentNode.ChildNodes);
116 bool IHierarchyData.HasChildren {
117 get { return item.HasChildNodes; }
120 object IHierarchyData.Item {
125 string IHierarchyData.Path {
126 get { throw new NotImplementedException (); }
129 string IHierarchyData.Type {
130 get { return item.Name; }
136 class XmlHierarchyDataPropertyDescriptor : PropertyDescriptor {
137 public XmlHierarchyDataPropertyDescriptor (XmlNode xmlNode, string name) : base (name, null)
139 this.xmlNode = xmlNode;
143 public override bool CanResetValue (object o)
148 public override void ResetValue (object o)
152 public override object GetValue (object o)
154 if (o is XmlHierarchyData) {
156 case "##Name##": return xmlNode.Name;
157 case "##Value##": return xmlNode.Value;
158 case "##InnerText##": return xmlNode.InnerText;
159 case null: return String.Empty;
161 if (xmlNode.Attributes != null) {
162 XmlAttribute a = xmlNode.Attributes [name];
172 public override void SetValue (object o, object value)
174 if (o is XmlHierarchyData) {
176 case "##Name##": break;
177 case "##Value##": xmlNode.Value = value.ToString (); break;
178 case "##InnerText##": xmlNode.InnerText = value.ToString (); break;
181 if (xmlNode.Attributes != null) {
182 XmlAttribute a = xmlNode.Attributes [name];
184 a.Value = value.ToString ();
191 public override bool ShouldSerializeValue (object o)
196 public override Type ComponentType {
197 get { return typeof (XmlHierarchyData); }
200 public override bool IsReadOnly {
201 get { return xmlNode.IsReadOnly; }
204 public override Type PropertyType {
205 get { return typeof (string); }