2 // System.Xml.Schema.XmlSchemaSimpleContentExtension.cs
\r
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
\r
6 // Atsushi Enomoto ginga@kit.hi-ho.ne.jp
\r
10 using System.Xml.Serialization;
\r
12 namespace System.Xml.Schema
\r
15 /// Summary description for XmlSchemaSimpleContentExtension.
\r
17 public class XmlSchemaSimpleContentExtension : XmlSchemaContent
\r
20 private XmlSchemaAnyAttribute any;
\r
21 private XmlSchemaObjectCollection attributes;
\r
22 private XmlQualifiedName baseTypeName;
\r
23 private static string xmlname = "extension";
\r
25 public XmlSchemaSimpleContentExtension()
\r
27 baseTypeName = XmlQualifiedName.Empty;
\r
28 attributes = new XmlSchemaObjectCollection();
\r
31 [System.Xml.Serialization.XmlAttribute("base")]
\r
32 public XmlQualifiedName BaseTypeName
\r
34 get{ return baseTypeName; }
\r
35 set{ baseTypeName = value; }
\r
38 [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace=XmlSchema.Namespace)]
\r
39 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace=XmlSchema.Namespace)]
\r
40 public XmlSchemaObjectCollection Attributes
\r
42 get{ return attributes; }
\r
45 [XmlElement("anyAttribute",Namespace=XmlSchema.Namespace)]
\r
46 public XmlSchemaAnyAttribute AnyAttribute
\r
53 /// 1. Base must be present and a QName
\r
55 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
57 // If this is already compiled this time, simply skip.
\r
58 if (this.IsComplied (schema.CompilationId))
\r
61 if (this.isRedefinedComponent) {
\r
62 if (Annotation != null)
\r
63 Annotation.isRedefinedComponent = true;
\r
64 if (AnyAttribute != null)
\r
65 AnyAttribute.isRedefinedComponent = true;
\r
66 foreach (XmlSchemaObject obj in Attributes)
\r
67 obj.isRedefinedComponent = true;
\r
70 if(BaseTypeName == null || BaseTypeName.IsEmpty)
\r
72 error(h, "base must be present, as a QName");
\r
74 else if(!XmlSchemaUtil.CheckQName(BaseTypeName))
\r
75 error(h,"BaseTypeName must be a QName");
\r
77 if(this.AnyAttribute != null)
\r
79 errorCount += AnyAttribute.Compile(h,schema);
\r
82 foreach(XmlSchemaObject obj in Attributes)
\r
84 if(obj is XmlSchemaAttribute)
\r
86 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
87 errorCount += attr.Compile(h,schema);
\r
89 else if(obj is XmlSchemaAttributeGroupRef)
\r
91 XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
\r
92 errorCount += atgrp.Compile(h,schema);
\r
95 error(h,obj.GetType() +" is not valid in this place::SimpleConentExtension");
\r
98 XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
\r
100 this.CompilationId = schema.CompilationId;
\r
104 internal override XmlQualifiedName GetBaseTypeName ()
\r
106 return baseTypeName;
\r
109 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
111 if (IsValidated (schema.ValidationId))
\r
114 XmlSchemaType st = schema.SchemaTypes [baseTypeName] as XmlSchemaType;
\r
116 XmlSchemaComplexType ct = st as XmlSchemaComplexType;
\r
117 if (ct != null && ct.ContentModel is XmlSchemaComplexContent)
\r
118 error (h, "Specified type is complex type which contains complex content.");
\r
119 st.Validate (h, schema);
\r
120 actualBaseSchemaType = st;
\r
121 } else if (baseTypeName == XmlSchemaComplexType.AnyTypeName) {
\r
122 actualBaseSchemaType = XmlSchemaComplexType.AnyType;
123 } else if (baseTypeName.Namespace == XmlSchema.Namespace) {
\r
124 actualBaseSchemaType = XmlSchemaDatatype.FromName (baseTypeName);
\r
125 if (actualBaseSchemaType == null)
\r
126 error (h, "Invalid schema datatype name is specified.");
\r
128 // otherwise, it might be missing sub components.
\r
129 else if (!schema.IsNamespaceAbsent (baseTypeName.Namespace))
\r
130 error (h, "Referenced base schema type " + baseTypeName + " was not found in the corresponding schema.");
\r
132 ValidationId = schema.ValidationId;
\r
139 //{any attributes with non-schema namespace . . .}>
\r
140 //Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
\r
142 internal static XmlSchemaSimpleContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
144 XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();
\r
145 reader.MoveToElement();
\r
147 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
149 error(h,"Should not happen :1: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);
\r
154 extension.LineNumber = reader.LineNumber;
\r
155 extension.LinePosition = reader.LinePosition;
\r
156 extension.SourceUri = reader.BaseURI;
\r
158 while(reader.MoveToNextAttribute())
\r
160 if(reader.Name == "base")
\r
163 extension.baseTypeName= XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
164 if(innerex != null)
\r
165 error(h, reader.Value + " is not a valid value for base attribute",innerex);
\r
167 else if(reader.Name == "id")
\r
169 extension.Id = reader.Value;
\r
171 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
173 error(h,reader.Name + " is not a valid attribute for extension in this context",null);
\r
177 XmlSchemaUtil.ReadUnhandledAttribute(reader,extension);
\r
181 reader.MoveToElement();
\r
182 if(reader.IsEmptyElement)
\r
185 //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute?
\r
187 while(reader.ReadNextElement())
\r
189 if(reader.NodeType == XmlNodeType.EndElement)
\r
191 if(reader.LocalName != xmlname)
\r
192 error(h,"Should not happen :2: XmlSchemaSimpleContentExtension.Read, name="+reader.Name,null);
\r
195 if(level <= 1 && reader.LocalName == "annotation")
\r
197 level = 2; //Only one annotation
\r
198 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
199 if(annotation != null)
\r
200 extension.Annotation = annotation;
\r
205 if(reader.LocalName == "attribute")
\r
208 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
210 extension.Attributes.Add(attr);
\r
213 if(reader.LocalName == "attributeGroup")
\r
216 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
218 extension.attributes.Add(attr);
\r
222 if(level <= 3 && reader.LocalName == "anyAttribute")
\r
225 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
226 if(anyattr != null)
\r
227 extension.AnyAttribute = anyattr;
\r
230 reader.RaiseInvalidElementError();
\r