1 // Author: Dwivedi, Ajay kumar
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:
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
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.
26 using System
.Xml
.Serialization
;
28 namespace System
.Xml
.Schema
31 /// Summary description for XmlSchemaRedefine.
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
61 public XmlSchemaObjectTable AttributeGroups
63 get{ return attributeGroups; }
67 public XmlSchemaObjectTable SchemaTypes
69 get{ return schemaTypes; }
73 public XmlSchemaObjectTable Groups
78 internal override void SetParent (XmlSchemaObject parent
)
80 base.SetParent (parent
);
81 foreach (XmlSchemaObject i
in Items
) {
83 i
.isRedefinedComponent
= true;
84 i
.isRedefineChild
= true;
90 // schemaLocation = anyURI
91 // {any attributes with non-schema namespace . . .}>
92 // Content: (annotation | (simpleType | complexType | group | attributeGroup))*
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);
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);
126 XmlSchemaUtil
.ReadUnhandledAttribute(reader
,redefine
);
130 reader
.MoveToElement();
131 if(reader
.IsEmptyElement
)
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);
143 if(reader
.LocalName
== "annotation")
145 XmlSchemaAnnotation annotation
= XmlSchemaAnnotation
.Read(reader
,h
);
146 if(annotation
!= null)
147 redefine
.items
.Add(annotation
);
150 if(reader
.LocalName
== "simpleType")
152 XmlSchemaSimpleType simpleType
= XmlSchemaSimpleType
.Read(reader
,h
);
153 if(simpleType
!= null)
154 redefine
.items
.Add(simpleType
);
157 if(reader
.LocalName
== "complexType")
159 XmlSchemaComplexType complexType
= XmlSchemaComplexType
.Read(reader
,h
);
160 if(complexType
!= null)
161 redefine
.items
.Add(complexType
);
164 if(reader
.LocalName
== "group")
166 XmlSchemaGroup
group = XmlSchemaGroup
.Read(reader
,h
);
168 redefine
.items
.Add(group);
171 if(reader
.LocalName
== "attributeGroup")
173 XmlSchemaAttributeGroup attributeGroup
= XmlSchemaAttributeGroup
.Read(reader
,h
);
174 if(attributeGroup
!= null)
175 redefine
.items
.Add(attributeGroup
);
178 reader
.RaiseInvalidElementError();