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 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Xml.Serialization;
\r
33 namespace System.Xml.Schema
\r
36 /// Summary description for XmlSchemaSimpleContentExtension.
\r
38 public class XmlSchemaSimpleContentExtension : XmlSchemaContent
\r
41 private XmlSchemaAnyAttribute any;
\r
42 private XmlSchemaObjectCollection attributes;
\r
43 private XmlQualifiedName baseTypeName;
\r
44 const string xmlname = "extension";
\r
46 public XmlSchemaSimpleContentExtension()
\r
48 baseTypeName = XmlQualifiedName.Empty;
\r
49 attributes = new XmlSchemaObjectCollection();
\r
52 [System.Xml.Serialization.XmlAttribute("base")]
\r
53 public XmlQualifiedName BaseTypeName
\r
55 get{ return baseTypeName; }
\r
56 set{ baseTypeName = value; }
\r
59 [XmlElement("attribute",typeof(XmlSchemaAttribute))]
\r
60 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef))]
\r
61 public XmlSchemaObjectCollection Attributes
\r
63 get{ return attributes; }
\r
66 [XmlElement("anyAttribute")]
\r
67 public XmlSchemaAnyAttribute AnyAttribute
\r
73 // internal properties
\r
74 internal override bool IsExtension {
\r
75 get { return true; }
\r
79 /// 1. Base must be present and a QName
\r
81 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
83 // If this is already compiled this time, simply skip.
\r
84 if (this.IsComplied (schema.CompilationId))
\r
88 if (AnyAttribute != null)
\r
89 AnyAttribute.Parent = this;
\r
90 foreach (XmlSchemaObject obj in Attributes)
\r
94 if (this.isRedefinedComponent) {
\r
95 if (Annotation != null)
\r
96 Annotation.isRedefinedComponent = true;
\r
97 if (AnyAttribute != null)
\r
98 AnyAttribute.isRedefinedComponent = true;
\r
99 foreach (XmlSchemaObject obj in Attributes)
\r
100 obj.isRedefinedComponent = true;
\r
103 if(BaseTypeName == null || BaseTypeName.IsEmpty)
\r
105 error(h, "base must be present, as a QName");
\r
107 else if(!XmlSchemaUtil.CheckQName(BaseTypeName))
\r
108 error(h,"BaseTypeName must be a QName");
\r
110 if(this.AnyAttribute != null)
\r
112 errorCount += AnyAttribute.Compile(h,schema);
\r
115 foreach(XmlSchemaObject obj in Attributes)
\r
117 if(obj is XmlSchemaAttribute)
\r
119 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
120 errorCount += attr.Compile(h,schema);
\r
122 else if(obj is XmlSchemaAttributeGroupRef)
\r
124 XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
\r
125 errorCount += atgrp.Compile(h,schema);
\r
128 error(h,obj.GetType() +" is not valid in this place::SimpleConentExtension");
\r
131 XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
\r
133 this.CompilationId = schema.CompilationId;
\r
137 internal override XmlQualifiedName GetBaseTypeName ()
\r
139 return baseTypeName;
\r
142 internal override XmlSchemaParticle GetParticle ()
\r
147 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
149 if (IsValidated (schema.ValidationId))
\r
152 XmlSchemaType st = schema.SchemaTypes [baseTypeName] as XmlSchemaType;
\r
154 XmlSchemaComplexType ct = st as XmlSchemaComplexType;
\r
155 if (ct != null && ct.ContentModel is XmlSchemaComplexContent)
\r
156 error (h, "Specified type is complex type which contains complex content.");
\r
157 st.Validate (h, schema);
\r
158 actualBaseSchemaType = st;
\r
159 } else if (baseTypeName == XmlSchemaComplexType.AnyTypeName) {
\r
160 actualBaseSchemaType = XmlSchemaComplexType.AnyType;
161 } else if (XmlSchemaUtil.IsBuiltInDatatypeName (baseTypeName)) {
\r
162 actualBaseSchemaType = XmlSchemaDatatype.FromName (baseTypeName);
\r
163 if (actualBaseSchemaType == null)
\r
164 error (h, "Invalid schema datatype name is specified.");
\r
166 // otherwise, it might be missing sub components.
\r
167 else if (!schema.IsNamespaceAbsent (baseTypeName.Namespace))
\r
168 error (h, "Referenced base schema type " + baseTypeName + " was not found in the corresponding schema.");
\r
170 ValidationId = schema.ValidationId;
\r
177 //{any attributes with non-schema namespace . . .}>
\r
178 //Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
\r
180 internal static XmlSchemaSimpleContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
182 XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();
\r
183 reader.MoveToElement();
\r
185 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
187 error(h,"Should not happen :1: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);
\r
192 extension.LineNumber = reader.LineNumber;
\r
193 extension.LinePosition = reader.LinePosition;
\r
194 extension.SourceUri = reader.BaseURI;
\r
196 while(reader.MoveToNextAttribute())
\r
198 if(reader.Name == "base")
\r
201 extension.baseTypeName= XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
202 if(innerex != null)
\r
203 error(h, reader.Value + " is not a valid value for base attribute",innerex);
\r
205 else if(reader.Name == "id")
\r
207 extension.Id = reader.Value;
\r
209 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
211 error(h,reader.Name + " is not a valid attribute for extension in this context",null);
\r
215 XmlSchemaUtil.ReadUnhandledAttribute(reader,extension);
\r
219 reader.MoveToElement();
\r
220 if(reader.IsEmptyElement)
\r
223 //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute?
\r
225 while(reader.ReadNextElement())
\r
227 if(reader.NodeType == XmlNodeType.EndElement)
\r
229 if(reader.LocalName != xmlname)
\r
230 error(h,"Should not happen :2: XmlSchemaSimpleContentExtension.Read, name="+reader.Name,null);
\r
233 if(level <= 1 && reader.LocalName == "annotation")
\r
235 level = 2; //Only one annotation
\r
236 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
237 if(annotation != null)
\r
238 extension.Annotation = annotation;
\r
243 if(reader.LocalName == "attribute")
\r
246 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
248 extension.Attributes.Add(attr);
\r
251 if(reader.LocalName == "attributeGroup")
\r
254 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
256 extension.attributes.Add(attr);
\r
260 if(level <= 3 && reader.LocalName == "anyAttribute")
\r
263 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
264 if(anyattr != null)
\r
265 extension.AnyAttribute = anyattr;
\r
268 reader.RaiseInvalidElementError();
\r