The Labs \ Source Viewer \ SSCLI \ System.Xml.Schema \ XmlSchemaAttribute

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XmlSchemaAttribute.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. // <owner current="true" primary="true">priyal</owner>
  15. //------------------------------------------------------------------------------
  16. using System.Xml.XPath;
  17. using System.Collections;
  18. using System.ComponentModel;
  19. using System.Xml.Serialization;
  20. namespace System.Xml.Schema
  21. {
  22.    
  23.     /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute"]/*' />
  24.     /// <devdoc>
  25.     /// <para>[To be supplied.]</para>
  26.     /// </devdoc>
  27.     public class XmlSchemaAttribute : XmlSchemaAnnotated
  28.     {
  29.         string defaultValue;
  30.         string fixedValue;
  31.         string name;
  32.         string prefix;
  33.        
  34.         XmlSchemaForm form = XmlSchemaForm.None;
  35.         XmlSchemaUse use = XmlSchemaUse.None;
  36.        
  37.         XmlQualifiedName refName = XmlQualifiedName.Empty;
  38.         XmlQualifiedName typeName = XmlQualifiedName.Empty;
  39.         XmlQualifiedName qualifiedName = XmlQualifiedName.Empty;
  40.        
  41.         XmlSchemaSimpleType type;
  42.         XmlSchemaSimpleType attributeType;
  43.        
  44.         SchemaAttDef attDef;
  45.        
  46.         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.DefaultValue"]/*' />
  47.         /// <devdoc>
  48.         /// <para>[To be supplied.]</para>
  49.         /// </devdoc>
  50.         [XmlAttribute("default")]
  51.         [DefaultValue(null)]
  52.         public string DefaultValue {
  53.             get { return defaultValue; }
  54.             set { defaultValue = value; }
  55.         }
  56.        
  57.         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.FixedValue"]/*' />
  58.         /// <devdoc>
  59.         /// <para>[To be supplied.]</para>
  60.         /// </devdoc>
  61.         [XmlAttribute("fixed")]
  62.         [DefaultValue(null)]
  63.         public string FixedValue {
  64.             get { return fixedValue; }
  65.             set { fixedValue = value; }
  66.         }
  67.        
  68.         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.Form"]/*' />
  69.         /// <devdoc>
  70.         /// <para>[To be supplied.]</para>
  71.         /// </devdoc>
  72.         [XmlAttribute("form"), DefaultValue(XmlSchemaForm.None)]
  73.         public XmlSchemaForm Form {
  74.             get { return form; }
  75.             set { form = value; }
  76.         }
  77.        
  78.         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.Name"]/*' />
  79.         /// <devdoc>
  80.         /// <para>[To be supplied.]</para>
  81.         /// </devdoc>
  82.         [XmlAttribute("name")]
  83.         public string Name {
  84.             get { return name; }
  85.             set { name = value; }
  86.         }
  87.        
  88.         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.RefName"]/*' />
  89.         /// <devdoc>
  90.         /// <para>[To be supplied.]</para>
  91.         /// </devdoc>
  92.         [XmlAttribute("ref")]
  93.         public XmlQualifiedName RefName {
  94.             get { return refName; }
  95.             set { refName = (value == null ? XmlQualifiedName.Empty : value); }
  96.         }
  97.        
  98.         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.SchemaTypeName"]/*' />
  99.         /// <devdoc>
  100.         /// <para>[To be supplied.]</para>
  101.         /// </devdoc>
  102.         [XmlAttribute("type")]
  103.         public XmlQualifiedName SchemaTypeName {
  104.             get { return typeName; }
  105.             set { typeName = (value == null ? XmlQualifiedName.Empty : value); }
  106.         }
  107.        
  108.         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.SchemaType"]/*' />
  109.         /// <devdoc>
  110.         /// <para>[To be supplied.]</para>
  111.         /// </devdoc>
  112.         [XmlElement("simpleType")]
  113.         public XmlSchemaSimpleType SchemaType {
  114.             get { return type; }
  115.             set { type = value; }
  116.         }
  117.        
  118.         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.Use"]/*' />
  119.         /// <devdoc>
  120.         /// <para>[To be supplied.]</para>
  121.         /// </devdoc>
  122.         [XmlAttribute("use"), DefaultValue(XmlSchemaUse.None)]
  123.         public XmlSchemaUse Use {
  124.             get { return use; }
  125.             set { use = value; }
  126.         }
  127.        
  128.         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.QualifiedName"]/*' />
  129.         /// <devdoc>
  130.         /// <para>[To be supplied.]</para>
  131.         /// </devdoc>
  132.         [XmlIgnore()]
  133.         public XmlQualifiedName QualifiedName {
  134.             get { return qualifiedName; }
  135.         }
  136.        
  137.         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.AttributeType"]/*' />
  138.         /// <devdoc>
  139.         /// <para>[To be supplied.]</para>
  140.         /// </devdoc>
  141.         [XmlIgnore()]
  142.         [Obsolete("This property has been deprecated. Please use AttributeSchemaType property that returns a strongly typed attribute type. http://go.microsoft.com/fwlink/?linkid=14202")]
  143.         public object AttributeType {
  144.             get {
  145.                 if (attributeType.QualifiedName.Namespace == XmlReservedNs.NsXs) {
  146.                     return attributeType.Datatype;
  147.                 }
  148.                 return attributeType;
  149.             }
  150.         }
  151.        
  152.         /// <include file='doc\XmlSchemaAttribute.uex' path='docs/doc[@for="XmlSchemaAttribute.AttributeSchemaType"]/*' />
  153.         /// <devdoc>
  154.         /// <para>[To be supplied.]</para>
  155.         /// </devdoc>
  156.         [XmlIgnore()]
  157.         public XmlSchemaSimpleType AttributeSchemaType {
  158.             get { return attributeType; }
  159.         }
  160.        
  161.         internal XmlReader Validate(XmlReader reader, XmlResolver resolver, XmlSchemaSet schemaSet, ValidationEventHandler valEventHandler)
  162.         {
  163.             if (schemaSet != null) {
  164.                 XmlReaderSettings readerSettings = new XmlReaderSettings();
  165.                 readerSettings.ValidationType = ValidationType.Schema;
  166.                 readerSettings.Schemas = schemaSet;
  167.                 readerSettings.ValidationEventHandler += valEventHandler;
  168.                 return new XsdValidatingReader(reader, resolver, readerSettings, this);
  169.             }
  170.             return null;
  171.         }
  172.        
  173.         [XmlIgnore()]
  174.         internal XmlSchemaDatatype Datatype {
  175.             get {
  176.                 if (attributeType != null) {
  177.                     return attributeType.Datatype;
  178.                 }
  179.                 return null;
  180.             }
  181.         }
  182.        
  183.         internal void SetQualifiedName(XmlQualifiedName value)
  184.         {
  185.             qualifiedName = value;
  186.         }
  187.        
  188.         internal void SetAttributeType(XmlSchemaSimpleType value)
  189.         {
  190.             attributeType = value;
  191.         }
  192.        
  193.         internal string Prefix {
  194.             get { return prefix; }
  195.         }
  196.        
  197.         internal SchemaAttDef AttDef {
  198.             get { return attDef; }
  199.             set { attDef = value; }
  200.         }
  201.        
  202.         internal bool HasDefault {
  203.             get { return defaultValue != null; }
  204.         }
  205.        
  206.         [XmlIgnore()]
  207.         internal override string NameAttribute {
  208.             get { return Name; }
  209.             set { Name = value; }
  210.         }
  211.        
  212.         internal override XmlSchemaObject Clone()
  213.         {
  214.             XmlSchemaAttribute newAtt = (XmlSchemaAttribute)MemberwiseClone();
  215.            
  216.             //Deep clone the QNames as these will be updated on chameleon includes
  217.             newAtt.refName = this.refName.Clone();
  218.             newAtt.typeName = this.typeName.Clone();
  219.             return newAtt;
  220.         }
  221.     }
  222. }

Developer Fusion