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 const 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
74 // internal properties
\r
75 internal override bool IsExtension {
\r
76 get { return false; }
\r
80 /// 1. Base must be present and a QName
\r
82 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
84 // If this is already compiled this time, simply skip.
\r
85 if (this.IsComplied (schema.CompilationId))
\r
88 if (this.isRedefinedComponent) {
\r
89 if (Annotation != null)
\r
90 Annotation.isRedefinedComponent = true;
\r
91 if (AnyAttribute != null)
\r
92 AnyAttribute.isRedefinedComponent = true;
\r
93 foreach (XmlSchemaObject obj in Attributes)
\r
94 obj.isRedefinedComponent = true;
\r
97 if(BaseTypeName == null || BaseTypeName.IsEmpty)
\r
99 error(h, "base must be present, as a QName");
\r
101 else if(!XmlSchemaUtil.CheckQName(BaseTypeName))
\r
102 error(h,"BaseTypeName must be a QName");
\r
104 if(BaseType != null)
\r
106 errorCount += BaseType.Compile(h,schema);
\r
109 if(this.AnyAttribute != null)
\r
111 errorCount += AnyAttribute.Compile(h,schema);
\r
114 foreach(XmlSchemaObject obj in Attributes)
\r
116 if(obj is XmlSchemaAttribute)
\r
118 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
119 errorCount += attr.Compile(h,schema);
\r
121 else if(obj is XmlSchemaAttributeGroupRef)
\r
123 XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
\r
124 errorCount += atgrp.Compile(h,schema);
\r
127 error(h,obj.GetType() +" is not valid in this place::SimpleContentRestriction");
\r
130 //TODO: Compile Facets: Looks like they are a part of datatypes. So we'll do them with the datatypes
\r
133 XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
\r
134 this.CompilationId = schema.CompilationId;
\r
138 internal override XmlQualifiedName GetBaseTypeName ()
\r
140 return baseTypeName;
\r
143 internal override XmlSchemaParticle GetParticle ()
\r
148 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
150 if (IsValidated (schema.ValidationId))
\r
153 if (baseType != null) {
\r
154 baseType.Validate (h, schema);
\r
155 actualBaseSchemaType = baseType;
\r
157 else if (baseTypeName != XmlQualifiedName.Empty) {
\r
158 XmlSchemaType st = schema.SchemaTypes [baseTypeName] as XmlSchemaType;
\r
160 st.Validate (h, schema);
\r
161 actualBaseSchemaType = st;
\r
162 } else if (baseTypeName == XmlSchemaComplexType.AnyTypeName) {
\r
163 actualBaseSchemaType = XmlSchemaComplexType.AnyType;
164 } else if (XmlSchemaUtil.IsBuiltInDatatypeName (baseTypeName)) {
\r
165 actualBaseSchemaType = XmlSchemaDatatype.FromName (baseTypeName);
\r
166 if (actualBaseSchemaType == null)
\r
167 error (h, "Invalid schema datatype name is specified.");
\r
169 // otherwise, it might be missing sub components.
\r
170 else if (!schema.IsNamespaceAbsent (baseTypeName.Namespace))
\r
171 error (h, "Referenced base schema type " + baseTypeName + " was not found in the corresponding schema.");
\r
174 ValidationId = schema.ValidationId;
\r
181 //{any attributes with non-schema namespace . . .}>
\r
182 //Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))
\r
184 internal static XmlSchemaSimpleContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
186 XmlSchemaSimpleContentRestriction restriction = new XmlSchemaSimpleContentRestriction();
\r
187 reader.MoveToElement();
\r
189 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
191 error(h,"Should not happen :1: XmlSchemaComplexContentRestriction.Read, name="+reader.Name,null);
\r
192 reader.SkipToEnd();
\r
196 restriction.LineNumber = reader.LineNumber;
\r
197 restriction.LinePosition = reader.LinePosition;
\r
198 restriction.SourceUri = reader.BaseURI;
\r
200 while(reader.MoveToNextAttribute())
\r
202 if(reader.Name == "base")
\r
205 restriction.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
206 if(innerex != null)
\r
207 error(h, reader.Value + " is not a valid value for base attribute",innerex);
\r
209 else if(reader.Name == "id")
\r
211 restriction.Id = reader.Value;
\r
213 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
215 error(h,reader.Name + " is not a valid attribute for restriction",null);
\r
219 XmlSchemaUtil.ReadUnhandledAttribute(reader,restriction);
\r
223 reader.MoveToElement();
\r
224 if(reader.IsEmptyElement)
\r
225 return restriction;
\r
227 //Content: 1.annotation?,
\r
229 // 3.(minExclusive |...| enumeration | whiteSpace | pattern)*,
\r
230 // 4.(attribute | attributeGroup)*,
\r
233 while(reader.ReadNextElement())
\r
235 if(reader.NodeType == XmlNodeType.EndElement)
\r
237 if(reader.LocalName != xmlname)
\r
238 error(h,"Should not happen :2: XmlSchemaSimpleContentRestriction.Read, name="+reader.Name,null);
\r
241 if(level <= 1 && reader.LocalName == "annotation")
\r
243 level = 2; //Only one annotation
\r
244 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
245 if(annotation != null)
\r
246 restriction.Annotation = annotation;
\r
249 if(level <=2 && reader.LocalName == "simpleType")
\r
252 XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader,h);
\r
254 restriction.baseType = stype;
\r
259 if(reader.LocalName == "minExclusive")
\r
262 XmlSchemaMinExclusiveFacet minex = XmlSchemaMinExclusiveFacet.Read(reader,h);
\r
264 restriction.facets.Add(minex);
\r
267 else if(reader.LocalName == "minInclusive")
\r
270 XmlSchemaMinInclusiveFacet mini = XmlSchemaMinInclusiveFacet.Read(reader,h);
\r
272 restriction.facets.Add(mini);
\r
275 else if(reader.LocalName == "maxExclusive")
\r
278 XmlSchemaMaxExclusiveFacet maxex = XmlSchemaMaxExclusiveFacet.Read(reader,h);
\r
280 restriction.facets.Add(maxex);
\r
283 else if(reader.LocalName == "maxInclusive")
\r
286 XmlSchemaMaxInclusiveFacet maxi = XmlSchemaMaxInclusiveFacet.Read(reader,h);
\r
288 restriction.facets.Add(maxi);
\r
291 else if(reader.LocalName == "totalDigits")
\r
294 XmlSchemaTotalDigitsFacet total = XmlSchemaTotalDigitsFacet.Read(reader,h);
\r
296 restriction.facets.Add(total);
\r
299 else if(reader.LocalName == "fractionDigits")
\r
302 XmlSchemaFractionDigitsFacet fraction = XmlSchemaFractionDigitsFacet.Read(reader,h);
\r
303 if(fraction != null)
\r
304 restriction.facets.Add(fraction);
\r
307 else if(reader.LocalName == "length")
\r
310 XmlSchemaLengthFacet length = XmlSchemaLengthFacet.Read(reader,h);
\r
312 restriction.facets.Add(length);
\r
315 else if(reader.LocalName == "minLength")
\r
318 XmlSchemaMinLengthFacet minlen = XmlSchemaMinLengthFacet.Read(reader,h);
\r
320 restriction.facets.Add(minlen);
\r
323 else if(reader.LocalName == "maxLength")
\r
326 XmlSchemaMaxLengthFacet maxlen = XmlSchemaMaxLengthFacet.Read(reader,h);
\r
328 restriction.facets.Add(maxlen);
\r
331 else if(reader.LocalName == "enumeration")
\r
334 XmlSchemaEnumerationFacet enumeration = XmlSchemaEnumerationFacet.Read(reader,h);
\r
335 if(enumeration != null)
\r
336 restriction.facets.Add(enumeration);
\r
339 else if(reader.LocalName == "whiteSpace")
\r
342 XmlSchemaWhiteSpaceFacet ws = XmlSchemaWhiteSpaceFacet.Read(reader,h);
\r
344 restriction.facets.Add(ws);
\r
347 else if(reader.LocalName == "pattern")
\r
350 XmlSchemaPatternFacet pattern = XmlSchemaPatternFacet.Read(reader,h);
\r
351 if(pattern != null)
\r
352 restriction.facets.Add(pattern);
\r
358 if(reader.LocalName == "attribute")
\r
361 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
363 restriction.Attributes.Add(attr);
\r
366 if(reader.LocalName == "attributeGroup")
\r
369 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
371 restriction.attributes.Add(attr);
\r
375 if(level <= 5 && reader.LocalName == "anyAttribute")
\r
378 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
379 if(anyattr != null)
\r
380 restriction.AnyAttribute = anyattr;
\r
383 reader.RaiseInvalidElementError();
\r
385 return restriction;
\r