XmlSchemaComplexContentExtension.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Xml;
  5. using System.Xml.Serialization;
  6. namespace System.Xml.Schema
  7. {
  8. /// <summary>
  9. /// Summary description for XmlSchemaComplexContentExtension.
  10. /// </summary>
  11. public class XmlSchemaComplexContentExtension : XmlSchemaContent
  12. {
  13. private XmlSchemaAnyAttribute any;
  14. private XmlSchemaObjectCollection attributes;
  15. private XmlQualifiedName baseTypeName;
  16. private XmlSchemaParticle particle;
  17. private static string xmlname = "extension";
  18. public XmlSchemaComplexContentExtension()
  19. {
  20. attributes = new XmlSchemaObjectCollection();
  21. baseTypeName = XmlQualifiedName.Empty;
  22. }
  23. [System.Xml.Serialization.XmlAttribute("base")]
  24. public XmlQualifiedName BaseTypeName
  25. {
  26. get{ return baseTypeName; }
  27. set{ baseTypeName = value; }
  28. }
  29. [XmlElement("group",typeof(XmlSchemaGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]
  30. [XmlElement("all",typeof(XmlSchemaAll),Namespace="http://www.w3.org/2001/XMLSchema")]
  31. [XmlElement("choice",typeof(XmlSchemaChoice),Namespace="http://www.w3.org/2001/XMLSchema")]
  32. [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace="http://www.w3.org/2001/XMLSchema")]
  33. public XmlSchemaParticle Particle
  34. {
  35. get{ return particle; }
  36. set{ particle = value; }
  37. }
  38. [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace="http://www.w3.org/2001/XMLSchema")]
  39. [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]
  40. public XmlSchemaObjectCollection Attributes
  41. {
  42. get{ return attributes; }
  43. }
  44. [XmlElement("anyAttribute",Namespace="http://www.w3.org/2001/XMLSchema")]
  45. public XmlSchemaAnyAttribute AnyAttribute
  46. {
  47. get{ return any; }
  48. set{ any = value;}
  49. }
  50. /// <remarks>
  51. /// </remarks>
  52. [MonoTODO]
  53. internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
  54. {
  55. if(BaseTypeName == null || BaseTypeName.IsEmpty)
  56. {
  57. error(h, "base must be present and a QName");
  58. }
  59. else if(!XmlSchemaUtil.CheckQName(BaseTypeName))
  60. error(h,"BaseTypeName is not a valid XmlQualifiedName");
  61. if(this.AnyAttribute != null)
  62. {
  63. errorCount += AnyAttribute.Compile(h,info);
  64. }
  65. foreach(XmlSchemaObject obj in Attributes)
  66. {
  67. if(obj is XmlSchemaAttribute)
  68. {
  69. XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
  70. errorCount += attr.Compile(h,info);
  71. }
  72. else if(obj is XmlSchemaAttributeGroupRef)
  73. {
  74. XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
  75. errorCount += atgrp.Compile(h,info);
  76. }
  77. else
  78. error(h,obj.GetType() +" is not valid in this place::ComplexConetnetExtension");
  79. }
  80. if(Particle != null)
  81. {
  82. if(Particle is XmlSchemaGroupRef)
  83. {
  84. errorCount += ((XmlSchemaGroupRef)Particle).Compile(h,info);
  85. }
  86. else if(Particle is XmlSchemaAll)
  87. {
  88. errorCount += ((XmlSchemaAll)Particle).Compile(h,info);
  89. }
  90. else if(Particle is XmlSchemaChoice)
  91. {
  92. errorCount += ((XmlSchemaChoice)Particle).Compile(h,info);
  93. }
  94. else if(Particle is XmlSchemaSequence)
  95. {
  96. errorCount += ((XmlSchemaSequence)Particle).Compile(h,info);
  97. }
  98. }
  99. XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h);
  100. return errorCount;
  101. }
  102. [MonoTODO]
  103. internal int Validate(ValidationEventHandler h)
  104. {
  105. return errorCount;
  106. }
  107. //<extension
  108. // base = QName
  109. // id = ID
  110. // {any attributes with non-schema namespace . . .}>
  111. // Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
  112. //</extension>
  113. internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
  114. {
  115. XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
  116. reader.MoveToElement();
  117. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  118. {
  119. error(h,"Should not happen :1: XmlSchemaComplexContentExtension.Read, name="+reader.Name,null);
  120. reader.Skip();
  121. return null;
  122. }
  123. extension.LineNumber = reader.LineNumber;
  124. extension.LinePosition = reader.LinePosition;
  125. extension.SourceUri = reader.BaseURI;
  126. while(reader.MoveToNextAttribute())
  127. {
  128. if(reader.Name == "base")
  129. {
  130. Exception innerex;
  131. extension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
  132. if(innerex != null)
  133. error(h, reader.Value + " is not a valid value for base attribute",innerex);
  134. }
  135. else if(reader.Name == "id")
  136. {
  137. extension.Id = reader.Value;
  138. }
  139. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  140. {
  141. error(h,reader.Name + " is not a valid attribute for extension",null);
  142. }
  143. else
  144. {
  145. XmlSchemaUtil.ReadUnhandledAttribute(reader,extension);
  146. }
  147. }
  148. reader.MoveToElement();
  149. if(reader.IsEmptyElement)
  150. return extension;
  151. //Content: 1. annotation?,
  152. // (2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?)))
  153. int level = 1;
  154. while(reader.ReadNextElement())
  155. {
  156. if(reader.NodeType == XmlNodeType.EndElement)
  157. {
  158. if(reader.LocalName != xmlname)
  159. error(h,"Should not happen :2: XmlSchemaComplexContentExtension.Read, name="+reader.Name,null);
  160. break;
  161. }
  162. if(level <= 1 && reader.LocalName == "annotation")
  163. {
  164. level = 2; //Only one annotation
  165. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  166. if(annotation != null)
  167. extension.Annotation = annotation;
  168. continue;
  169. }
  170. if(level <= 2)
  171. {
  172. if(reader.LocalName == "group")
  173. {
  174. level = 3;
  175. XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader,h);
  176. if(group != null)
  177. extension.particle = group;
  178. continue;
  179. }
  180. if(reader.LocalName == "all")
  181. {
  182. level = 3;
  183. XmlSchemaAll all = XmlSchemaAll.Read(reader,h);
  184. if(all != null)
  185. extension.particle = all;
  186. continue;
  187. }
  188. if(reader.LocalName == "choice")
  189. {
  190. level = 3;
  191. XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
  192. if(choice != null)
  193. extension.particle = choice;
  194. continue;
  195. }
  196. if(reader.LocalName == "sequence")
  197. {
  198. level = 3;
  199. XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);
  200. if(sequence != null)
  201. extension.particle = sequence;
  202. continue;
  203. }
  204. }
  205. if(level <= 3)
  206. {
  207. if(reader.LocalName == "attribute")
  208. {
  209. level = 3;
  210. XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
  211. if(attr != null)
  212. extension.Attributes.Add(attr);
  213. continue;
  214. }
  215. if(reader.LocalName == "attributeGroup")
  216. {
  217. level = 3;
  218. XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
  219. if(attr != null)
  220. extension.attributes.Add(attr);
  221. continue;
  222. }
  223. }
  224. if(level <= 4 && reader.LocalName == "anyAttribute")
  225. {
  226. level = 5;
  227. XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
  228. if(anyattr != null)
  229. extension.AnyAttribute = anyattr;
  230. continue;
  231. }
  232. reader.RaiseInvalidElementError();
  233. }
  234. return extension;
  235. }
  236. }
  237. }