4920ccbbe76a567fbdedad4934be300d61b01416
[mono.git] / mcs / class / referencesource / System.Xml / System / Xml / Schema / XmlSchemaAttribute.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="XmlSchemaAttribute.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright> 
5 // <owner current="true" primary="true">Microsoft</owner>                                                               
6 //------------------------------------------------------------------------------
7
8 using System.Collections;
9 using System.ComponentModel;
10 using System.Xml.Serialization;
11
12 namespace System.Xml.Schema {
13
14     /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute"]/*' />
15     /// <devdoc>
16     ///    <para>[To be supplied.]</para>
17     /// </devdoc>
18     public class XmlSchemaAttribute : XmlSchemaAnnotated {
19         string defaultValue;
20         string fixedValue;
21         string name;
22
23         XmlSchemaForm form = XmlSchemaForm.None;
24         XmlSchemaUse use = XmlSchemaUse.None;
25
26         XmlQualifiedName refName = XmlQualifiedName.Empty; 
27         XmlQualifiedName typeName = XmlQualifiedName.Empty;
28         XmlQualifiedName qualifiedName = XmlQualifiedName.Empty;
29
30         XmlSchemaSimpleType type;
31         XmlSchemaSimpleType attributeType;
32
33         SchemaAttDef attDef;
34         
35         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.DefaultValue"]/*' />
36         /// <devdoc>
37         ///    <para>[To be supplied.]</para>
38         /// </devdoc>
39         [XmlAttribute("default")]
40         [DefaultValue(null)]
41         public string DefaultValue { 
42             get { return defaultValue; }
43             set { defaultValue = value; }
44         }
45
46         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.FixedValue"]/*' />
47         /// <devdoc>
48         ///    <para>[To be supplied.]</para>
49         /// </devdoc>
50         [XmlAttribute("fixed")]
51         [DefaultValue(null)]
52         public string FixedValue { 
53             get { return fixedValue; }
54             set { fixedValue = value; }
55         }
56
57         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.Form"]/*' />
58         /// <devdoc>
59         ///    <para>[To be supplied.]</para>
60         /// </devdoc>
61         [XmlAttribute("form"), DefaultValue(XmlSchemaForm.None)]
62         public XmlSchemaForm Form { 
63             get { return form; }
64             set { form = value; }
65         }
66
67         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.Name"]/*' />
68         /// <devdoc>
69         ///    <para>[To be supplied.]</para>
70         /// </devdoc>
71         [XmlAttribute("name")]
72         public string Name { 
73             get { return name; }
74             set { name = value; }
75         }
76         
77         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.RefName"]/*' />
78         /// <devdoc>
79         ///    <para>[To be supplied.]</para>
80         /// </devdoc>
81         [XmlAttribute("ref")]
82         public XmlQualifiedName RefName { 
83             get { return refName; }
84             set { refName = (value == null ? XmlQualifiedName.Empty : value); }
85         }
86         
87         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.SchemaTypeName"]/*' />
88         /// <devdoc>
89         ///    <para>[To be supplied.]</para>
90         /// </devdoc>
91         [XmlAttribute("type")]
92         public XmlQualifiedName SchemaTypeName { 
93             get { return typeName; }
94             set { typeName = (value == null ? XmlQualifiedName.Empty : value); }
95         }
96         
97         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.SchemaType"]/*' />
98         /// <devdoc>
99         ///    <para>[To be supplied.]</para>
100         /// </devdoc>
101         [XmlElement("simpleType")]
102         public XmlSchemaSimpleType SchemaType {
103             get { return type; }
104             set { type = value; }
105         }
106
107         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.Use"]/*' />
108         /// <devdoc>
109         ///    <para>[To be supplied.]</para>
110         /// </devdoc>
111         [XmlAttribute("use"), DefaultValue(XmlSchemaUse.None)]
112         public XmlSchemaUse Use {
113             get { return use; }
114             set { use = value; }
115         }
116
117         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.QualifiedName"]/*' />
118         /// <devdoc>
119         ///    <para>[To be supplied.]</para>
120         /// </devdoc>
121         [XmlIgnore]
122         public XmlQualifiedName QualifiedName { 
123             get { return qualifiedName; }
124         }
125
126         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.AttributeType"]/*' />
127         /// <devdoc>
128         ///    <para>[To be supplied.]</para>
129         /// </devdoc>
130         [XmlIgnore]
131         [Obsolete("This property has been deprecated. Please use AttributeSchemaType property that returns a strongly typed attribute type. http://go.microsoft.com/fwlink/?linkid=14202")]
132         public object AttributeType {
133             get {
134                 if (attributeType == null)
135                     return null;
136
137                 if (attributeType.QualifiedName.Namespace == XmlReservedNs.NsXs) {
138                     return attributeType.Datatype;
139                 } 
140                 return attributeType;
141             }
142         }
143         
144         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.AttributeSchemaType"]/*' />
145         /// <devdoc>
146         ///    <para>[To be supplied.]</para>
147         /// </devdoc>
148         [XmlIgnore]
149         public XmlSchemaSimpleType AttributeSchemaType {
150             get { return attributeType; }
151         }
152
153         internal XmlReader Validate(XmlReader reader, XmlResolver resolver, XmlSchemaSet schemaSet, ValidationEventHandler valEventHandler) {
154             if (schemaSet != null) {
155                 XmlReaderSettings readerSettings = new XmlReaderSettings();
156                 readerSettings.ValidationType = ValidationType.Schema;
157                 readerSettings.Schemas = schemaSet;
158                 readerSettings.ValidationEventHandler += valEventHandler;                
159                 return new XsdValidatingReader(reader, resolver, readerSettings, this);
160             }
161             return null;
162         }
163
164         [XmlIgnore]
165         internal XmlSchemaDatatype Datatype {
166             get { 
167                 if (attributeType != null) {
168                     return attributeType.Datatype; 
169                 }
170                 return null;
171             }
172         }
173
174         internal void  SetQualifiedName(XmlQualifiedName value) { 
175             qualifiedName = value;
176         }
177
178         internal void SetAttributeType(XmlSchemaSimpleType value) { 
179             attributeType = value;
180         }
181
182         internal SchemaAttDef AttDef {
183             get { return attDef; }
184             set { attDef = value; }
185         }
186
187         internal bool HasDefault {
188             get { return defaultValue != null; }
189         }
190
191         [XmlIgnore]
192         internal override string NameAttribute {
193             get { return Name; }
194             set { Name = value; }
195         }
196
197          internal override XmlSchemaObject Clone() {
198             XmlSchemaAttribute newAtt = (XmlSchemaAttribute)MemberwiseClone();
199
200             //Deep clone the QNames as these will be updated on chameleon includes
201             newAtt.refName = this.refName.Clone();
202             newAtt.typeName = this.typeName.Clone();
203             newAtt.qualifiedName = this.qualifiedName.Clone();
204             return newAtt;
205         }
206     }
207 }