2006-01-09 Chris Toshok <toshok@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / TagPrefixInfo.cs
1 //
2 // System.Web.Configuration.TagPrefixInfo
3 //
4 // Authors:
5 //      Chris Toshok (toshok@ximian.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 #if NET_2_0
32
33 using System;
34 using System.ComponentModel;
35 using System.Configuration;
36 using System.Web.UI;
37 using System.Xml;
38
39 namespace System.Web.Configuration
40 {
41         public sealed class TagPrefixInfo : ConfigurationElement
42         {
43                 static ConfigurationPropertyCollection properties;
44                 static ConfigurationProperty tagPrefixProp;
45                 static ConfigurationProperty namespaceProp;
46                 static ConfigurationProperty assemblyProp;
47                 static ConfigurationProperty tagNameProp;
48                 static ConfigurationProperty sourceProp;
49
50                 static ConfigurationElementProperty elementProperty;
51
52                 static TagPrefixInfo ()
53                 {
54                         tagPrefixProp = new ConfigurationProperty ("tagPrefix", typeof (string), "/",
55                                                                    TypeDescriptor.GetConverter (typeof (string)),
56                                                                    PropertyHelper.NonEmptyStringValidator,
57                                                                    ConfigurationPropertyOptions.IsRequired);
58                         namespaceProp = new ConfigurationProperty ("namespace", typeof (string));
59                         assemblyProp = new ConfigurationProperty ("assembly", typeof (string));
60                         tagNameProp = new ConfigurationProperty ("tagName", typeof (string));
61                         sourceProp = new ConfigurationProperty ("src", typeof (string));
62
63                         properties = new ConfigurationPropertyCollection ();
64                         properties.Add (tagPrefixProp);
65                         properties.Add (namespaceProp);
66                         properties.Add (assemblyProp);
67                         properties.Add (tagNameProp);
68                         properties.Add (sourceProp);
69
70                         elementProperty = new ConfigurationElementProperty (new CallbackValidator (typeof (TagPrefixInfo), ValidateElement));
71                 }
72
73                 internal TagPrefixInfo ()
74                 {
75                 }
76
77                 public TagPrefixInfo (string tagPrefix, string nameSpace, string assembly, string tagName, string source)
78                 {
79                         this.TagPrefix = tagPrefix;
80                         this.Namespace = nameSpace;
81                         this.Assembly = assembly;
82                         this.TagName = tagName;
83                         this.Source = source;
84                 }
85
86                 [MonoTODO]
87                 static void ValidateElement (object o)
88                 {
89                         /* XXX do some sort of element validation here? */
90                 }
91
92                 protected override ConfigurationElementProperty ElementProperty {
93                         get { return elementProperty; }
94                 }
95
96                 public override bool Equals (object prefix)
97                 {
98                         TagPrefixInfo info = prefix as TagPrefixInfo;
99                         if (info == null)
100                                 return false;
101
102                         return (Namespace == info.Namespace
103                                 && Source == info.Source
104                                 && TagName == info.TagName
105                                 && TagPrefix == info.TagPrefix);
106                 }
107
108                 public override int GetHashCode ()
109                 {
110                         return Namespace.GetHashCode() + Source.GetHashCode() + TagName.GetHashCode() + TagPrefix.GetHashCode();
111                 }
112
113                 [ConfigurationProperty ("assembly")]
114                 public string Assembly {
115                         get { return (string) base[assemblyProp]; }
116                         set { base[assemblyProp] = value; }
117                 }
118
119                 [ConfigurationProperty ("namespace")]
120                 public string Namespace {
121                         get { return (string) base[namespaceProp]; }
122                         set { base[namespaceProp] = value; }
123                 }
124
125                 [ConfigurationProperty ("src")]
126                 public string Source {
127                         get { return (string) base[sourceProp]; }
128                         set { base[sourceProp] = value; }
129                 }
130
131                 [ConfigurationProperty ("tagName")]
132                 public string TagName {
133                         get { return (string) base[tagNameProp]; }
134                         set { base[tagNameProp] = value; }
135                 }
136
137                 [StringValidator (MinLength = 1)]
138                 [ConfigurationProperty ("tagPrefix", DefaultValue = "/", Options = ConfigurationPropertyOptions.IsRequired)]
139                 public string TagPrefix {
140                         get { return (string) base[tagPrefixProp]; }
141                         set { base[tagPrefixProp] = value; }
142                 }
143
144                 protected override ConfigurationPropertyCollection Properties {
145                         get { return properties; }
146                 }
147         }
148 }
149
150 #endif