1 //------------------------------------------------------------------------------ 2 // <copyright file="XmlSchemaParticle.cs" company="Microsoft"> 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // </copyright> 5 // <owner current="true" primary="true">Microsoft</owner> 6 //------------------------------------------------------------------------------ 7 8 namespace System.Xml.Schema { 9 10 using System.Xml.Serialization; 11 12 /// <include file='doc\XmlSchemaParticle.uex' path='docs/doc[@for="XmlSchemaParticle"]/*' /> 13 /// <devdoc> 14 /// <para>[To be supplied.]</para> 15 /// </devdoc> 16 public abstract class XmlSchemaParticle : XmlSchemaAnnotated { 17 [Flags] 18 enum Occurs { 19 None, 20 Min, 21 Max 22 }; 23 decimal minOccurs = decimal.One; 24 decimal maxOccurs = decimal.One; 25 Occurs flags = Occurs.None; 26 27 /// <include file='doc\XmlSchemaParticle.uex' path='docs/doc[@for="XmlSchemaParticle.MinOccursString"]/*' /> 28 /// <devdoc> 29 /// <para>[To be supplied.]</para> 30 /// </devdoc> 31 [XmlAttribute("minOccurs")] 32 public string MinOccursString { 33 get { 34 return (flags & Occurs.Min) == 0 ? null : XmlConvert.ToString(minOccurs); 35 } 36 set { 37 if (value == null) { 38 minOccurs = decimal.One; 39 flags &= ~Occurs.Min; 40 } 41 else { 42 minOccurs = XmlConvert.ToInteger(value); 43 if (minOccurs < decimal.Zero) { 44 throw new XmlSchemaException(Res.Sch_MinOccursInvalidXsd, string.Empty); 45 } 46 flags |= Occurs.Min; 47 } 48 } 49 } 50 51 /// <include file='doc\XmlSchemaParticle.uex' path='docs/doc[@for="XmlSchemaParticle.MaxOccursString"]/*' /> 52 /// <devdoc> 53 /// <para>[To be supplied.]</para> 54 /// </devdoc> 55 [XmlAttribute("maxOccurs")] 56 public string MaxOccursString { 57 get { 58 return (flags & Occurs.Max) == 0 ? null : (maxOccurs == decimal.MaxValue) ? "unbounded" : XmlConvert.ToString(maxOccurs); 59 } 60 set { 61 if (value == null) { 62 maxOccurs = decimal.One; 63 flags &= ~Occurs.Max; 64 } 65 else { 66 if (value == "unbounded") { 67 maxOccurs = decimal.MaxValue; 68 } 69 else { 70 maxOccurs = XmlConvert.ToInteger(value); 71 if (maxOccurs < decimal.Zero) { 72 throw new XmlSchemaException(Res.Sch_MaxOccursInvalidXsd, string.Empty); 73 } 74 else if (maxOccurs == decimal.Zero && (flags & Occurs.Min) == 0) { 75 minOccurs = decimal.Zero; 76 } 77 } 78 flags |= Occurs.Max; 79 } 80 } 81 } 82 83 /// <include file='doc\XmlSchemaParticle.uex' path='docs/doc[@for="XmlSchemaParticle.MinOccurs"]/*' /> 84 /// <devdoc> 85 /// <para>[To be supplied.]</para> 86 /// </devdoc> 87 [XmlIgnore] 88 public decimal MinOccurs { 89 get { return minOccurs; } 90 set { 91 if (value < decimal.Zero || value != decimal.Truncate(value)) { 92 throw new XmlSchemaException(Res.Sch_MinOccursInvalidXsd, string.Empty); 93 } 94 minOccurs = value; 95 flags |= Occurs.Min; 96 } 97 } 98 99 /// <include file='doc\XmlSchemaParticle.uex' path='docs/doc[@for="XmlSchemaParticle.MaxOccurs"]/*' /> 100 /// <devdoc> 101 /// <para>[To be supplied.]</para> 102 /// </devdoc> 103 [XmlIgnore] 104 public decimal MaxOccurs { 105 get { return maxOccurs; } 106 set { 107 if (value < decimal.Zero || value != decimal.Truncate(value)) { 108 throw new XmlSchemaException(Res.Sch_MaxOccursInvalidXsd, string.Empty); 109 } 110 maxOccurs = value; 111 if (maxOccurs == decimal.Zero && (flags & Occurs.Min) == 0) { 112 minOccurs = decimal.Zero; 113 } 114 flags |= Occurs.Max; 115 } 116 } 117 118 internal virtual bool IsEmpty { 119 get { return maxOccurs == decimal.Zero; } 120 } 121 122 internal bool IsMultipleOccurrence { 123 get { return maxOccurs > decimal.One; } 124 } 125 126 internal virtual string NameString { 127 get { 128 return string.Empty; 129 } 130 } 131 GetQualifiedName()132 internal XmlQualifiedName GetQualifiedName() { 133 XmlSchemaElement elem = this as XmlSchemaElement; 134 if (elem != null) { 135 return elem.QualifiedName; 136 } 137 else { 138 XmlSchemaAny any = this as XmlSchemaAny; 139 if (any != null) { 140 string ns = any.Namespace; 141 if (ns != null) { 142 ns = ns.Trim(); 143 } 144 else { 145 ns = string.Empty; 146 } 147 return new XmlQualifiedName("*", ns.Length == 0 ? "##any" : ns); 148 } 149 } 150 return XmlQualifiedName.Empty; //If ever called on other particles 151 } 152 153 class EmptyParticle : XmlSchemaParticle { 154 internal override bool IsEmpty { 155 get { return true; } 156 } 157 } 158 159 internal static readonly XmlSchemaParticle Empty = new EmptyParticle(); 160 } 161 } 162