2010-06-21 Atsushi Enomoto <atsushi@ximian.com>
[mcs.git] / class / System.XML / System.Xml.Schema / XmlSchemaRedefine.cs
blob85b5e5a0b30f944fcc99f74df3dedbce2d79cdeb
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.Xml;
26 using System.Xml.Serialization;
28 namespace System.Xml.Schema
30 /// <summary>
31 /// Summary description for XmlSchemaRedefine.
32 /// </summary>
33 public class XmlSchemaRedefine : XmlSchemaExternal
35 private XmlSchemaObjectTable attributeGroups;
36 private XmlSchemaObjectTable groups;
37 private XmlSchemaObjectCollection items;
38 private XmlSchemaObjectTable schemaTypes;
39 const string xmlname = "redefine";
41 public XmlSchemaRedefine()
43 attributeGroups = new XmlSchemaObjectTable();
44 groups = new XmlSchemaObjectTable();
45 items = new XmlSchemaObjectCollection(this);
46 schemaTypes = new XmlSchemaObjectTable();
49 [XmlElement("annotation",typeof(XmlSchemaAnnotation))]
50 [XmlElement("simpleType",typeof(XmlSchemaSimpleType))]
51 [XmlElement("complexType",typeof(XmlSchemaComplexType))]
52 [XmlElement("group",typeof(XmlSchemaGroup))]
53 //NOTE: AttributeGroup and not AttributeGroupRef
54 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroup))]
55 public XmlSchemaObjectCollection Items
57 get{ return items; }
60 [XmlIgnore]
61 public XmlSchemaObjectTable AttributeGroups
63 get{ return attributeGroups; }
66 [XmlIgnore]
67 public XmlSchemaObjectTable SchemaTypes
69 get{ return schemaTypes; }
72 [XmlIgnore]
73 public XmlSchemaObjectTable Groups
75 get{ return groups; }
78 internal override void SetParent (XmlSchemaObject parent)
80 base.SetParent (parent);
81 foreach (XmlSchemaObject i in Items) {
82 i.SetParent (this);
83 i.isRedefinedComponent = true;
84 i.isRedefineChild = true;
88 //<redefine
89 // id = ID
90 // schemaLocation = anyURI
91 // {any attributes with non-schema namespace . . .}>
92 // Content: (annotation | (simpleType | complexType | group | attributeGroup))*
93 //</redefine>
94 internal static XmlSchemaRedefine Read(XmlSchemaReader reader, ValidationEventHandler h)
96 XmlSchemaRedefine redefine = new XmlSchemaRedefine();
97 reader.MoveToElement();
99 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
101 error(h,"Should not happen :1: XmlSchemaRedefine.Read, name="+reader.Name,null);
102 reader.Skip();
103 return null;
106 redefine.LineNumber = reader.LineNumber;
107 redefine.LinePosition = reader.LinePosition;
108 redefine.SourceUri = reader.BaseURI;
110 while(reader.MoveToNextAttribute())
112 if(reader.Name == "id")
114 redefine.Id = reader.Value;
116 else if(reader.Name == "schemaLocation")
118 redefine.SchemaLocation = reader.Value;
120 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
122 error(h,reader.Name + " is not a valid attribute for redefine",null);
124 else
126 XmlSchemaUtil.ReadUnhandledAttribute(reader,redefine);
130 reader.MoveToElement();
131 if(reader.IsEmptyElement)
132 return redefine;
134 //(annotation | (simpleType | complexType | group | attributeGroup))*
135 while(reader.ReadNextElement())
137 if(reader.NodeType == XmlNodeType.EndElement)
139 if(reader.LocalName != xmlname)
140 error(h,"Should not happen :2: XmlSchemaRedefine.Read, name="+reader.Name,null);
141 break;
143 if(reader.LocalName == "annotation")
145 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
146 if(annotation != null)
147 redefine.items.Add(annotation);
148 continue;
150 if(reader.LocalName == "simpleType")
152 XmlSchemaSimpleType simpleType = XmlSchemaSimpleType.Read(reader,h);
153 if(simpleType != null)
154 redefine.items.Add(simpleType);
155 continue;
157 if(reader.LocalName == "complexType")
159 XmlSchemaComplexType complexType = XmlSchemaComplexType.Read(reader,h);
160 if(complexType != null)
161 redefine.items.Add(complexType);
162 continue;
164 if(reader.LocalName == "group")
166 XmlSchemaGroup group = XmlSchemaGroup.Read(reader,h);
167 if(group != null)
168 redefine.items.Add(group);
169 continue;
171 if(reader.LocalName == "attributeGroup")
173 XmlSchemaAttributeGroup attributeGroup = XmlSchemaAttributeGroup.Read(reader,h);
174 if(attributeGroup != null)
175 redefine.items.Add(attributeGroup);
176 continue;
178 reader.RaiseInvalidElementError();
180 return redefine;