New test.
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaEnumerationFacet.cs
1 // Author: Dwivedi, Ajay kumar
2 //            Adwiv@Yahoo.com
3
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
12 // 
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
15 // 
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 using System;
25 using System.Xml;
26
27 namespace System.Xml.Schema
28 {
29         /// <summary>
30         /// Summary description for XmlSchemaEnumerationFacet.
31         /// </summary>
32         public class XmlSchemaEnumerationFacet : XmlSchemaFacet
33         {
34                 const string xmlname = "enumeration";
35                 public XmlSchemaEnumerationFacet()
36                 {
37                 }
38
39                 internal override Facet ThisFacet { 
40                         get { return Facet.enumeration;}
41                 }
42         
43
44                 //<enumeration
45                 //  id = ID
46                 //  value = anySimpleType
47                 //  {any attributes with non-schema namespace . . .}>
48                 //  Content: (annotation?)
49                 //</enumeration>
50                 internal static XmlSchemaEnumerationFacet Read(XmlSchemaReader reader, ValidationEventHandler h)
51                 {
52                         XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();
53                         reader.MoveToElement();
54
55                         if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
56                         {
57                                 error(h,"Should not happen :1: XmlSchemaEnumerationFacet.Read, name="+reader.Name,null);
58                                 reader.Skip();
59                                 return null;
60                         }
61
62                         enumeration.LineNumber = reader.LineNumber;
63                         enumeration.LinePosition = reader.LinePosition;
64                         enumeration.SourceUri = reader.BaseURI;
65
66                         while(reader.MoveToNextAttribute())
67                         {
68                                 if(reader.Name == "id")
69                                 {
70                                         enumeration.Id = reader.Value;
71                                 }
72                                 else if(reader.Name == "value")
73                                 {
74                                         enumeration.Value = reader.Value;
75                                 }
76                                 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
77                                 {
78                                         error(h,reader.Name + " is not a valid attribute for "+xmlname,null);
79                                 }
80                                 else
81                                 {
82                                         XmlSchemaUtil.ReadUnhandledAttribute(reader,enumeration);
83                                 }
84                         }
85                         
86                         reader.MoveToElement();
87                         if(reader.IsEmptyElement)
88                                 return enumeration;
89
90                         //  Content: (annotation?)
91                         int level = 1;
92                         while(reader.ReadNextElement())
93                         {
94                                 if(reader.NodeType == XmlNodeType.EndElement)
95                                 {
96                                         if(reader.LocalName != xmlname)
97                                                 error(h,"Should not happen :2: XmlSchemaEnumerationFacet.Read, name="+reader.Name,null);
98                                         break;
99                                 }
100                                 if(level <= 1 && reader.LocalName == "annotation")
101                                 {
102                                         level = 2;      //Only one annotation
103                                         XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
104                                         if(annotation != null)
105                                                 enumeration.Annotation = annotation;
106                                         continue;
107                                 }
108                                 reader.RaiseInvalidElementError();
109                         }                       
110                         return enumeration;
111                 }
112         }
113 }