2002-05-25 Dwivedi, Ajay kumar <adwiv@yahoo.com>
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaSimpleContentRestriction.cs
1 // Author: Dwivedi, Ajay kumar\r
2 //            Adwiv@Yahoo.com\r
3 using System;\r
4 using System.Xml;\r
5 using System.Xml.Serialization;\r
6 \r
7 namespace System.Xml.Schema\r
8 {\r
9         /// <summary>\r
10         /// Summary description for XmlSchemaSimpleContentRestriction.\r
11         /// </summary>\r
12         public class XmlSchemaSimpleContentRestriction : XmlSchemaContent\r
13         {\r
14                 \r
15                 private XmlSchemaAnyAttribute any;\r
16                 private XmlSchemaObjectCollection attributes;\r
17                 private XmlSchemaSimpleType baseType;\r
18                 private XmlQualifiedName baseTypeName;\r
19                 private XmlSchemaObjectCollection facets;\r
20                 private int errorCount=0;\r
21 \r
22                 public XmlSchemaSimpleContentRestriction()\r
23                 {\r
24                         baseTypeName = XmlQualifiedName.Empty;\r
25                         attributes       = new XmlSchemaObjectCollection();\r
26                         facets           = new XmlSchemaObjectCollection();\r
27                 }\r
28 \r
29                 [System.Xml.Serialization.XmlAttribute("base")]\r
30                 public XmlQualifiedName BaseTypeName \r
31                 {\r
32                         get{ return  baseTypeName; }\r
33                         set{ baseTypeName = value; }\r
34                 }\r
35 \r
36                 [XmlElement("anyAttribute",Namespace="http://www.w3.org/2001/XMLSchema")]\r
37                 public XmlSchemaAnyAttribute AnyAttribute \r
38                 {\r
39                         get{ return  any; }\r
40                         set{ any = value; }\r
41                 }\r
42 \r
43                 [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace="http://www.w3.org/2001/XMLSchema")]\r
44                 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]\r
45                 public XmlSchemaObjectCollection Attributes \r
46                 {\r
47                         get{ return attributes; }\r
48                 }\r
49 \r
50                 [XmlElement("simpleType",Namespace="http://www.w3.org/2001/XMLSchema")]\r
51                 public XmlSchemaSimpleType BaseType \r
52                 { \r
53                         get{ return  baseType; } \r
54                         set{ baseType = value; } \r
55                 }\r
56                 \r
57                 \r
58                 [XmlElement("minExclusive",typeof(XmlSchemaMinExclusiveFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
59                 [XmlElement("minInclusive",typeof(XmlSchemaMinInclusiveFacet),Namespace="http://www.w3.org/2001/XMLSchema")] \r
60                 [XmlElement("maxExclusive",typeof(XmlSchemaMaxExclusiveFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
61                 [XmlElement("maxInclusive",typeof(XmlSchemaMaxInclusiveFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
62                 [XmlElement("totalDigits",typeof(XmlSchemaTotalDigitsFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
63                 [XmlElement("fractionDigits",typeof(XmlSchemaFractionDigitsFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
64                 [XmlElement("length",typeof(XmlSchemaLengthFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
65                 [XmlElement("minLength",typeof(XmlSchemaMinLengthFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
66                 [XmlElement("maxLength",typeof(XmlSchemaMaxLengthFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
67                 [XmlElement("enumeration",typeof(XmlSchemaEnumerationFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
68                 [XmlElement("whiteSpace",typeof(XmlSchemaWhiteSpaceFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
69                 [XmlElement("pattern",typeof(XmlSchemaPatternFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
70                 public XmlSchemaObjectCollection Facets \r
71                 { \r
72                         get{ return facets; } \r
73                 }\r
74                 ///<remarks>\r
75                 /// 1. Base must be present and a QName\r
76                 ///</remarks>\r
77                 [MonoTODO]\r
78                 internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
79                 {\r
80                         if(BaseTypeName == null || BaseTypeName.IsEmpty)\r
81                         {\r
82                                 error(h, "base must be present and a QName");\r
83                         }\r
84 \r
85                         if(BaseType != null)\r
86                         {\r
87                                 errorCount += BaseType.Compile(h,info);\r
88                         }\r
89 \r
90                         if(this.AnyAttribute != null)\r
91                         {\r
92                                 errorCount += AnyAttribute.Compile(h,info);\r
93                         }\r
94 \r
95                         foreach(XmlSchemaObject obj in Attributes)\r
96                         {\r
97                                 if(obj is XmlSchemaAttribute)\r
98                                 {\r
99                                         XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;\r
100                                         errorCount += attr.Compile(h,info);\r
101                                 }\r
102                                 else if(obj is XmlSchemaAttributeGroupRef)\r
103                                 {\r
104                                         XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;\r
105                                         errorCount += atgrp.Compile(h,info);\r
106                                 }\r
107                                 else\r
108                                         error(h,"object is not valid in this place");\r
109                         }\r
110                         \r
111                         //TODO: Compile Facets: Looks like they are a part of datatypes. So we'll do them with the datatypes\r
112 \r
113                         if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
114                                 error(h, "id must be a valid ID");\r
115                         return errorCount;\r
116                 }\r
117                 \r
118                 [MonoTODO]\r
119                 internal int Validate(ValidationEventHandler h)\r
120                 {\r
121                         return errorCount;\r
122                 }\r
123 \r
124                 internal void error(ValidationEventHandler handle,string message)\r
125                 {\r
126                         errorCount++;\r
127                         ValidationHandler.RaiseValidationError(handle,this,message);\r
128                 }\r
129         }\r
130 }\r