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("simpleType",Namespace=XmlSchema.Namespace)]
\r
37 public XmlSchemaSimpleType BaseType
\r
39 get{ return baseType; }
\r
40 set{ baseType = value; }
\r
43 [XmlElement("minExclusive",typeof(XmlSchemaMinExclusiveFacet),Namespace=XmlSchema.Namespace)]
\r
44 [XmlElement("minInclusive",typeof(XmlSchemaMinInclusiveFacet),Namespace=XmlSchema.Namespace)]
\r
45 [XmlElement("maxExclusive",typeof(XmlSchemaMaxExclusiveFacet),Namespace=XmlSchema.Namespace)]
\r
46 [XmlElement("maxInclusive",typeof(XmlSchemaMaxInclusiveFacet),Namespace=XmlSchema.Namespace)]
\r
47 [XmlElement("totalDigits",typeof(XmlSchemaTotalDigitsFacet),Namespace=XmlSchema.Namespace)]
\r
48 [XmlElement("fractionDigits",typeof(XmlSchemaFractionDigitsFacet),Namespace=XmlSchema.Namespace)]
\r
49 [XmlElement("length",typeof(XmlSchemaLengthFacet),Namespace=XmlSchema.Namespace)]
\r
50 [XmlElement("minLength",typeof(XmlSchemaMinLengthFacet),Namespace=XmlSchema.Namespace)]
\r
51 [XmlElement("maxLength",typeof(XmlSchemaMaxLengthFacet),Namespace=XmlSchema.Namespace)]
\r
52 [XmlElement("enumeration",typeof(XmlSchemaEnumerationFacet),Namespace=XmlSchema.Namespace)]
\r
53 [XmlElement("whiteSpace",typeof(XmlSchemaWhiteSpaceFacet),Namespace=XmlSchema.Namespace)]
\r
54 [XmlElement("pattern",typeof(XmlSchemaPatternFacet),Namespace=XmlSchema.Namespace)]
\r
55 public XmlSchemaObjectCollection Facets
\r
57 get{ return facets; }
\r
60 [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace=XmlSchema.Namespace)]
\r
61 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace=XmlSchema.Namespace)]
\r
62 public XmlSchemaObjectCollection Attributes
\r
64 get{ return attributes; }
\r
67 [XmlElement("anyAttribute",Namespace=XmlSchema.Namespace)]
\r
68 public XmlSchemaAnyAttribute AnyAttribute
\r
75 /// 1. Base must be present and a QName
\r
78 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
80 // If this is already compiled this time, simply skip.
\r
81 if (this.IsComplied (schema.CompilationId))
\r
84 if (this.isRedefinedComponent) {
\r
85 if (Annotation != null)
\r
86 Annotation.isRedefinedComponent = true;
\r
87 if (AnyAttribute != null)
\r
88 AnyAttribute.isRedefinedComponent = true;
\r
89 foreach (XmlSchemaObject obj in Attributes)
\r
90 obj.isRedefinedComponent = true;
\r
93 if(BaseTypeName == null || BaseTypeName.IsEmpty)
\r
95 error(h, "base must be present, as a QName");
\r
97 else if(!XmlSchemaUtil.CheckQName(BaseTypeName))
\r
98 error(h,"BaseTypeName must be a QName");
\r
100 if(BaseType != null)
\r
102 errorCount += BaseType.Compile(h,schema);
\r
105 if(this.AnyAttribute != null)
\r
107 errorCount += AnyAttribute.Compile(h,schema);
\r
110 foreach(XmlSchemaObject obj in Attributes)
\r
112 if(obj is XmlSchemaAttribute)
\r
114 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
115 errorCount += attr.Compile(h,schema);
\r
117 else if(obj is XmlSchemaAttributeGroupRef)
\r
119 XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
\r
120 errorCount += atgrp.Compile(h,schema);
\r
123 error(h,obj.GetType() +" is not valid in this place::SimpleContentRestriction");
\r
126 //TODO: Compile Facets: Looks like they are a part of datatypes. So we'll do them with the datatypes
\r
129 XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
\r
130 this.CompilationId = schema.CompilationId;
\r
135 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
137 if (IsValidated (schema.ValidationId))
\r
140 if (baseType != null) {
\r
141 baseType.Validate (h, schema);
\r
142 actualBaseSchemaType = baseType;
\r
144 else if (baseTypeName != XmlQualifiedName.Empty) {
\r
145 XmlSchemaType st = schema.SchemaTypes [baseTypeName] as XmlSchemaType;
\r
147 st.Validate (h, schema);
\r
148 actualBaseSchemaType = st;
\r
149 } else if (baseTypeName == XmlSchemaComplexType.AnyTypeName) {
\r
150 actualBaseSchemaType = XmlSchemaComplexType.AnyType;
151 } else if (baseTypeName.Namespace == XmlSchema.Namespace) {
\r
152 actualBaseSchemaType = XmlSchemaDatatype.FromName (baseTypeName);
\r
153 if (actualBaseSchemaType == null)
\r
154 error (h, "Invalid schema datatype name is specified.");
\r
156 // otherwise, it might be missing sub components.
\r
157 else if (!schema.missedSubComponents)// && schema.Schemas [baseTypeName.Namespace] != null)
\r
158 error (h, "Referenced base schema type " + baseTypeName + " was not found in the corresponding schema.");
\r
161 ValidationId = schema.ValidationId;
\r
168 //{any attributes with non-schema namespace . . .}>
\r
169 //Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))
\r
171 internal static XmlSchemaSimpleContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
173 XmlSchemaSimpleContentRestriction restriction = new XmlSchemaSimpleContentRestriction();
\r
174 reader.MoveToElement();
\r
176 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
178 error(h,"Should not happen :1: XmlSchemaComplexContentRestriction.Read, name="+reader.Name,null);
\r
179 reader.SkipToEnd();
\r
183 restriction.LineNumber = reader.LineNumber;
\r
184 restriction.LinePosition = reader.LinePosition;
\r
185 restriction.SourceUri = reader.BaseURI;
\r
187 while(reader.MoveToNextAttribute())
\r
189 if(reader.Name == "base")
\r
192 restriction.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
193 if(innerex != null)
\r
194 error(h, reader.Value + " is not a valid value for base attribute",innerex);
\r
196 else if(reader.Name == "id")
\r
198 restriction.Id = reader.Value;
\r
200 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
202 error(h,reader.Name + " is not a valid attribute for restriction",null);
\r
206 XmlSchemaUtil.ReadUnhandledAttribute(reader,restriction);
\r
210 reader.MoveToElement();
\r
211 if(reader.IsEmptyElement)
\r
212 return restriction;
\r
214 //Content: 1.annotation?,
\r
216 // 3.(minExclusive |...| enumeration | whiteSpace | pattern)*,
\r
217 // 4.(attribute | attributeGroup)*,
\r
220 while(reader.ReadNextElement())
\r
222 if(reader.NodeType == XmlNodeType.EndElement)
\r
224 if(reader.LocalName != xmlname)
\r
225 error(h,"Should not happen :2: XmlSchemaSimpleContentRestriction.Read, name="+reader.Name,null);
\r
228 if(level <= 1 && reader.LocalName == "annotation")
\r
230 level = 2; //Only one annotation
\r
231 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
232 if(annotation != null)
\r
233 restriction.Annotation = annotation;
\r
236 if(level <=2 && reader.LocalName == "simpleType")
\r
239 XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader,h);
\r
241 restriction.baseType = stype;
\r
246 if(reader.LocalName == "minExclusive")
\r
249 XmlSchemaMinExclusiveFacet minex = XmlSchemaMinExclusiveFacet.Read(reader,h);
\r
251 restriction.facets.Add(minex);
\r
254 else if(reader.LocalName == "minInclusive")
\r
257 XmlSchemaMinInclusiveFacet mini = XmlSchemaMinInclusiveFacet.Read(reader,h);
\r
259 restriction.facets.Add(mini);
\r
262 else if(reader.LocalName == "maxExclusive")
\r
265 XmlSchemaMaxExclusiveFacet maxex = XmlSchemaMaxExclusiveFacet.Read(reader,h);
\r
267 restriction.facets.Add(maxex);
\r
270 else if(reader.LocalName == "maxInclusive")
\r
273 XmlSchemaMaxInclusiveFacet maxi = XmlSchemaMaxInclusiveFacet.Read(reader,h);
\r
275 restriction.facets.Add(maxi);
\r
278 else if(reader.LocalName == "totalDigits")
\r
281 XmlSchemaTotalDigitsFacet total = XmlSchemaTotalDigitsFacet.Read(reader,h);
\r
283 restriction.facets.Add(total);
\r
286 else if(reader.LocalName == "fractionDigits")
\r
289 XmlSchemaFractionDigitsFacet fraction = XmlSchemaFractionDigitsFacet.Read(reader,h);
\r
290 if(fraction != null)
\r
291 restriction.facets.Add(fraction);
\r
294 else if(reader.LocalName == "length")
\r
297 XmlSchemaLengthFacet length = XmlSchemaLengthFacet.Read(reader,h);
\r
299 restriction.facets.Add(length);
\r
302 else if(reader.LocalName == "minLength")
\r
305 XmlSchemaMinLengthFacet minlen = XmlSchemaMinLengthFacet.Read(reader,h);
\r
307 restriction.facets.Add(minlen);
\r
310 else if(reader.LocalName == "maxLength")
\r
313 XmlSchemaMaxLengthFacet maxlen = XmlSchemaMaxLengthFacet.Read(reader,h);
\r
315 restriction.facets.Add(maxlen);
\r
318 else if(reader.LocalName == "enumeration")
\r
321 XmlSchemaEnumerationFacet enumeration = XmlSchemaEnumerationFacet.Read(reader,h);
\r
322 if(enumeration != null)
\r
323 restriction.facets.Add(enumeration);
\r
326 else if(reader.LocalName == "whiteSpace")
\r
329 XmlSchemaWhiteSpaceFacet ws = XmlSchemaWhiteSpaceFacet.Read(reader,h);
\r
331 restriction.facets.Add(ws);
\r
334 else if(reader.LocalName == "pattern")
\r
337 XmlSchemaPatternFacet pattern = XmlSchemaPatternFacet.Read(reader,h);
\r
338 if(pattern != null)
\r
339 restriction.facets.Add(pattern);
\r
345 if(reader.LocalName == "attribute")
\r
348 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
350 restriction.Attributes.Add(attr);
\r
353 if(reader.LocalName == "attributeGroup")
\r
356 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
358 restriction.attributes.Add(attr);
\r
362 if(level <= 5 && reader.LocalName == "anyAttribute")
\r
365 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
366 if(anyattr != null)
\r
367 restriction.AnyAttribute = anyattr;
\r
370 reader.RaiseInvalidElementError();
\r
372 return restriction;
\r