2003-10-01 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaAttributeGroupRef.cs
1 //\r
2 // System.Xml.Schema.XmlSchemaAttributeGroupRef.cs\r
3 //\r
4 // Author:\r
5 //      Dwivedi, Ajay kumar  Adwiv@Yahoo.com\r
6 //      Atsushi Enomoto  ginga@kit.hi-ho.ne.jp\r
7 //\r
8 using System;\r
9 using System.Xml;\r
10 using System.Xml.Serialization;\r
11 \r
12 namespace System.Xml.Schema\r
13 {\r
14         /// <summary>\r
15         /// Summary description for XmlSchemaAttributeGroupRef.\r
16         /// </summary>\r
17         public class XmlSchemaAttributeGroupRef : XmlSchemaAnnotated\r
18         {\r
19                 private XmlQualifiedName refName;\r
20                 private static string xmlname = "attributeGroup";\r
21 \r
22                 public XmlSchemaAttributeGroupRef()\r
23                 {\r
24                         refName = XmlQualifiedName.Empty;\r
25                 }\r
26                 \r
27                 [System.Xml.Serialization.XmlAttribute("ref")]\r
28                 public XmlQualifiedName RefName \r
29                 {\r
30                         get{ return  refName; }\r
31                         set{ refName = value; }\r
32                 }\r
33 \r
34                 /// <remarks>\r
35                 /// 1. ref must be present\r
36                 /// 2. The element must be empty. ?? FIXME: Is this correct or annotation is permitted?\r
37                 /// </remarks>\r
38                 [MonoTODO]\r
39                 internal override int Compile(ValidationEventHandler h, XmlSchema schema)\r
40                 {\r
41                         // If this is already compiled this time, simply skip.\r
42                         if (this.IsComplied (schema.CompilationId))\r
43                                 return 0;\r
44 \r
45                         errorCount = 0;\r
46                         if(RefName == null || RefName.IsEmpty)\r
47                                 error(h, "ref must be present");\r
48                         else if(!XmlSchemaUtil.CheckQName(RefName))\r
49                                 error(h, "ref must be a valid qname");\r
50 \r
51                         XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);\r
52 \r
53 //                      if(this.Annotation != null)\r
54 //                              error(h, "attributegroup with a ref can't have any content");\r
55                         \r
56                         this.CompilationId = schema.CompilationId;\r
57                         return errorCount;\r
58                 }\r
59                 \r
60                 [MonoTODO]\r
61                 internal override int Validate(ValidationEventHandler h, XmlSchema schema)\r
62                 {\r
63                         return errorCount;\r
64                 }\r
65 \r
66                 //<attributeGroup\r
67                 //  id = ID\r
68                 //  ref = QName\r
69                 //  {any attributes with non-schema namespace . . .}>\r
70                 //  Content: (annotation?)\r
71                 //</attributeGroup>\r
72                 internal static XmlSchemaAttributeGroupRef Read(XmlSchemaReader reader, ValidationEventHandler h)\r
73                 {\r
74                         XmlSchemaAttributeGroupRef attrgrp = new XmlSchemaAttributeGroupRef();\r
75                         reader.MoveToElement();\r
76 \r
77                         if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)\r
78                         {\r
79                                 error(h,"Should not happen :1: XmlSchemaAttributeGroupRef.Read, name="+reader.Name,null);\r
80                                 reader.SkipToEnd();\r
81                                 return null;\r
82                         }\r
83 \r
84                         attrgrp.LineNumber = reader.LineNumber;\r
85                         attrgrp.LinePosition = reader.LinePosition;\r
86                         attrgrp.SourceUri = reader.BaseURI;\r
87 \r
88                         while(reader.MoveToNextAttribute())\r
89                         {\r
90                                 if(reader.Name == "id")\r
91                                 {\r
92                                         attrgrp.Id = reader.Value;\r
93                                 }\r
94                                 else if(reader.Name == "ref")\r
95                                 {\r
96                                         Exception innerex;\r
97                                         attrgrp.refName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);\r
98                                         if(innerex != null)\r
99                                                 error(h, reader.Value + " is not a valid value for ref attribute",innerex);\r
100                                 }\r
101                                 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)\r
102                                 {\r
103                                         error(h,reader.Name + " is not a valid attribute for attributeGroup in this context",null);\r
104                                 }\r
105                                 else\r
106                                 {\r
107                                         XmlSchemaUtil.ReadUnhandledAttribute(reader,attrgrp);\r
108                                 }\r
109                         }\r
110                         \r
111                         reader.MoveToElement();\r
112                         if(reader.IsEmptyElement)\r
113                                 return attrgrp;\r
114                         int level = 1;\r
115 \r
116                         while(reader.ReadNextElement())\r
117                         {\r
118                                 if(reader.NodeType == XmlNodeType.EndElement)\r
119                                 {\r
120                                         if(reader.LocalName != xmlname)\r
121                                                 error(h,"Should not happen :2: XmlSchemaAttributeGroupRef.Read, name="+reader.Name,null);\r
122                                         break;\r
123                                 }\r
124                                 if(level <= 1 && reader.LocalName == "annotation")\r
125                                 {\r
126                                         level = 2; //Only one annotation\r
127                                         XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);\r
128                                         if(annotation != null)\r
129                                                 attrgrp.Annotation = annotation;\r
130                                         continue;\r
131                                 }\r
132                                 reader.RaiseInvalidElementError();\r
133                         }\r
134                         return attrgrp;\r
135                 }\r
136         }\r
137 }\r