2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.XML / System.Xml.Schema / XmlSchemaAnnotation.cs
blob40fc731987bbfe9480dcc5982e59648563033e27
1 // Author: Dwivedi, Ajay kumar
2 // Adwiv@Yahoo.com
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.
24 using System;
25 using System.Collections;
26 using System.Xml;
27 using System.Xml.Serialization;
29 namespace System.Xml.Schema
31 /// <summary>
32 /// Summary description for XmlSchemaAnnotation.
33 /// </summary>
34 public class XmlSchemaAnnotation : XmlSchemaObject
36 private string id;
37 private XmlSchemaObjectCollection items;
38 private XmlAttribute[] unhandledAttributes;
39 const string xmlname = "annotation";
41 public XmlSchemaAnnotation()
43 items = new XmlSchemaObjectCollection();
46 [System.Xml.Serialization.XmlAttribute("id", DataType="ID")]
47 public string Id
49 get{ return id; }
50 set{ id = value; }
53 [XmlElement("appinfo",typeof(XmlSchemaAppInfo))]
54 [XmlElement("documentation",typeof(XmlSchemaDocumentation))]
55 public XmlSchemaObjectCollection Items
57 get{ return items; }
60 [XmlAnyAttribute]
61 public XmlAttribute[] UnhandledAttributes
63 get
65 if(unhandledAttributeList != null)
67 unhandledAttributes = (XmlAttribute[]) unhandledAttributeList.ToArray(typeof(XmlAttribute));
68 unhandledAttributeList = null;
70 return unhandledAttributes;
72 set
74 unhandledAttributes = value;
75 unhandledAttributeList = null;
79 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
81 // If this is already compiled this time, simply skip.
82 if (CompilationId == schema.CompilationId)
83 return 0;
85 this.CompilationId = schema.CompilationId;
86 return 0;
89 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
91 return 0;
94 //<annotation
95 // id = ID
96 // {any attributes with non-schema namespace . . .}>
97 // Content: (appinfo | documentation)*
98 //</annotation>
99 internal static XmlSchemaAnnotation Read(XmlSchemaReader reader, ValidationEventHandler h)
101 XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
102 reader.MoveToElement();
104 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
106 error(h,"Should not happen :1: XmlSchemaAnnotation.Read, name="+reader.Name,null);
107 reader.SkipToEnd();
108 return null;
111 annotation.LineNumber = reader.LineNumber;
112 annotation.LinePosition = reader.LinePosition;
113 annotation.SourceUri = reader.BaseURI;
115 //Read Attributes
116 while(reader.MoveToNextAttribute())
118 if(reader.Name == "id")
120 annotation.Id = reader.Value;
122 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
124 error(h,reader.Name + " is not a valid attribute for annotation",null);
126 else
128 XmlSchemaUtil.ReadUnhandledAttribute(reader,annotation);
132 reader.MoveToElement();
133 if(reader.IsEmptyElement)
134 return annotation;
136 //Content: (appinfo | documentation)*
137 bool skip = false;
138 string expectedEnd = null;
139 while(!reader.EOF)
141 if(skip)
142 skip=false;
143 else
144 reader.ReadNextElement();
146 if(reader.NodeType == XmlNodeType.EndElement)
148 bool end = true;
149 string expected = xmlname;
150 if(expectedEnd != null)
152 expected = expectedEnd;
153 expectedEnd = null;
154 end = false;
156 if(reader.LocalName != expected)
157 error(h,"Should not happen :2: XmlSchemaAnnotation.Read, name="+reader.Name+",expected="+expected,null);
158 if (end)
159 break;
160 else
161 continue;
163 if(reader.LocalName == "appinfo")
165 XmlSchemaAppInfo appinfo = XmlSchemaAppInfo.Read(reader,h,out skip);
166 if(appinfo != null)
167 annotation.items.Add(appinfo);
168 continue;
170 if(reader.LocalName == "documentation")
172 XmlSchemaDocumentation documentation = XmlSchemaDocumentation.Read(reader,h, out skip);
173 if(documentation != null)
174 annotation.items.Add(documentation);
175 continue;
177 reader.RaiseInvalidElementError();
179 return annotation;