2 // System.Web.UI.WebControls.XmlHierarchyData
5 // Ben Maurer (bmaurer@users.sourceforge.net)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Collections.Specialized;
36 using System.ComponentModel;
37 using AC = System.ComponentModel.AttributeCollection;
39 namespace System.Web.UI.WebControls {
40 internal class XmlHierarchyData : IHierarchyData, ICustomTypeDescriptor {
41 internal XmlHierarchyData (XmlNode item)
46 public override string ToString ()
51 #region ICustomTypeDescriptor
52 AC ICustomTypeDescriptor.GetAttributes ()
57 string ICustomTypeDescriptor.GetClassName ()
59 return "XmlHierarchyData";
62 string ICustomTypeDescriptor.GetComponentName ()
67 TypeConverter ICustomTypeDescriptor.GetConverter ()
72 EventDescriptor ICustomTypeDescriptor.GetDefaultEvent ()
77 PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty ()
79 return new XmlHierarchyDataPropertyDescriptor (item, "##Name##");
82 object ICustomTypeDescriptor.GetEditor (Type editorBaseType)
87 EventDescriptorCollection ICustomTypeDescriptor.GetEvents ()
92 EventDescriptorCollection ICustomTypeDescriptor.GetEvents (Attribute [] attrs)
97 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties ()
99 return ((ICustomTypeDescriptor)this).GetProperties (null);
102 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties (Attribute [] attrFilter)
104 ArrayList ret = new ArrayList ();
105 ret.Add (new XmlHierarchyDataPropertyDescriptor (item, "##Name##"));
106 ret.Add (new XmlHierarchyDataPropertyDescriptor (item, "##Value##"));
107 ret.Add (new XmlHierarchyDataPropertyDescriptor (item, "##InnerText##"));
109 if (item.Attributes != null)
110 foreach (XmlAttribute a in item.Attributes)
111 ret.Add (new XmlHierarchyDataPropertyDescriptor (item, a.Name));
113 return new PropertyDescriptorCollection ((PropertyDescriptor[]) ret.ToArray (typeof (PropertyDescriptor)));
116 object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
118 if (pd is XmlHierarchyDataPropertyDescriptor)
124 #region IHierarchyData
125 IHierarchicalEnumerable IHierarchyData.GetChildren ()
127 return new XmlHierarchicalEnumerable (item.ChildNodes);
130 IHierarchicalEnumerable IHierarchyData.GetParent ()
132 if (item.ParentNode == null)
134 return new XmlHierarchicalEnumerable (item.ParentNode.ChildNodes);
137 bool IHierarchyData.HasChildren {
138 get { return item.HasChildNodes; }
141 object IHierarchyData.Item {
146 string IHierarchyData.Path {
147 get { throw new NotImplementedException (); }
150 string IHierarchyData.Type {
151 get { return item.Name; }
157 class XmlHierarchyDataPropertyDescriptor : PropertyDescriptor {
158 public XmlHierarchyDataPropertyDescriptor (XmlNode xmlNode, string name) : base (name, null)
160 this.xmlNode = xmlNode;
164 public override bool CanResetValue (object o)
169 public override void ResetValue (object o)
173 public override object GetValue (object o)
175 if (o is XmlHierarchyData) {
177 case "##Name##": return xmlNode.Name;
178 case "##Value##": return xmlNode.Value;
179 case "##InnerText##": return xmlNode.InnerText;
180 case null: return String.Empty;
182 if (xmlNode.Attributes != null) {
183 XmlAttribute a = xmlNode.Attributes [name];
193 public override void SetValue (object o, object value)
195 if (o is XmlHierarchyData) {
197 case "##Name##": break;
198 case "##Value##": xmlNode.Value = value.ToString (); break;
199 case "##InnerText##": xmlNode.InnerText = value.ToString (); break;
202 if (xmlNode.Attributes != null) {
203 XmlAttribute a = xmlNode.Attributes [name];
205 a.Value = value.ToString ();
212 public override bool ShouldSerializeValue (object o)
217 public override Type ComponentType {
218 get { return typeof (XmlHierarchyData); }
221 public override bool IsReadOnly {
222 get { return xmlNode.IsReadOnly; }
225 public override Type PropertyType {
226 get { return typeof (string); }