1 // Author: Dwivedi, Ajay kumar
\r
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;
\r
29 namespace System.Xml.Schema
\r
32 /// Summary description for XmlSchemaSimpleTypeList.
\r
34 public class XmlSchemaSimpleTypeList : XmlSchemaSimpleTypeContent
\r
36 private XmlSchemaSimpleType itemType;
\r
37 private XmlQualifiedName itemTypeName;
\r
38 const string xmlname = "list";
\r
39 private object validatedListItemType;
\r
41 private XmlSchemaSimpleType validatedListItemSchemaType;
\r
44 public XmlSchemaSimpleTypeList()
\r
46 this.ItemTypeName = XmlQualifiedName.Empty;
\r
49 [System.Xml.Serialization.XmlAttribute("itemType")]
\r
50 public XmlQualifiedName ItemTypeName
\r
52 get{ return itemTypeName; }
\r
55 itemTypeName = value;
\r
59 [XmlElement("simpleType", Type=typeof (XmlSchemaSimpleType))]
\r
60 public XmlSchemaSimpleType ItemType
\r
62 get{ return itemType; }
\r
70 // LAMESPEC: this name is really ambiguous. Actually it just
\r
71 // holds compiled itemType, not baseType of the itemType.
\r
73 public XmlSchemaSimpleType BaseItemType {
\r
74 get { return validatedListItemSchemaType; }
\r
75 // LAMESPEC: Since it is "post compilation information"
\r
76 // this setter should not exist. Here I just ignore
\r
77 // to not break the whole API. If this setter means
\r
78 // something, then it means that MS implementation is
\r
84 internal object ValidatedListItemType
\r
86 get { return validatedListItemType; }
\r
90 /// 1. One of itemType or a <simpleType> must be present, but not both.
\r
91 /// 2. id must be of type ID
\r
93 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
95 // If this is already compiled this time, simply skip.
\r
96 if (CompilationId == schema.CompilationId)
\r
100 if (ItemType != null)
\r
101 ItemType.Parent = this;
\r
106 if(ItemType != null && !ItemTypeName.IsEmpty)
\r
107 error(h, "both itemType and simpletype can't be present");
\r
108 if(ItemType == null && ItemTypeName.IsEmpty)
\r
109 error(h, "one of itemType or simpletype must be present");
\r
110 if(ItemType != null)
\r
112 errorCount += ItemType.Compile(h,schema);
\r
114 if(!XmlSchemaUtil.CheckQName(ItemTypeName))
\r
115 error(h,"BaseTypeName must be a XmlQualifiedName");
\r
117 XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
\r
119 this.CompilationId = schema.CompilationId;
\r
123 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
125 if (IsValidated (schema.ValidationId))
\r
129 XmlSchemaSimpleType type = itemType;
\r
131 type = schema.SchemaTypes [itemTypeName] as XmlSchemaSimpleType;
\r
132 if (type != null) {
\r
133 errorCount += type.Validate (h, schema);
\r
134 validatedListItemType = type;
\r
135 } else if (itemTypeName == XmlSchemaComplexType.AnyTypeName) {
\r
136 validatedListItemType = XmlSchemaSimpleType.AnySimpleType;
137 } else if (XmlSchemaUtil.IsBuiltInDatatypeName (itemTypeName)) {
\r
138 validatedListItemType = XmlSchemaDatatype.FromName (itemTypeName);
\r
139 if (validatedListItemType == null)
\r
140 error (h, "Invalid schema type name was specified: " + itemTypeName);
\r
142 // otherwise, it might be missing sub components.
\r
143 else if (!schema.IsNamespaceAbsent (itemTypeName.Namespace))
\r
144 error (h, "Referenced base list item schema type " + itemTypeName + " was not found.");
\r
147 XmlSchemaSimpleType st = validatedListItemType as XmlSchemaSimpleType;
\r
148 if (st == null && validatedListItemType != null)
\r
149 st = XmlSchemaType.GetBuiltInSimpleType (((XmlSchemaDatatype) validatedListItemType).TypeCode);
\r
150 validatedListItemSchemaType = st;
\r
153 ValidationId = schema.ValidationId;
\r
159 // itemType = QName
\r
160 // {any attributes with non-schema namespace . . .}>
\r
161 // Content: (annotation?, (simpleType?))
\r
163 internal static XmlSchemaSimpleTypeList Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
165 XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
\r
166 reader.MoveToElement();
\r
168 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
170 error(h,"Should not happen :1: XmlSchemaSimpleTypeList.Read, name="+reader.Name,null);
\r
175 list.LineNumber = reader.LineNumber;
\r
176 list.LinePosition = reader.LinePosition;
\r
177 list.SourceUri = reader.BaseURI;
\r
179 while(reader.MoveToNextAttribute())
\r
181 if(reader.Name == "id")
\r
183 list.Id = reader.Value;
\r
185 else if(reader.Name == "itemType")
\r
188 list.ItemTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
189 if(innerex != null)
\r
190 error(h, reader.Value + " is not a valid value for itemType attribute",innerex);
\r
192 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
194 error(h,reader.Name + " is not a valid attribute for list",null);
\r
198 XmlSchemaUtil.ReadUnhandledAttribute(reader,list);
\r
202 reader.MoveToElement();
\r
203 if(reader.IsEmptyElement)
\r
205 // Content: annotation?, simpleType?
\r
207 while(reader.ReadNextElement())
\r
209 if(reader.NodeType == XmlNodeType.EndElement)
\r
211 if(reader.LocalName != xmlname)
\r
212 error(h,"Should not happen :2: XmlSchemaSimpleTypeList.Read, name="+reader.Name,null);
\r
215 if(level <= 1 && reader.LocalName == "annotation")
\r
217 level = 2; //Only one annotation
\r
218 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
219 if(annotation != null)
\r
220 list.Annotation = annotation;
\r
223 if(level <= 2 && reader.LocalName == "simpleType")
\r
226 XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader,h);
\r
228 list.itemType = stype;
\r
231 reader.RaiseInvalidElementError();
\r