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