XmlSchemaAttributeGroupRef.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // System.Xml.Schema.XmlSchemaAttributeGroupRef.cs
  3. //
  4. // Author:
  5. // Dwivedi, Ajay kumar [email protected]
  6. // Atsushi Enomoto [email protected]
  7. //
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Xml;
  30. using System.Xml.Serialization;
  31. namespace System.Xml.Schema
  32. {
  33. /// <summary>
  34. /// Summary description for XmlSchemaAttributeGroupRef.
  35. /// </summary>
  36. public class XmlSchemaAttributeGroupRef : XmlSchemaAnnotated
  37. {
  38. private XmlQualifiedName refName;
  39. const string xmlname = "attributeGroup";
  40. public XmlSchemaAttributeGroupRef()
  41. {
  42. refName = XmlQualifiedName.Empty;
  43. }
  44. [System.Xml.Serialization.XmlAttribute("ref")]
  45. public XmlQualifiedName RefName
  46. {
  47. get{ return refName; }
  48. set{ refName = value; }
  49. }
  50. /// <remarks>
  51. /// 1. ref must be present
  52. /// </remarks>
  53. internal override int Compile(ValidationEventHandler h, XmlSchema schema)
  54. {
  55. // If this is already compiled this time, simply skip.
  56. if (this.IsComplied (schema.CompilationId))
  57. return 0;
  58. errorCount = 0;
  59. if(RefName == null || RefName.IsEmpty)
  60. error(h, "ref must be present");
  61. else if(!XmlSchemaUtil.CheckQName(RefName))
  62. error(h, "ref must be a valid qname");
  63. XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
  64. this.CompilationId = schema.CompilationId;
  65. return errorCount;
  66. }
  67. internal override int Validate(ValidationEventHandler h, XmlSchema schema)
  68. {
  69. return errorCount;
  70. }
  71. //<attributeGroup
  72. // id = ID
  73. // ref = QName
  74. // {any attributes with non-schema namespace . . .}>
  75. // Content: (annotation?)
  76. //</attributeGroup>
  77. internal static XmlSchemaAttributeGroupRef Read(XmlSchemaReader reader, ValidationEventHandler h)
  78. {
  79. XmlSchemaAttributeGroupRef attrgrp = new XmlSchemaAttributeGroupRef();
  80. reader.MoveToElement();
  81. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  82. {
  83. error(h,"Should not happen :1: XmlSchemaAttributeGroupRef.Read, name="+reader.Name,null);
  84. reader.SkipToEnd();
  85. return null;
  86. }
  87. attrgrp.LineNumber = reader.LineNumber;
  88. attrgrp.LinePosition = reader.LinePosition;
  89. attrgrp.SourceUri = reader.BaseURI;
  90. while(reader.MoveToNextAttribute())
  91. {
  92. if(reader.Name == "id")
  93. {
  94. attrgrp.Id = reader.Value;
  95. }
  96. else if(reader.Name == "ref")
  97. {
  98. Exception innerex;
  99. attrgrp.refName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
  100. if(innerex != null)
  101. error(h, reader.Value + " is not a valid value for ref attribute",innerex);
  102. }
  103. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  104. {
  105. error(h,reader.Name + " is not a valid attribute for attributeGroup in this context",null);
  106. }
  107. else
  108. {
  109. XmlSchemaUtil.ReadUnhandledAttribute(reader,attrgrp);
  110. }
  111. }
  112. reader.MoveToElement();
  113. if(reader.IsEmptyElement)
  114. return attrgrp;
  115. int level = 1;
  116. while(reader.ReadNextElement())
  117. {
  118. if(reader.NodeType == XmlNodeType.EndElement)
  119. {
  120. if(reader.LocalName != xmlname)
  121. error(h,"Should not happen :2: XmlSchemaAttributeGroupRef.Read, name="+reader.Name,null);
  122. break;
  123. }
  124. if(level <= 1 && reader.LocalName == "annotation")
  125. {
  126. level = 2; //Only one annotation
  127. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  128. if(annotation != null)
  129. attrgrp.Annotation = annotation;
  130. continue;
  131. }
  132. reader.RaiseInvalidElementError();
  133. }
  134. return attrgrp;
  135. }
  136. }
  137. }