XmlSchemaGroupRef.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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, XmlSchemaInfo info)
  36. {
  37. //FIXME: Should we reset the values
  38. if(MinOccurs > MaxOccurs)
  39. error(h,"minOccurs must be less than or equal to maxOccurs");
  40. XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h);
  41. if(refName == null || refName.IsEmpty)
  42. {
  43. error(h,"ref must be present");
  44. }
  45. else if(!XmlSchemaUtil.CheckQName(RefName))
  46. error(h, "RefName must be a valid XmlQualifiedName");
  47. return errorCount;
  48. }
  49. [MonoTODO]
  50. internal int Validate(ValidationEventHandler h)
  51. {
  52. return errorCount;
  53. }
  54. // <group
  55. // id = ID
  56. // ref = QName
  57. // minOccurs = ? : 1
  58. // maxOccurs = ? : 1>
  59. // Content: (annotation?)
  60. // </group>
  61. internal static XmlSchemaGroupRef Read(XmlSchemaReader reader, ValidationEventHandler h)
  62. {
  63. XmlSchemaGroupRef groupref = new XmlSchemaGroupRef();
  64. reader.MoveToElement();
  65. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  66. {
  67. error(h,"Should not happen :1: XmlSchemaGroup.Read, name="+reader.Name,null);
  68. reader.Skip();
  69. return null;
  70. }
  71. groupref.LineNumber = reader.LineNumber;
  72. groupref.LinePosition = reader.LinePosition;
  73. groupref.SourceUri = reader.BaseURI;
  74. while(reader.MoveToNextAttribute())
  75. {
  76. if(reader.Name == "id")
  77. {
  78. groupref.Id = reader.Value;
  79. }
  80. else if(reader.Name == "ref")
  81. {
  82. Exception innerex;
  83. groupref.refName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
  84. if(innerex != null)
  85. error(h, reader.Value + " is not a valid value for ref attribute",innerex);
  86. }
  87. else if(reader.Name == "maxOccurs")
  88. {
  89. try
  90. {
  91. groupref.MaxOccursString = reader.Value;
  92. }
  93. catch(Exception e)
  94. {
  95. error(h,reader.Value + " is an invalid value for maxOccurs",e);
  96. }
  97. }
  98. else if(reader.Name == "minOccurs")
  99. {
  100. try
  101. {
  102. groupref.MinOccursString = reader.Value;
  103. }
  104. catch(Exception e)
  105. {
  106. error(h,reader.Value + " is an invalid value for minOccurs", e);
  107. }
  108. }
  109. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  110. {
  111. error(h,reader.Name + " is not a valid attribute for group",null);
  112. }
  113. else
  114. {
  115. XmlSchemaUtil.ReadUnhandledAttribute(reader,groupref);
  116. }
  117. }
  118. reader.MoveToElement();
  119. if(reader.IsEmptyElement)
  120. return groupref;
  121. // Content: (annotation?)
  122. int level = 1;
  123. while(reader.ReadNextElement())
  124. {
  125. if(reader.NodeType == XmlNodeType.EndElement)
  126. {
  127. if(reader.LocalName != xmlname)
  128. error(h,"Should not happen :2: XmlSchemaGroupRef.Read, name="+reader.Name,null);
  129. break;
  130. }
  131. if(level <= 1 && reader.LocalName == "annotation")
  132. {
  133. level = 2; //Only one annotation
  134. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  135. if(annotation != null)
  136. groupref.Annotation = annotation;
  137. continue;
  138. }
  139. reader.RaiseInvalidElementError();
  140. }
  141. return groupref;
  142. }
  143. }
  144. }