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