2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaMaxInclusiveFacet.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 XmlSchemaMaxInclusiveFacet.\r
31         /// </summary>\r
32         public class XmlSchemaMaxInclusiveFacet : XmlSchemaFacet\r
33         {\r
34                 const string xmlname = "maxInclusive";\r
35 \r
36                 public XmlSchemaMaxInclusiveFacet()\r
37                 {\r
38                 }\r
39 \r
40                 internal override Facet ThisFacet {\r
41                         get { return Facet.maxInclusive;}\r
42                 }\r
43 \r
44                 //<maxInclusive\r
45                 //  fixed = boolean : false\r
46                 //  id = ID\r
47                 //  value = anySimpleType\r
48                 //  {any attributes with non-schema namespace . . .}>\r
49                 //  Content: (annotation?)\r
50                 //</maxInclusive>\r
51                 internal static XmlSchemaMaxInclusiveFacet Read(XmlSchemaReader reader, ValidationEventHandler h)\r
52                 {\r
53                         XmlSchemaMaxInclusiveFacet maxi = new XmlSchemaMaxInclusiveFacet();\r
54                         reader.MoveToElement();\r
55 \r
56                         if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)\r
57                         {\r
58                                 error(h,"Should not happen :1: XmlSchemaMaxInclusiveFacet.Read, name="+reader.Name,null);\r
59                                 reader.Skip();\r
60                                 return null;\r
61                         }\r
62 \r
63                         maxi.LineNumber = reader.LineNumber;\r
64                         maxi.LinePosition = reader.LinePosition;\r
65                         maxi.SourceUri = reader.BaseURI;\r
66 \r
67                         while(reader.MoveToNextAttribute())\r
68                         {\r
69                                 if(reader.Name == "id")\r
70                                 {\r
71                                         maxi.Id = reader.Value;\r
72                                 }\r
73                                 else if(reader.Name == "fixed")\r
74                                 {\r
75                                         Exception innerex;\r
76                                         maxi.IsFixed = XmlSchemaUtil.ReadBoolAttribute(reader,out innerex);\r
77                                         if(innerex != null)\r
78                                                 error(h, reader.Value + " is not a valid value for fixed attribute",innerex);\r
79                                 }\r
80                                 else if(reader.Name == "value")\r
81                                 {\r
82                                         maxi.Value = reader.Value;\r
83                                 }\r
84                                 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)\r
85                                 {\r
86                                         error(h,reader.Name + " is not a valid attribute for "+xmlname,null);\r
87                                 }\r
88                                 else\r
89                                 {\r
90                                         XmlSchemaUtil.ReadUnhandledAttribute(reader,maxi);\r
91                                 }\r
92                         }\r
93                         \r
94                         reader.MoveToElement();\r
95                         if(reader.IsEmptyElement)\r
96                                 return maxi;\r
97 \r
98                         //  Content: (annotation?)\r
99                         int level = 1;\r
100                         while(reader.ReadNextElement())\r
101                         {\r
102                                 if(reader.NodeType == XmlNodeType.EndElement)\r
103                                 {\r
104                                         if(reader.LocalName != xmlname)\r
105                                                 error(h,"Should not happen :2: XmlSchemaMaxInclusiveFacet.Read, name="+reader.Name,null);\r
106                                         break;\r
107                                 }\r
108                                 if(level <= 1 && reader.LocalName == "annotation")\r
109                                 {\r
110                                         level = 2;      //Only one annotation\r
111                                         XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);\r
112                                         if(annotation != null)\r
113                                                 maxi.Annotation = annotation;\r
114                                         continue;\r
115                                 }\r
116                                 reader.RaiseInvalidElementError();\r
117                         }                       \r
118                         return maxi;\r
119                 }\r
120         }\r
121 }\r