XmlSchemaGroupRef.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 XmlSchemaGroupRef.
  10. /// </summary>
  11. public class XmlSchemaGroupRef : XmlSchemaParticle
  12. {
  13. private XmlSchemaGroupBase particle;
  14. private XmlQualifiedName refName;
  15. private static string xmlname = "group";
  16. public XmlSchemaGroupRef()
  17. {
  18. refName = XmlQualifiedName.Empty;
  19. }
  20. [System.Xml.Serialization.XmlAttribute("ref")]
  21. public XmlQualifiedName RefName
  22. {
  23. get{ return refName; }
  24. set{ refName = value; }
  25. }
  26. [XmlIgnore]
  27. public XmlSchemaGroupBase Particle
  28. {
  29. get{ return particle; }
  30. }
  31. /// <remarks>
  32. /// 1. RefName must be present
  33. /// </remarks>
  34. [MonoTODO]
  35. internal int Compile(ValidationEventHandler h, XmlSchema schema)
  36. {
  37. // If this is already compiled this time, simply skip.
  38. if (this.IsComplied (schema.CompilationId))
  39. return 0;
  40. //FIXME: Should we reset the values
  41. if(MinOccurs > MaxOccurs)
  42. error(h,"minOccurs must be less than or equal to maxOccurs");
  43. XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
  44. if(refName == null || refName.IsEmpty)
  45. {
  46. error(h,"ref must be present");
  47. }
  48. else if(!XmlSchemaUtil.CheckQName(RefName))
  49. error(h, "RefName must be a valid XmlQualifiedName");
  50. this.CompilationId = schema.CompilationId;
  51. return errorCount;
  52. }
  53. [MonoTODO]
  54. internal int Validate(ValidationEventHandler h)
  55. {
  56. return errorCount;
  57. }
  58. // <group
  59. // id = ID
  60. // ref = QName
  61. // minOccurs = ? : 1
  62. // maxOccurs = ? : 1>
  63. // Content: (annotation?)
  64. // </group>
  65. internal static XmlSchemaGroupRef Read(XmlSchemaReader reader, ValidationEventHandler h)
  66. {
  67. XmlSchemaGroupRef groupref = new XmlSchemaGroupRef();
  68. reader.MoveToElement();
  69. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  70. {
  71. error(h,"Should not happen :1: XmlSchemaGroup.Read, name="+reader.Name,null);
  72. reader.Skip();
  73. return null;
  74. }
  75. groupref.LineNumber = reader.LineNumber;
  76. groupref.LinePosition = reader.LinePosition;
  77. groupref.SourceUri = reader.BaseURI;
  78. while(reader.MoveToNextAttribute())
  79. {
  80. if(reader.Name == "id")
  81. {
  82. groupref.Id = reader.Value;
  83. }
  84. else if(reader.Name == "ref")
  85. {
  86. Exception innerex;
  87. groupref.refName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
  88. if(innerex != null)
  89. error(h, reader.Value + " is not a valid value for ref attribute",innerex);
  90. }
  91. else if(reader.Name == "maxOccurs")
  92. {
  93. try
  94. {
  95. groupref.MaxOccursString = reader.Value;
  96. }
  97. catch(Exception e)
  98. {
  99. error(h,reader.Value + " is an invalid value for maxOccurs",e);
  100. }
  101. }
  102. else if(reader.Name == "minOccurs")
  103. {
  104. try
  105. {
  106. groupref.MinOccursString = reader.Value;
  107. }
  108. catch(Exception e)
  109. {
  110. error(h,reader.Value + " is an invalid value for minOccurs", e);
  111. }
  112. }
  113. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  114. {
  115. error(h,reader.Name + " is not a valid attribute for group",null);
  116. }
  117. else
  118. {
  119. XmlSchemaUtil.ReadUnhandledAttribute(reader,groupref);
  120. }
  121. }
  122. reader.MoveToElement();
  123. if(reader.IsEmptyElement)
  124. return groupref;
  125. // Content: (annotation?)
  126. int level = 1;
  127. while(reader.ReadNextElement())
  128. {
  129. if(reader.NodeType == XmlNodeType.EndElement)
  130. {
  131. if(reader.LocalName != xmlname)
  132. error(h,"Should not happen :2: XmlSchemaGroupRef.Read, name="+reader.Name,null);
  133. break;
  134. }
  135. if(level <= 1 && reader.LocalName == "annotation")
  136. {
  137. level = 2; //Only one annotation
  138. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  139. if(annotation != null)
  140. groupref.Annotation = annotation;
  141. continue;
  142. }
  143. reader.RaiseInvalidElementError();
  144. }
  145. return groupref;
  146. }
  147. }
  148. }