1 // Author: Dwivedi, Ajay kumar
\r
4 using System.Xml.Serialization;
\r
7 namespace System.Xml.Schema
\r
10 /// Summary description for XmlSchemaSimpleType.
\r
12 public class XmlSchemaSimpleType : XmlSchemaType
\r
14 private XmlSchemaSimpleTypeContent content;
\r
16 internal bool islocal = true; // Assuming local means we have to specify islocal=false only in XmlSchema
\r
17 private int errorCount;
\r
19 public XmlSchemaSimpleType()
\r
23 [XmlElement("restriction",typeof(XmlSchemaSimpleTypeRestriction),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
24 [XmlElement("list",typeof(XmlSchemaSimpleTypeList),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
25 [XmlElement("union",typeof(XmlSchemaSimpleTypeUnion),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
26 public XmlSchemaSimpleTypeContent Content
\r
28 get{ return content; }
\r
29 set{ content = value; }
\r
33 /// For a simple Type:
\r
34 /// 1. Content must be present
\r
35 /// 2. id if present, must have be a valid ID
\r
36 /// a) If the simpletype is local
\r
37 /// 1- are from <xs:complexType name="simpleType"> and <xs:complexType name="localSimpleType">
\r
38 /// 1. name is prohibited
\r
39 /// 2. final is prohibited
\r
40 /// b) If the simpletype is toplevel
\r
41 /// 1- are from <xs:complexType name="simpleType"> and <xs:complexType name="topLevelSimpleType">
\r
42 /// 1. name is required, type must be NCName
\r
43 /// 2. Content is required
\r
44 /// 3. final can have values : #all | (list | union | restriction)
\r
45 /// 4. If final is set, finalResolved is same as final (but within the values of b.3)
\r
46 /// 5. If final is not set, the finalDefault of the schema (ie. only #all and restriction)
\r
47 /// 6. Base type is:
\r
48 /// 4.1 If restriction is chosen,the base type of restriction or elements
\r
49 /// 4.2 otherwise simple ur-type
\r
52 internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
\r
56 if(this.islocal) // a
\r
58 if(this.Name != null) // a.1
\r
59 error(h,"Name is prohibited in a local simpletype");
\r
60 if(this.Final != XmlSchemaDerivationMethod.None) //a.2
\r
61 error(h,"Final is prohibited in a local simpletype");
\r
65 if(this.Name == null) //b.1
\r
66 error(h,"Name is required in top level simpletype");
\r
67 else if(!XmlSchemaUtil.CheckNCName(this.Name)) // b.1.2
\r
68 error(h,"name attribute of a simpleType must be NCName");
\r
70 this.qName = new XmlQualifiedName(this.Name,info.targetNS);
\r
72 //NOTE: Although the FinalResolved can be Empty, it is not a valid value for Final
\r
73 //DEVIATION: If an error occurs, the finaldefault is always consulted. This deviates
\r
74 // from the way MS implementation works.
\r
75 switch(this.Final) //b.3, b.4
\r
77 // Invalid values: Throw error and use "prohibited substitutions"
\r
78 case XmlSchemaDerivationMethod.Substitution:
\r
79 error(h,"substition is not a valid value for final in a simpletype");
\r
80 goto case XmlSchemaDerivationMethod.None;
\r
81 case XmlSchemaDerivationMethod.Extension:
\r
82 error(h,"extension is not a valid value for final in a simpletype");
\r
83 goto case XmlSchemaDerivationMethod.None;
\r
84 case XmlSchemaDerivationMethod.Empty:
\r
85 error(h,"empty is not a valid value for final in simpletype");
\r
86 goto case XmlSchemaDerivationMethod.None;
\r
88 case XmlSchemaDerivationMethod.All:
\r
89 this.finalResolved = XmlSchemaDerivationMethod.All;
\r
91 case XmlSchemaDerivationMethod.List:
\r
92 this.finalResolved = XmlSchemaDerivationMethod.List;
\r
94 case XmlSchemaDerivationMethod.Union:
\r
95 this.finalResolved = XmlSchemaDerivationMethod.Union;
\r
97 case XmlSchemaDerivationMethod.Restriction:
\r
98 this.finalResolved = XmlSchemaDerivationMethod.Restriction;
\r
100 // If mutliple values are specified
\r
102 error(h,"simpletype can't have more than one value for final");
\r
103 goto case XmlSchemaDerivationMethod.None;
\r
104 // use assignment from finaldefault on schema.
\r
105 // The possible values of finalDefault on schema are #all | List of (extension | restriction)
\r
106 // Of these, the only possible values for us are #all | restriction.
\r
107 case XmlSchemaDerivationMethod.None: // b.5
\r
108 if(info.finalDefault == XmlSchemaDerivationMethod.All)
\r
109 finalResolved = XmlSchemaDerivationMethod.All;
\r
110 else // Either Restriction or Empty
\r
111 finalResolved = info.finalDefault & XmlSchemaDerivationMethod.Restriction;
\r
116 if(this.Id != null && !XmlSchemaUtil.CheckID(this.Id))
\r
117 error(h,"id must be a valid ID");
\r
119 if(this.Content == null) //a.3,b.2
\r
120 error(h,"Content is required in a simpletype");
\r
121 else if(Content is XmlSchemaSimpleTypeRestriction)
\r
123 errorCount += ((XmlSchemaSimpleTypeRestriction)Content).Compile(h,info);
\r
125 else if(Content is XmlSchemaSimpleTypeList)
\r
127 errorCount += ((XmlSchemaSimpleTypeList)Content).Compile(h,info);
\r
129 else if(Content is XmlSchemaSimpleTypeUnion)
\r
131 errorCount += ((XmlSchemaSimpleTypeUnion)Content).Compile(h,info);
\r
137 internal int Validate(ValidationEventHandler h)
\r
142 internal void error(ValidationEventHandler handle,string message)
\r
145 ValidationHandler.RaiseValidationError(handle,this,message);
\r