remove svn:executable from .cs files
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaEnumerationFacet.cs
1 // Author: Dwivedi, Ajay kumar\r
2 //            Adwiv@Yahoo.com\r
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;\r
25 using System.Xml;\r
26 \r
27 namespace System.Xml.Schema\r
28 {\r
29         /// <summary>\r
30         /// Summary description for XmlSchemaEnumerationFacet.\r
31         /// </summary>\r
32         public class XmlSchemaEnumerationFacet : XmlSchemaFacet\r
33         {\r
34                 const string xmlname = "enumeration";\r
35                 public XmlSchemaEnumerationFacet()\r
36                 {\r
37                 }\r
38 \r
39                 internal override Facet ThisFacet { \r
40                         get { return Facet.enumeration;}\r
41                 }\r
42         \r
43 \r
44                 //<enumeration\r
45                 //  id = ID\r
46                 //  value = anySimpleType\r
47                 //  {any attributes with non-schema namespace . . .}>\r
48                 //  Content: (annotation?)\r
49                 //</enumeration>\r
50                 internal static XmlSchemaEnumerationFacet Read(XmlSchemaReader reader, ValidationEventHandler h)\r
51                 {\r
52                         XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();\r
53                         reader.MoveToElement();\r
54 \r
55                         if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)\r
56                         {\r
57                                 error(h,"Should not happen :1: XmlSchemaEnumerationFacet.Read, name="+reader.Name,null);\r
58                                 reader.Skip();\r
59                                 return null;\r
60                         }\r
61 \r
62                         enumeration.LineNumber = reader.LineNumber;\r
63                         enumeration.LinePosition = reader.LinePosition;\r
64                         enumeration.SourceUri = reader.BaseURI;\r
65 \r
66                         while(reader.MoveToNextAttribute())\r
67                         {\r
68                                 if(reader.Name == "id")\r
69                                 {\r
70                                         enumeration.Id = reader.Value;\r
71                                 }\r
72                                 else if(reader.Name == "value")\r
73                                 {\r
74                                         enumeration.Value = reader.Value;\r
75                                 }\r
76                                 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)\r
77                                 {\r
78                                         error(h,reader.Name + " is not a valid attribute for "+xmlname,null);\r
79                                 }\r
80                                 else\r
81                                 {\r
82                                         XmlSchemaUtil.ReadUnhandledAttribute(reader,enumeration);\r
83                                 }\r
84                         }\r
85                         \r
86                         reader.MoveToElement();\r
87                         if(reader.IsEmptyElement)\r
88                                 return enumeration;\r
89 \r
90                         //  Content: (annotation?)\r
91                         int level = 1;\r
92                         while(reader.ReadNextElement())\r
93                         {\r
94                                 if(reader.NodeType == XmlNodeType.EndElement)\r
95                                 {\r
96                                         if(reader.LocalName != xmlname)\r
97                                                 error(h,"Should not happen :2: XmlSchemaEnumerationFacet.Read, name="+reader.Name,null);\r
98                                         break;\r
99                                 }\r
100                                 if(level <= 1 && reader.LocalName == "annotation")\r
101                                 {\r
102                                         level = 2;      //Only one annotation\r
103                                         XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);\r
104                                         if(annotation != null)\r
105                                                 enumeration.Annotation = annotation;\r
106                                         continue;\r
107                                 }\r
108                                 reader.RaiseInvalidElementError();\r
109                         }                       \r
110                         return enumeration;\r
111                 }\r
112         }\r
113 }\r