1 // Author: Dwivedi, Ajay kumar
\r
5 using System.Xml.Serialization;
\r
7 namespace System.Xml.Schema
\r
10 /// Summary description for XmlSchemaSimpleContentRestriction.
\r
12 public class XmlSchemaSimpleContentRestriction : XmlSchemaContent
\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 static string xmlname = "restriction";
\r
22 public XmlSchemaSimpleContentRestriction()
\r
24 baseTypeName = XmlQualifiedName.Empty;
\r
25 attributes = new XmlSchemaObjectCollection();
\r
26 facets = new XmlSchemaObjectCollection();
\r
29 [System.Xml.Serialization.XmlAttribute("base")]
\r
30 public XmlQualifiedName BaseTypeName
\r
32 get{ return baseTypeName; }
\r
33 set{ baseTypeName = value; }
\r
36 [XmlElement("anyAttribute",Namespace="http://www.w3.org/2001/XMLSchema")]
\r
37 public XmlSchemaAnyAttribute AnyAttribute
\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
47 get{ return attributes; }
\r
50 [XmlElement("simpleType",Namespace="http://www.w3.org/2001/XMLSchema")]
\r
51 public XmlSchemaSimpleType BaseType
\r
53 get{ return baseType; }
\r
54 set{ baseType = value; }
\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
72 get{ return facets; }
\r
75 /// 1. Base must be present and a QName
\r
78 internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
\r
80 if(BaseTypeName == null || BaseTypeName.IsEmpty)
\r
82 error(h, "base must be present and a QName");
\r
84 else if(!XmlSchemaUtil.CheckQName(BaseTypeName))
\r
85 error(h,"BaseTypeName must be a QName");
\r
87 if(BaseType != null)
\r
89 errorCount += BaseType.Compile(h,info);
\r
92 if(this.AnyAttribute != null)
\r
94 errorCount += AnyAttribute.Compile(h,info);
\r
97 foreach(XmlSchemaObject obj in Attributes)
\r
99 if(obj is XmlSchemaAttribute)
\r
101 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
102 errorCount += attr.Compile(h,info);
\r
104 else if(obj is XmlSchemaAttributeGroupRef)
\r
106 XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
\r
107 errorCount += atgrp.Compile(h,info);
\r
110 error(h,obj.GetType() +" is not valid in this place::SimpleContentRestriction");
\r
113 //TODO: Compile Facets: Looks like they are a part of datatypes. So we'll do them with the datatypes
\r
116 XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h);
\r
121 internal int Validate(ValidationEventHandler h)
\r
129 //{any attributes with non-schema namespace . . .}>
\r
130 //Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))
\r
132 internal static XmlSchemaSimpleContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
134 XmlSchemaSimpleContentRestriction restriction = new XmlSchemaSimpleContentRestriction();
\r
135 reader.MoveToElement();
\r
137 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
139 error(h,"Should not happen :1: XmlSchemaComplexContentRestriction.Read, name="+reader.Name,null);
\r
140 reader.SkipToEnd();
\r
144 restriction.LineNumber = reader.LineNumber;
\r
145 restriction.LinePosition = reader.LinePosition;
\r
146 restriction.SourceUri = reader.BaseURI;
\r
148 while(reader.MoveToNextAttribute())
\r
150 if(reader.Name == "base")
\r
153 restriction.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
154 if(innerex != null)
\r
155 error(h, reader.Value + " is not a valid value for base attribute",innerex);
\r
157 else if(reader.Name == "id")
\r
159 restriction.Id = reader.Value;
\r
161 else if(reader.NamespaceURI == "" || reader.NamespaceURI == XmlSchema.Namespace)
\r
163 error(h,reader.Name + " is not a valid attribute for restriction",null);
\r
167 if(reader.Prefix == "xmlns")
\r
168 restriction.Namespaces.Add(reader.LocalName, reader.Value);
\r
169 else if(reader.Name == "xmlns")
\r
170 restriction.Namespaces.Add("",reader.Value);
\r
171 //TODO: Add to Unhandled attributes
\r
175 reader.MoveToElement();
\r
176 if(reader.IsEmptyElement)
\r
177 return restriction;
\r
179 //Content: 1.annotation?,
\r
181 // 3.(minExclusive |...| enumeration | whiteSpace | pattern)*,
\r
182 // 4.(attribute | attributeGroup)*,
\r
185 while(reader.ReadNextElement())
\r
187 if(reader.NodeType == XmlNodeType.EndElement)
\r
189 if(reader.LocalName != xmlname)
\r
190 error(h,"Should not happen :2: XmlSchemaSimpleContentRestriction.Read, name="+reader.Name,null);
\r
193 if(level <= 1 && reader.LocalName == "annotation")
\r
195 level = 2; //Only one annotation
\r
196 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
197 if(annotation != null)
\r
198 restriction.Annotation = annotation;
\r
201 if(level <=2 && reader.LocalName == "simpleType")
\r
204 XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader,h);
\r
206 restriction.baseType = stype;
\r
211 if(reader.LocalName == "minExclusive")
\r
214 XmlSchemaMinExclusiveFacet minex = XmlSchemaMinExclusiveFacet.Read(reader,h);
\r
216 restriction.facets.Add(minex);
\r
219 else if(reader.LocalName == "minInclusive")
\r
222 XmlSchemaMinInclusiveFacet mini = XmlSchemaMinInclusiveFacet.Read(reader,h);
\r
224 restriction.facets.Add(mini);
\r
227 else if(reader.LocalName == "maxExclusive")
\r
230 XmlSchemaMaxExclusiveFacet maxex = XmlSchemaMaxExclusiveFacet.Read(reader,h);
\r
232 restriction.facets.Add(maxex);
\r
235 else if(reader.LocalName == "maxInclusive")
\r
238 XmlSchemaMaxInclusiveFacet maxi = XmlSchemaMaxInclusiveFacet.Read(reader,h);
\r
240 restriction.facets.Add(maxi);
\r
243 else if(reader.LocalName == "totalDigits")
\r
246 XmlSchemaTotalDigitsFacet total = XmlSchemaTotalDigitsFacet.Read(reader,h);
\r
248 restriction.facets.Add(total);
\r
251 else if(reader.LocalName == "fractionDigits")
\r
254 XmlSchemaFractionDigitsFacet fraction = XmlSchemaFractionDigitsFacet.Read(reader,h);
\r
255 if(fraction != null)
\r
256 restriction.facets.Add(fraction);
\r
259 else if(reader.LocalName == "length")
\r
262 XmlSchemaLengthFacet length = XmlSchemaLengthFacet.Read(reader,h);
\r
264 restriction.facets.Add(length);
\r
267 else if(reader.LocalName == "minLength")
\r
270 XmlSchemaMinLengthFacet minlen = XmlSchemaMinLengthFacet.Read(reader,h);
\r
272 restriction.facets.Add(minlen);
\r
275 else if(reader.LocalName == "maxLength")
\r
278 XmlSchemaMaxLengthFacet maxlen = XmlSchemaMaxLengthFacet.Read(reader,h);
\r
280 restriction.facets.Add(maxlen);
\r
283 else if(reader.LocalName == "enumeration")
\r
286 XmlSchemaEnumerationFacet enumeration = XmlSchemaEnumerationFacet.Read(reader,h);
\r
287 if(enumeration != null)
\r
288 restriction.facets.Add(enumeration);
\r
291 else if(reader.LocalName == "whiteSpace")
\r
294 XmlSchemaWhiteSpaceFacet ws = XmlSchemaWhiteSpaceFacet.Read(reader,h);
\r
296 restriction.facets.Add(ws);
\r
299 else if(reader.LocalName == "pattern")
\r
302 XmlSchemaPatternFacet pattern = XmlSchemaPatternFacet.Read(reader,h);
\r
303 if(pattern != null)
\r
304 restriction.facets.Add(pattern);
\r
310 if(reader.LocalName == "attribute")
\r
313 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
315 restriction.Attributes.Add(attr);
\r
318 if(reader.LocalName == "attributeGroup")
\r
321 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
323 restriction.attributes.Add(attr);
\r
327 if(level <= 5 && reader.LocalName == "anyAttribute")
\r
330 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
331 if(anyattr != null)
\r
332 restriction.AnyAttribute = anyattr;
\r
335 reader.RaiseInvalidElementError();
\r
337 return restriction;
\r