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;
29 namespace System.Xml.Schema
32 /// Summary description for XmlSchemaSimpleTypeList.
34 public class XmlSchemaSimpleTypeList : XmlSchemaSimpleTypeContent
36 private XmlSchemaSimpleType itemType;
37 private XmlQualifiedName itemTypeName;
38 const string xmlname = "list";
39 private object validatedListItemType;
41 private XmlSchemaSimpleType validatedListItemSchemaType;
44 public XmlSchemaSimpleTypeList()
46 this.ItemTypeName = XmlQualifiedName.Empty;
49 [System.Xml.Serialization.XmlAttribute("itemType")]
50 public XmlQualifiedName ItemTypeName
52 get{ return itemTypeName; }
59 [XmlElement("simpleType", Type=typeof (XmlSchemaSimpleType))]
60 public XmlSchemaSimpleType ItemType
62 get{ return itemType; }
70 // LAMESPEC: this name is really ambiguous. Actually it just
71 // holds compiled itemType, not baseType of the itemType.
73 public XmlSchemaSimpleType BaseItemType {
74 get { return validatedListItemSchemaType; }
75 // LAMESPEC: Since it is "post compilation information"
76 // this setter should not exist. Here I just ignore
77 // to not break the whole API. If this setter means
78 // something, then it means that MS implementation is
84 internal object ValidatedListItemType
86 get { return validatedListItemType; }
89 internal override void SetParent (XmlSchemaObject parent)
91 base.SetParent (parent);
93 ItemType.SetParent (this);
97 /// 1. One of itemType or a <simpleType> must be present, but not both.
98 /// 2. id must be of type ID
100 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
102 // If this is already compiled this time, simply skip.
103 if (CompilationId == schema.CompilationId)
108 if(ItemType != null && !ItemTypeName.IsEmpty)
109 error(h, "both itemType and simpletype can't be present");
110 if(ItemType == null && ItemTypeName.IsEmpty)
111 error(h, "one of itemType or simpletype must be present");
114 errorCount += ItemType.Compile(h,schema);
116 if(!XmlSchemaUtil.CheckQName(ItemTypeName))
117 error(h,"BaseTypeName must be a XmlQualifiedName");
119 XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
121 this.CompilationId = schema.CompilationId;
125 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
127 if (IsValidated (schema.ValidationId))
131 XmlSchemaSimpleType type = itemType;
133 type = schema.FindSchemaType (itemTypeName) as XmlSchemaSimpleType;
135 errorCount += type.Validate (h, schema);
136 validatedListItemType = type;
137 } else if (itemTypeName == XmlSchemaComplexType.AnyTypeName) {
138 validatedListItemType = XmlSchemaSimpleType.AnySimpleType;
139 } else if (XmlSchemaUtil.IsBuiltInDatatypeName (itemTypeName)) {
140 validatedListItemType = XmlSchemaDatatype.FromName (itemTypeName);
141 if (validatedListItemType == null)
142 error (h, "Invalid schema type name was specified: " + itemTypeName);
144 // otherwise, it might be missing sub components.
145 else if (!schema.IsNamespaceAbsent (itemTypeName.Namespace))
146 error (h, "Referenced base list item schema type " + itemTypeName + " was not found.");
149 XmlSchemaSimpleType st = validatedListItemType as XmlSchemaSimpleType;
150 if (st == null && validatedListItemType != null)
151 st = XmlSchemaType.GetBuiltInSimpleType (((XmlSchemaDatatype) validatedListItemType).TypeCode);
152 validatedListItemSchemaType = st;
155 ValidationId = schema.ValidationId;
162 // {any attributes with non-schema namespace . . .}>
163 // Content: (annotation?, (simpleType?))
165 internal static XmlSchemaSimpleTypeList Read(XmlSchemaReader reader, ValidationEventHandler h)
167 XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
168 reader.MoveToElement();
170 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
172 error(h,"Should not happen :1: XmlSchemaSimpleTypeList.Read, name="+reader.Name,null);
177 list.LineNumber = reader.LineNumber;
178 list.LinePosition = reader.LinePosition;
179 list.SourceUri = reader.BaseURI;
181 while(reader.MoveToNextAttribute())
183 if(reader.Name == "id")
185 list.Id = reader.Value;
187 else if(reader.Name == "itemType")
190 list.ItemTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
192 error(h, reader.Value + " is not a valid value for itemType attribute",innerex);
194 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
196 error(h,reader.Name + " is not a valid attribute for list",null);
200 XmlSchemaUtil.ReadUnhandledAttribute(reader,list);
204 reader.MoveToElement();
205 if(reader.IsEmptyElement)
207 // Content: annotation?, simpleType?
209 while(reader.ReadNextElement())
211 if(reader.NodeType == XmlNodeType.EndElement)
213 if(reader.LocalName != xmlname)
214 error(h,"Should not happen :2: XmlSchemaSimpleTypeList.Read, name="+reader.Name,null);
217 if(level <= 1 && reader.LocalName == "annotation")
219 level = 2; //Only one annotation
220 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
221 if(annotation != null)
222 list.Annotation = annotation;
225 if(level <= 2 && reader.LocalName == "simpleType")
228 XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader,h);
230 list.itemType = stype;
233 reader.RaiseInvalidElementError();