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