1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
//------------------------------------------------------------------------------
// <copyright file="SchemaElementDecl.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
//------------------------------------------------------------------------------
namespace System.Xml.Schema {
using System;
using System.Collections;
using System.Diagnostics;
using System.Collections.Generic;
internal sealed class SchemaElementDecl : SchemaDeclBase, IDtdAttributeListInfo {
Dictionary<XmlQualifiedName, SchemaAttDef> attdefs = new Dictionary<XmlQualifiedName, SchemaAttDef>();
List<IDtdDefaultAttributeInfo> defaultAttdefs;
bool isIdDeclared;
bool hasNonCDataAttribute = false;
#if !SILVERLIGHT
bool isAbstract = false;
bool isNillable = false;
bool hasRequiredAttribute = false;
bool isNotationDeclared;
Dictionary<XmlQualifiedName, XmlQualifiedName> prohibitedAttributes = new Dictionary<XmlQualifiedName, XmlQualifiedName>();
ContentValidator contentValidator;
XmlSchemaAnyAttribute anyAttribute;
XmlSchemaDerivationMethod block;
CompiledIdentityConstraint[] constraints;
XmlSchemaElement schemaElement;
internal static readonly SchemaElementDecl Empty = new SchemaElementDecl();
#endif
//
// Constructor
//
#if !SILVERLIGHT
internal SchemaElementDecl() {
}
internal SchemaElementDecl(XmlSchemaDatatype dtype) {
Datatype = dtype;
contentValidator = ContentValidator.TextOnly;
}
#endif
internal SchemaElementDecl(XmlQualifiedName name, String prefix)
: base(name, prefix) {
}
//
// Static methods
//
#if !SILVERLIGHT
internal static SchemaElementDecl CreateAnyTypeElementDecl() {
SchemaElementDecl anyTypeElementDecl = new SchemaElementDecl();
anyTypeElementDecl.Datatype = DatatypeImplementation.AnySimpleType.Datatype;
return anyTypeElementDecl;
}
#endif
//
// IDtdAttributeListInfo interface
//
#region IDtdAttributeListInfo Members
string IDtdAttributeListInfo.Prefix {
get { return ((SchemaElementDecl)this).Prefix; }
}
string IDtdAttributeListInfo.LocalName {
get { return ((SchemaElementDecl)this).Name.Name; }
}
bool IDtdAttributeListInfo.HasNonCDataAttributes {
get { return hasNonCDataAttribute; }
}
IDtdAttributeInfo IDtdAttributeListInfo.LookupAttribute(string prefix, string localName) {
XmlQualifiedName qname = new XmlQualifiedName(localName, prefix);
SchemaAttDef attDef;
if (attdefs.TryGetValue(qname, out attDef)) {
return attDef;
}
return null;
}
IEnumerable<IDtdDefaultAttributeInfo> IDtdAttributeListInfo.LookupDefaultAttributes() {
return defaultAttdefs;
}
IDtdAttributeInfo IDtdAttributeListInfo.LookupIdAttribute() {
foreach (SchemaAttDef attDef in attdefs.Values) {
if (attDef.TokenizedType == XmlTokenizedType.ID) {
return (IDtdAttributeInfo)attDef;
}
}
return null;
}
#endregion
//
// SchemaElementDecl properties
//
internal bool IsIdDeclared {
get { return isIdDeclared;}
set { isIdDeclared = value;}
}
internal bool HasNonCDataAttribute {
get { return hasNonCDataAttribute; }
set { hasNonCDataAttribute = value; }
}
#if !SILVERLIGHT
internal SchemaElementDecl Clone() {
return (SchemaElementDecl) MemberwiseClone();
}
internal bool IsAbstract {
get { return isAbstract;}
set { isAbstract = value;}
}
internal bool IsNillable {
get { return isNillable;}
set { isNillable = value;}
}
internal XmlSchemaDerivationMethod Block {
get { return block; }
set { block = value; }
}
internal bool IsNotationDeclared {
get { return isNotationDeclared; }
set { isNotationDeclared = value; }
}
internal bool HasDefaultAttribute {
get { return defaultAttdefs != null; }
}
internal bool HasRequiredAttribute {
get { return hasRequiredAttribute; }
set { hasRequiredAttribute = value; }
}
internal ContentValidator ContentValidator {
get { return contentValidator;}
set { contentValidator = value;}
}
internal XmlSchemaAnyAttribute AnyAttribute {
get { return anyAttribute; }
set { anyAttribute = value; }
}
internal CompiledIdentityConstraint[] Constraints {
get { return constraints; }
set { constraints = value; }
}
internal XmlSchemaElement SchemaElement {
get { return schemaElement;}
set { schemaElement = value;}
}
#endif
// add a new SchemaAttDef to the SchemaElementDecl
internal void AddAttDef(SchemaAttDef attdef) {
attdefs.Add(attdef.Name, attdef);
#if !SILVERLIGHT
if (attdef.Presence == SchemaDeclBase.Use.Required || attdef.Presence == SchemaDeclBase.Use.RequiredFixed) {
hasRequiredAttribute = true;
}
#endif
if (attdef.Presence == SchemaDeclBase.Use.Default || attdef.Presence == SchemaDeclBase.Use.Fixed) { //Not adding RequiredFixed here
if (defaultAttdefs == null) {
defaultAttdefs = new List<IDtdDefaultAttributeInfo>();
}
defaultAttdefs.Add(attdef);
}
}
/*
* Retrieves the attribute definition of the named attribute.
* @param name The name of the attribute.
* @return an attribute definition object; returns null if it is not found.
*/
internal SchemaAttDef GetAttDef(XmlQualifiedName qname) {
SchemaAttDef attDef;
if (attdefs.TryGetValue(qname, out attDef)) {
return attDef;
}
return null;
}
internal IList<IDtdDefaultAttributeInfo> DefaultAttDefs {
get { return defaultAttdefs; }
}
#if !SILVERLIGHT
internal Dictionary<XmlQualifiedName, SchemaAttDef> AttDefs {
get { return attdefs; }
}
internal Dictionary<XmlQualifiedName, XmlQualifiedName> ProhibitedAttributes {
get { return prohibitedAttributes; }
}
internal void CheckAttributes(Hashtable presence, bool standalone) {
foreach(SchemaAttDef attdef in attdefs.Values) {
if (presence[attdef.Name] == null) {
if (attdef.Presence == SchemaDeclBase.Use.Required) {
throw new XmlSchemaException(Res.Sch_MissRequiredAttribute, attdef.Name.ToString());
}
else if (standalone && attdef.IsDeclaredInExternal && (attdef.Presence == SchemaDeclBase.Use.Default || attdef.Presence == SchemaDeclBase.Use.Fixed)) {
throw new XmlSchemaException(Res.Sch_StandAlone, string.Empty);
}
}
}
}
#endif
}
}
|