5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
6 // Atsushi Enomoto atsushi@ximian.com
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.ComponentModel;
32 using Mono.Xml.Schema;
33 using System.Xml.Serialization;
34 #if NET_2_0_in_the_future
35 using MS.Internal.Xml;
38 namespace System.Xml.Schema
41 /// Summary description for XmlSchemaType.
43 public class XmlSchemaType : XmlSchemaAnnotated
45 private XmlSchemaDerivationMethod final;
50 internal XmlQualifiedName BaseSchemaTypeName;
51 internal XmlSchemaType BaseXmlSchemaTypeInternal;
52 internal XmlSchemaDatatype DatatypeInternal;
53 internal XmlSchemaDerivationMethod resolvedDerivedBy;
54 internal XmlSchemaDerivationMethod finalResolved;
55 internal XmlQualifiedName QNameInternal;
57 public XmlSchemaType ()
59 final = XmlSchemaDerivationMethod.None;
60 QNameInternal = XmlQualifiedName.Empty;
64 [System.Xml.Serialization.XmlAttribute("name")]
70 [DefaultValue(XmlSchemaDerivationMethod.None)]
71 [System.Xml.Serialization.XmlAttribute("final")]
72 public XmlSchemaDerivationMethod Final {
78 #region Post Compilation Schema Information
80 public XmlQualifiedName QualifiedName {
81 get{ return QNameInternal; }
85 public XmlSchemaDerivationMethod FinalResolved {
86 get{ return finalResolved; }
91 [Obsolete ("This property is going away. Use BaseXmlSchemaType instead")]
93 public object BaseSchemaType {
95 if (BaseXmlSchemaType != null)
96 return BaseXmlSchemaType;
97 else if (this == XmlSchemaComplexType.AnyType)
98 return null; // This property is designed so.
105 // FIXME:This property works as always returning a valid schema type.
107 // In .NET 2.0, all schema types used in schema documents must
108 // be XmlSchemaType, even if it is primitive type, in terms of
109 // non-obsolete System.Xml.Schema members.
111 // To modify this property, we have to make sure that it does
112 // not affect to any compilation/validation logic.
114 public XmlSchemaType BaseXmlSchemaType {
116 internal XmlSchemaType BaseXmlSchemaType {
118 get { return BaseXmlSchemaTypeInternal; }
122 public XmlSchemaDerivationMethod DerivedBy {
123 get{ return resolvedDerivedBy; }
127 public XmlSchemaDatatype Datatype {
128 get{ return DatatypeInternal; }
132 public virtual bool IsMixed {
133 get{ return isMixed; }
134 set{ isMixed = value; }
138 // LAMESPEC: for IDREFS it returns Idref. for ENTITIES
139 // it returns Entity. for NMTOKENS it returns NmToken.
141 public XmlTypeCode TypeCode {
143 if (this == XmlSchemaComplexType.AnyType)
144 return XmlTypeCode.Item;
145 if (DatatypeInternal == XmlSchemaSimpleType.AnySimpleType)
146 return XmlTypeCode.AnyAtomicType;
147 if (this == XmlSchemaSimpleType.XsIDRefs)
148 return XmlTypeCode.Idref;
149 if (this == XmlSchemaSimpleType.XsEntities)
150 return XmlTypeCode.Entity;
151 if (this == XmlSchemaSimpleType.XsNMTokens)
152 return XmlTypeCode.NmToken;
153 if (DatatypeInternal != null)
154 return DatatypeInternal.TypeCode;
155 return BaseXmlSchemaType.TypeCode;
162 internal static XmlSchemaType GetBuiltInType (XmlQualifiedName qualifiedName)
164 XmlSchemaType t = GetBuiltInSimpleType (qualifiedName);
166 t = GetBuiltInComplexType (qualifiedName);
170 internal static XmlSchemaType GetBuiltInType (XmlTypeCode typecode)
172 if (typecode == XmlTypeCode.Item)
173 return XmlSchemaComplexType.AnyType;
174 return GetBuiltInSimpleType (typecode);
179 public static XmlSchemaComplexType GetBuiltInComplexType (XmlQualifiedName qualifiedName)
181 internal static XmlSchemaComplexType GetBuiltInComplexType (XmlQualifiedName qualifiedName)
184 if (qualifiedName.Name == "anyType" && qualifiedName.Namespace == XmlSchema.Namespace)
185 return XmlSchemaComplexType.AnyType;
191 public static XmlSchemaComplexType GetBuiltInComplexType (XmlTypeCode typeCode)
194 case XmlTypeCode.Item:
195 return XmlSchemaComplexType.AnyType;
203 public static XmlSchemaSimpleType GetBuiltInSimpleType (XmlQualifiedName qualifiedName)
205 if (qualifiedName.Namespace == "http://www.w3.org/2003/11/xpath-datatypes") {
206 switch (qualifiedName.Name) {
207 case "untypedAtomic":
208 return XmlSchemaSimpleType.XdtUntypedAtomic;
209 case "anyAtomicType":
210 return XmlSchemaSimpleType.XdtAnyAtomicType;
211 case "yearMonthDuration":
212 return XmlSchemaSimpleType.XdtYearMonthDuration;
213 case "dayTimeDuration":
214 return XmlSchemaSimpleType.XdtDayTimeDuration;
218 else if (qualifiedName.Namespace != XmlSchema.Namespace)
220 switch (qualifiedName.Name) {
221 case "anySimpleType":
222 return XmlSchemaSimpleType.XsAnySimpleType;
224 return XmlSchemaSimpleType.XsString;
226 return XmlSchemaSimpleType.XsBoolean;
228 return XmlSchemaSimpleType.XsDecimal;
230 return XmlSchemaSimpleType.XsFloat;
232 return XmlSchemaSimpleType.XsDouble;
234 return XmlSchemaSimpleType.XsDuration;
236 return XmlSchemaSimpleType.XsDateTime;
238 return XmlSchemaSimpleType.XsTime;
240 return XmlSchemaSimpleType.XsDate;
242 return XmlSchemaSimpleType.XsGYearMonth;
244 return XmlSchemaSimpleType.XsGYear;
246 return XmlSchemaSimpleType.XsGMonthDay;
248 return XmlSchemaSimpleType.XsGDay;
250 return XmlSchemaSimpleType.XsGMonth;
252 return XmlSchemaSimpleType.XsHexBinary;
254 return XmlSchemaSimpleType.XsBase64Binary;
256 return XmlSchemaSimpleType.XsAnyUri;
258 return XmlSchemaSimpleType.XsQName;
260 return XmlSchemaSimpleType.XsNotation;
261 case "normalizedString":
262 return XmlSchemaSimpleType.XsNormalizedString;
264 return XmlSchemaSimpleType.XsToken;
266 return XmlSchemaSimpleType.XsLanguage;
268 return XmlSchemaSimpleType.XsNMToken;
270 return XmlSchemaSimpleType.XsNMTokens;
272 return XmlSchemaSimpleType.XsName;
274 return XmlSchemaSimpleType.XsNCName;
276 return XmlSchemaSimpleType.XsID;
278 return XmlSchemaSimpleType.XsIDRef;
280 return XmlSchemaSimpleType.XsIDRefs;
282 return XmlSchemaSimpleType.XsEntity;
284 return XmlSchemaSimpleType.XsEntities;
286 return XmlSchemaSimpleType.XsInteger;
287 case "nonPositiveInteger":
288 return XmlSchemaSimpleType.XsNonPositiveInteger;
289 case "negativeInteger":
290 return XmlSchemaSimpleType.XsNegativeInteger;
292 return XmlSchemaSimpleType.XsLong;
294 return XmlSchemaSimpleType.XsInt;
296 return XmlSchemaSimpleType.XsShort;
298 return XmlSchemaSimpleType.XsByte;
299 case "nonNegativeInteger":
300 return XmlSchemaSimpleType.XsNonNegativeInteger;
301 case "positiveInteger":
302 return XmlSchemaSimpleType.XsPositiveInteger;
304 return XmlSchemaSimpleType.XsUnsignedLong;
306 return XmlSchemaSimpleType.XsUnsignedInt;
307 case "unsignedShort":
308 return XmlSchemaSimpleType.XsUnsignedShort;
310 return XmlSchemaSimpleType.XsUnsignedByte;
315 internal static XmlSchemaSimpleType GetBuiltInSimpleType (XmlSchemaDatatype type)
317 if (type is XsdEntities)
318 return XmlSchemaSimpleType.XsEntities;
319 else if (type is XsdNMTokens)
320 return XmlSchemaSimpleType.XsNMTokens;
321 else if (type is XsdIDRefs)
322 return XmlSchemaSimpleType.XsIDRefs;
324 return GetBuiltInSimpleType (type.TypeCode);
328 // Don't use this method to cover all XML Schema datatypes.
329 public static XmlSchemaSimpleType GetBuiltInSimpleType (XmlTypeCode typeCode)
332 case XmlTypeCode.None:
333 case XmlTypeCode.Item:
334 case XmlTypeCode.Node:
335 case XmlTypeCode.Document: // node
336 case XmlTypeCode.Element: // node
337 case XmlTypeCode.Attribute: // node
338 case XmlTypeCode.Namespace: // node
339 case XmlTypeCode.ProcessingInstruction: // node
340 case XmlTypeCode.Comment: // node
341 case XmlTypeCode.Text: // node
343 case XmlTypeCode.AnyAtomicType:
344 return XmlSchemaSimpleType.XdtAnyAtomicType;
345 case XmlTypeCode.UntypedAtomic:
346 return XmlSchemaSimpleType.XdtUntypedAtomic;
347 case XmlTypeCode.String:
348 return XmlSchemaSimpleType.XsString;
349 case XmlTypeCode.Boolean:
350 return XmlSchemaSimpleType.XsBoolean;
351 case XmlTypeCode.Decimal:
352 return XmlSchemaSimpleType.XsDecimal;
353 case XmlTypeCode.Float:
354 return XmlSchemaSimpleType.XsFloat;
355 case XmlTypeCode.Double:
356 return XmlSchemaSimpleType.XsDouble;
357 case XmlTypeCode.Duration:
358 return XmlSchemaSimpleType.XsDuration;
359 case XmlTypeCode.DateTime:
360 return XmlSchemaSimpleType.XsDateTime;
361 case XmlTypeCode.Time:
362 return XmlSchemaSimpleType.XsTime;
363 case XmlTypeCode.Date:
364 return XmlSchemaSimpleType.XsDate;
365 case XmlTypeCode.GYearMonth:
366 return XmlSchemaSimpleType.XsGYearMonth;
367 case XmlTypeCode.GYear:
368 return XmlSchemaSimpleType.XsGYear;
369 case XmlTypeCode.GMonthDay:
370 return XmlSchemaSimpleType.XsGMonthDay;
371 case XmlTypeCode.GDay:
372 return XmlSchemaSimpleType.XsGDay;
373 case XmlTypeCode.GMonth:
374 return XmlSchemaSimpleType.XsGMonth;
375 case XmlTypeCode.HexBinary:
376 return XmlSchemaSimpleType.XsHexBinary;
377 case XmlTypeCode.Base64Binary:
378 return XmlSchemaSimpleType.XsBase64Binary;
379 case XmlTypeCode.AnyUri:
380 return XmlSchemaSimpleType.XsAnyUri;
381 case XmlTypeCode.QName:
382 return XmlSchemaSimpleType.XsQName;
383 case XmlTypeCode.Notation:
384 return XmlSchemaSimpleType.XsNotation;
385 case XmlTypeCode.NormalizedString:
386 return XmlSchemaSimpleType.XsNormalizedString;
387 case XmlTypeCode.Token:
388 return XmlSchemaSimpleType.XsToken;
389 case XmlTypeCode.Language:
390 return XmlSchemaSimpleType.XsLanguage;
391 case XmlTypeCode.NmToken: // NmTokens is not primitive
392 return XmlSchemaSimpleType.XsNMToken;
393 case XmlTypeCode.Name:
394 return XmlSchemaSimpleType.XsName;
395 case XmlTypeCode.NCName:
396 return XmlSchemaSimpleType.XsNCName;
398 return XmlSchemaSimpleType.XsID;
399 case XmlTypeCode.Idref: // Idrefs is not primitive
400 return XmlSchemaSimpleType.XsIDRef;
401 case XmlTypeCode.Entity: // Entities is not primitive
402 return XmlSchemaSimpleType.XsEntity;
403 case XmlTypeCode.Integer:
404 return XmlSchemaSimpleType.XsInteger;
405 case XmlTypeCode.NonPositiveInteger:
406 return XmlSchemaSimpleType.XsNonPositiveInteger;
407 case XmlTypeCode.NegativeInteger:
408 return XmlSchemaSimpleType.XsNegativeInteger;
409 case XmlTypeCode.Long:
410 return XmlSchemaSimpleType.XsLong;
411 case XmlTypeCode.Int:
412 return XmlSchemaSimpleType.XsInt;
413 case XmlTypeCode.Short:
414 return XmlSchemaSimpleType.XsShort;
415 case XmlTypeCode.Byte:
416 return XmlSchemaSimpleType.XsByte;
417 case XmlTypeCode.NonNegativeInteger:
418 return XmlSchemaSimpleType.XsNonNegativeInteger;
419 case XmlTypeCode.UnsignedLong:
420 return XmlSchemaSimpleType.XsUnsignedLong;
421 case XmlTypeCode.UnsignedInt:
422 return XmlSchemaSimpleType.XsUnsignedInt;
423 case XmlTypeCode.UnsignedShort:
424 return XmlSchemaSimpleType.XsUnsignedShort;
425 case XmlTypeCode.UnsignedByte:
426 return XmlSchemaSimpleType.XsUnsignedByte;
427 case XmlTypeCode.PositiveInteger:
428 return XmlSchemaSimpleType.XsPositiveInteger;
429 case XmlTypeCode.YearMonthDuration:
430 return XmlSchemaSimpleType.XdtYearMonthDuration;
431 case XmlTypeCode.DayTimeDuration:
432 return XmlSchemaSimpleType.XdtDayTimeDuration;
437 public static bool IsDerivedFrom (XmlSchemaType derivedType, XmlSchemaType baseType, XmlSchemaDerivationMethod except)
439 if (derivedType.BaseXmlSchemaType == null)
441 if ((derivedType.DerivedBy & except) != 0)
443 if (derivedType.BaseXmlSchemaType == baseType)
445 return IsDerivedFrom (derivedType.BaseXmlSchemaType,
450 internal bool ValidateRecursionCheck ()
453 return (this != XmlSchemaComplexType.AnyType);
455 XmlSchemaType baseType = this.BaseXmlSchemaType as XmlSchemaType;
457 if (baseType != null)
458 result = baseType.ValidateRecursionCheck ();