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 const 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
52 // internal properties
\r
53 internal override bool IsExtension {
\r
54 get { return true; }
\r
58 /// 1. Base must be present and a QName
\r
60 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
62 // If this is already compiled this time, simply skip.
\r
63 if (this.IsComplied (schema.CompilationId))
\r
66 if (this.isRedefinedComponent) {
\r
67 if (Annotation != null)
\r
68 Annotation.isRedefinedComponent = true;
\r
69 if (AnyAttribute != null)
\r
70 AnyAttribute.isRedefinedComponent = true;
\r
71 foreach (XmlSchemaObject obj in Attributes)
\r
72 obj.isRedefinedComponent = true;
\r
75 if(BaseTypeName == null || BaseTypeName.IsEmpty)
\r
77 error(h, "base must be present, as a QName");
\r
79 else if(!XmlSchemaUtil.CheckQName(BaseTypeName))
\r
80 error(h,"BaseTypeName must be a QName");
\r
82 if(this.AnyAttribute != null)
\r
84 errorCount += AnyAttribute.Compile(h,schema);
\r
87 foreach(XmlSchemaObject obj in Attributes)
\r
89 if(obj is XmlSchemaAttribute)
\r
91 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
92 errorCount += attr.Compile(h,schema);
\r
94 else if(obj is XmlSchemaAttributeGroupRef)
\r
96 XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
\r
97 errorCount += atgrp.Compile(h,schema);
\r
100 error(h,obj.GetType() +" is not valid in this place::SimpleConentExtension");
\r
103 XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
\r
105 this.CompilationId = schema.CompilationId;
\r
109 internal override XmlQualifiedName GetBaseTypeName ()
\r
111 return baseTypeName;
\r
114 internal override XmlSchemaParticle GetParticle ()
\r
119 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
121 if (IsValidated (schema.ValidationId))
\r
124 XmlSchemaType st = schema.SchemaTypes [baseTypeName] as XmlSchemaType;
\r
126 XmlSchemaComplexType ct = st as XmlSchemaComplexType;
\r
127 if (ct != null && ct.ContentModel is XmlSchemaComplexContent)
\r
128 error (h, "Specified type is complex type which contains complex content.");
\r
129 st.Validate (h, schema);
\r
130 actualBaseSchemaType = st;
\r
131 } else if (baseTypeName == XmlSchemaComplexType.AnyTypeName) {
\r
132 actualBaseSchemaType = XmlSchemaComplexType.AnyType;
133 } else if (XmlSchemaUtil.IsBuiltInDatatypeName (baseTypeName)) {
\r
134 actualBaseSchemaType = XmlSchemaDatatype.FromName (baseTypeName);
\r
135 if (actualBaseSchemaType == null)
\r
136 error (h, "Invalid schema datatype name is specified.");
\r
138 // otherwise, it might be missing sub components.
\r
139 else if (!schema.IsNamespaceAbsent (baseTypeName.Namespace))
\r
140 error (h, "Referenced base schema type " + baseTypeName + " was not found in the corresponding schema.");
\r
142 ValidationId = schema.ValidationId;
\r
149 //{any attributes with non-schema namespace . . .}>
\r
150 //Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
\r
152 internal static XmlSchemaSimpleContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
154 XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();
\r
155 reader.MoveToElement();
\r
157 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
159 error(h,"Should not happen :1: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);
\r
164 extension.LineNumber = reader.LineNumber;
\r
165 extension.LinePosition = reader.LinePosition;
\r
166 extension.SourceUri = reader.BaseURI;
\r
168 while(reader.MoveToNextAttribute())
\r
170 if(reader.Name == "base")
\r
173 extension.baseTypeName= XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
174 if(innerex != null)
\r
175 error(h, reader.Value + " is not a valid value for base attribute",innerex);
\r
177 else if(reader.Name == "id")
\r
179 extension.Id = reader.Value;
\r
181 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
183 error(h,reader.Name + " is not a valid attribute for extension in this context",null);
\r
187 XmlSchemaUtil.ReadUnhandledAttribute(reader,extension);
\r
191 reader.MoveToElement();
\r
192 if(reader.IsEmptyElement)
\r
195 //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute?
\r
197 while(reader.ReadNextElement())
\r
199 if(reader.NodeType == XmlNodeType.EndElement)
\r
201 if(reader.LocalName != xmlname)
\r
202 error(h,"Should not happen :2: XmlSchemaSimpleContentExtension.Read, name="+reader.Name,null);
\r
205 if(level <= 1 && reader.LocalName == "annotation")
\r
207 level = 2; //Only one annotation
\r
208 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
209 if(annotation != null)
\r
210 extension.Annotation = annotation;
\r
215 if(reader.LocalName == "attribute")
\r
218 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
220 extension.Attributes.Add(attr);
\r
223 if(reader.LocalName == "attributeGroup")
\r
226 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
228 extension.attributes.Add(attr);
\r
232 if(level <= 3 && reader.LocalName == "anyAttribute")
\r
235 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
236 if(anyattr != null)
\r
237 extension.AnyAttribute = anyattr;
\r
240 reader.RaiseInvalidElementError();
\r