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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XmlSchemaElement.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.ComponentModel;
  18. using System.Xml.Serialization;
  19. using System.Diagnostics;
  20. namespace System.Xml.Schema
  21. {
  22.    
  23.    
  24.     /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement"]/*' />
  25.     /// <devdoc>
  26.     /// <para>[To be supplied.]</para>
  27.     /// </devdoc>
  28.     public class XmlSchemaElement : XmlSchemaParticle
  29.     {
  30.         bool isAbstract;
  31.         bool hasAbstractAttribute;
  32.         bool isNillable;
  33.         bool hasNillableAttribute;
  34.         bool isLocalTypeDerivationChecked;
  35.        
  36.         XmlSchemaDerivationMethod block = XmlSchemaDerivationMethod.None;
  37.         XmlSchemaDerivationMethod final = XmlSchemaDerivationMethod.None;
  38.         XmlSchemaForm form = XmlSchemaForm.None;
  39.         string defaultValue;
  40.         string fixedValue;
  41.         string name;
  42.        
  43.         XmlQualifiedName refName = XmlQualifiedName.Empty;
  44.         XmlQualifiedName substitutionGroup = XmlQualifiedName.Empty;
  45.         XmlQualifiedName typeName = XmlQualifiedName.Empty;
  46.         XmlSchemaType type = null;
  47.        
  48.         XmlQualifiedName qualifiedName = XmlQualifiedName.Empty;
  49.         XmlSchemaType elementType;
  50.         XmlSchemaDerivationMethod blockResolved;
  51.         XmlSchemaDerivationMethod finalResolved;
  52.         XmlSchemaObjectCollection constraints;
  53.         SchemaElementDecl elementDecl;
  54.        
  55.        
  56.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.IsAbstract"]/*' />
  57.         /// <devdoc>
  58.         /// <para>[To be supplied.]</para>
  59.         /// </devdoc>
  60.         [XmlAttribute("abstract"), DefaultValue(false)]
  61.         public bool IsAbstract {
  62.             get { return isAbstract; }
  63.             set {
  64.                 isAbstract = value;
  65.                 hasAbstractAttribute = true;
  66.             }
  67.         }
  68.        
  69.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.Block"]/*' />
  70.         /// <devdoc>
  71.         /// <para>[To be supplied.]</para>
  72.         /// </devdoc>
  73.         [XmlAttribute("block"), DefaultValue(XmlSchemaDerivationMethod.None)]
  74.         public XmlSchemaDerivationMethod Block {
  75.             get { return block; }
  76.             set { block = value; }
  77.         }
  78.        
  79.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.DefaultValue"]/*' />
  80.         /// <devdoc>
  81.         /// <para>[To be supplied.]</para>
  82.         /// </devdoc>
  83.         [XmlAttribute("default")]
  84.         [DefaultValue(null)]
  85.         public string DefaultValue {
  86.             get { return defaultValue; }
  87.             set { defaultValue = value; }
  88.         }
  89.        
  90.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.Final"]/*' />
  91.         /// <devdoc>
  92.         /// <para>[To be supplied.]</para>
  93.         /// </devdoc>
  94.         [XmlAttribute("final"), DefaultValue(XmlSchemaDerivationMethod.None)]
  95.         public XmlSchemaDerivationMethod Final {
  96.             get { return final; }
  97.             set { final = value; }
  98.         }
  99.        
  100.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.FixedValue"]/*' />
  101.         /// <devdoc>
  102.         /// <para>[To be supplied.]</para>
  103.         /// </devdoc>
  104.         [XmlAttribute("fixed")]
  105.         [DefaultValue(null)]
  106.         public string FixedValue {
  107.             get { return fixedValue; }
  108.             set { fixedValue = value; }
  109.         }
  110.        
  111.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.Form"]/*' />
  112.         /// <devdoc>
  113.         /// <para>[To be supplied.]</para>
  114.         /// </devdoc>
  115.         [XmlAttribute("form"), DefaultValue(XmlSchemaForm.None)]
  116.         public XmlSchemaForm Form {
  117.             get { return form; }
  118.             set { form = value; }
  119.         }
  120.        
  121.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.Name"]/*' />
  122.         /// <devdoc>
  123.         /// <para>[To be supplied.]</para>
  124.         /// </devdoc>
  125.         [XmlAttribute("name"), DefaultValue("")]
  126.         public string Name {
  127.             get { return name; }
  128.             set { name = value; }
  129.         }
  130.        
  131.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.IsNillable"]/*' />
  132.         /// <devdoc>
  133.         /// <para>[To be supplied.]</para>
  134.         /// </devdoc>
  135.         [XmlAttribute("nillable"), DefaultValue(false)]
  136.         public bool IsNillable {
  137.             get { return isNillable; }
  138.             set {
  139.                 isNillable = value;
  140.                 hasNillableAttribute = true;
  141.             }
  142.         }
  143.        
  144.         [XmlIgnore()]
  145.         internal bool HasNillableAttribute {
  146.             get { return hasNillableAttribute; }
  147.         }
  148.        
  149.         [XmlIgnore()]
  150.         internal bool HasAbstractAttribute {
  151.             get { return hasAbstractAttribute; }
  152.         }
  153.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.RefName"]/*' />
  154.         /// <devdoc>
  155.         /// <para>[To be supplied.]</para>
  156.         /// </devdoc>
  157.         [XmlAttribute("ref")]
  158.         public XmlQualifiedName RefName {
  159.             get { return refName; }
  160.             set { refName = (value == null ? XmlQualifiedName.Empty : value); }
  161.         }
  162.        
  163.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.SubstitutionGroup"]/*' />
  164.         /// <devdoc>
  165.         /// <para>[To be supplied.]</para>
  166.         /// </devdoc>
  167.         [XmlAttribute("substitutionGroup")]
  168.         public XmlQualifiedName SubstitutionGroup {
  169.             get { return substitutionGroup; }
  170.             set { substitutionGroup = (value == null ? XmlQualifiedName.Empty : value); }
  171.         }
  172.        
  173.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.SchemaTypeName"]/*' />
  174.         /// <devdoc>
  175.         /// <para>[To be supplied.]</para>
  176.         /// </devdoc>
  177.         [XmlAttribute("type")]
  178.         public XmlQualifiedName SchemaTypeName {
  179.             get { return typeName; }
  180.             set { typeName = (value == null ? XmlQualifiedName.Empty : value); }
  181.         }
  182.        
  183.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.SchemaType"]/*' />
  184.         /// <devdoc>
  185.         /// <para>[To be supplied.]</para>
  186.         /// </devdoc>
  187.         [XmlElement("complexType", typeof(XmlSchemaComplexType)), XmlElement("simpleType", typeof(XmlSchemaSimpleType))]
  188.         public XmlSchemaType SchemaType {
  189.             get { return type; }
  190.             set { type = value; }
  191.         }
  192.        
  193.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.Constraints"]/*' />
  194.         /// <devdoc>
  195.         /// <para>[To be supplied.]</para>
  196.         /// </devdoc>
  197.         [XmlElement("key", typeof(XmlSchemaKey)), XmlElement("keyref", typeof(XmlSchemaKeyref)), XmlElement("unique", typeof(XmlSchemaUnique))]
  198.         public XmlSchemaObjectCollection Constraints {
  199.             get {
  200.                 if (constraints == null) {
  201.                     constraints = new XmlSchemaObjectCollection();
  202.                 }
  203.                 return constraints;
  204.             }
  205.         }
  206.        
  207.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.QualifiedName"]/*' />
  208.         /// <devdoc>
  209.         /// <para>[To be supplied.]</para>
  210.         /// </devdoc>
  211.         [XmlIgnore()]
  212.         public XmlQualifiedName QualifiedName {
  213.             get { return qualifiedName; }
  214.         }
  215.        
  216.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.ElementType"]/*' />
  217.         /// <devdoc>
  218.         /// <para>[To be supplied.]</para>
  219.         /// </devdoc>
  220.         [XmlIgnore()]
  221.         [Obsolete("This property has been deprecated. Please use ElementSchemaType property that returns a strongly typed element type. http://go.microsoft.com/fwlink/?linkid=14202")]
  222.         public object ElementType {
  223.             get {
  224.                 if (elementType.QualifiedName.Namespace == XmlReservedNs.NsXs) {
  225.                     return elementType.Datatype;
  226.                     //returns XmlSchemaDatatype;
  227.                 }
  228.                 return elementType;
  229.             }
  230.         }
  231.        
  232.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.ElementType"]/*' />
  233.         /// <devdoc>
  234.         /// <para>[To be supplied.]</para>
  235.         /// </devdoc>
  236.         [XmlIgnore()]
  237.         public XmlSchemaType ElementSchemaType {
  238.             get { return elementType; }
  239.         }
  240.        
  241.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.BlockResolved"]/*' />
  242.         /// <devdoc>
  243.         /// <para>[To be supplied.]</para>
  244.         /// </devdoc>
  245.         [XmlIgnore()]
  246.         public XmlSchemaDerivationMethod BlockResolved {
  247.             get { return blockResolved; }
  248.         }
  249.        
  250.         /// <include file='doc\XmlSchemaElement.uex' path='docs/doc[@for="XmlSchemaElement.FinalResolved"]/*' />
  251.         /// <devdoc>
  252.         /// <para>[To be supplied.]</para>
  253.         /// </devdoc>
  254.         [XmlIgnore()]
  255.         public XmlSchemaDerivationMethod FinalResolved {
  256.             get { return finalResolved; }
  257.         }
  258.        
  259.         internal XmlReader Validate(XmlReader reader, XmlResolver resolver, XmlSchemaSet schemaSet, ValidationEventHandler valEventHandler)
  260.         {
  261.             if (schemaSet != null) {
  262.                 XmlReaderSettings readerSettings = new XmlReaderSettings();
  263.                 readerSettings.ValidationType = ValidationType.Schema;
  264.                 readerSettings.Schemas = schemaSet;
  265.                 readerSettings.ValidationEventHandler += valEventHandler;
  266.                 return new XsdValidatingReader(reader, resolver, readerSettings, this);
  267.             }
  268.             return null;
  269.         }
  270.        
  271.         internal void SetQualifiedName(XmlQualifiedName value)
  272.         {
  273.             qualifiedName = value;
  274.         }
  275.        
  276.         internal void SetElementType(XmlSchemaType value)
  277.         {
  278.             elementType = value;
  279.         }
  280.        
  281.         internal void SetBlockResolved(XmlSchemaDerivationMethod value)
  282.         {
  283.             blockResolved = value;
  284.         }
  285.        
  286.         internal void SetFinalResolved(XmlSchemaDerivationMethod value)
  287.         {
  288.             finalResolved = value;
  289.         }
  290.        
  291.         [XmlIgnore()]
  292.         internal bool HasDefault {
  293.             get { return defaultValue != null && defaultValue.Length > 0; }
  294.         }
  295.        
  296.         internal bool HasConstraints {
  297.             get { return constraints != null && constraints.Count > 0; }
  298.         }
  299.        
  300.         internal bool IsLocalTypeDerivationChecked {
  301.             get { return isLocalTypeDerivationChecked; }
  302.             set { isLocalTypeDerivationChecked = value; }
  303.         }
  304.        
  305.         internal SchemaElementDecl ElementDecl {
  306.             get { return elementDecl; }
  307.             set { elementDecl = value; }
  308.         }
  309.        
  310.         [XmlIgnore()]
  311.         internal override string NameAttribute {
  312.             get { return Name; }
  313.             set { Name = value; }
  314.         }
  315.        
  316.         [XmlIgnore()]
  317.         internal override string NameString {
  318.             get { return qualifiedName.ToString(); }
  319.         }
  320.        
  321.         internal override XmlSchemaObject Clone()
  322.         {
  323.             XmlSchemaElement newElem = (XmlSchemaElement)MemberwiseClone();
  324.            
  325.             //Deep clone the QNames as these will be updated on chameleon includes
  326.             newElem.refName = this.refName.Clone();
  327.             newElem.substitutionGroup = this.substitutionGroup.Clone();
  328.             newElem.typeName = this.typeName.Clone();
  329.            
  330.             //Clear compiled tables
  331.             newElem.constraints = null;
  332.             return newElem;
  333.         }
  334.     }
  335. }

Developer Fusion