/// <summary> /// Handler for the using element /// </summary> /// <param name="reader"></param> private void HandleUsingElement(XmlReader reader) { UsingElement referencedNamespace = new UsingElement(this); referencedNamespace.Parse(reader); AliasResolver.Add(referencedNamespace); }
internal override void ResolveTopLevelNames() { base.ResolveTopLevelNames(); // Resolve all the referenced namespace to make sure that this namespace is valid AliasResolver.ResolveNamespaces(); foreach (SchemaElement element in SchemaTypes) { element.ResolveTopLevelNames(); } foreach (Function function in Functions) { function.ResolveTopLevelNames(); } }
/// <summary> /// Look up a fully qualified type name reference. /// </summary> /// <param name="usingElement">element containing the reference</param> /// <param name="typeName">the fully qualified type name</param> /// <param name="type">the referenced schema type</param> /// <returns>false if there was an error</returns> internal bool ResolveTypeName(SchemaElement usingElement, string typeName, out SchemaType type) { Debug.Assert(usingElement != null); Debug.Assert(typeName != null); type = null; // get the schema(s) that match the namespace/alias string actualQualification; string unqualifiedTypeName; Utils.ExtractNamespaceAndName(DataModel, typeName, out actualQualification, out unqualifiedTypeName); string definingQualification = actualQualification; if (definingQualification == null) { definingQualification = this.ProviderManifest == null ? this._namespaceName : this.ProviderManifest.NamespaceName; } string namespaceName; // First check if there is an alias defined by this name. For primitive type namespace, we do not need to resolve // any alias, since that's a reserved keyword and we don't allow alias with that name if (actualQualification == null || !AliasResolver.TryResolveAlias(definingQualification, out namespaceName)) { namespaceName = definingQualification; } // Resolve the type name if (!SchemaManager.TryResolveType(namespaceName, unqualifiedTypeName, out type)) { // it must be an undefined type. if (actualQualification == null) { // Every type except the primitive type must be qualified usingElement.AddError(ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.NotNamespaceQualified(typeName)); } else if (!SchemaManager.IsValidNamespaceName(namespaceName)) { usingElement.AddError(ErrorCode.BadNamespace, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.BadNamespaceOrAlias(actualQualification)); } else { // if the type name was alias qualified if (namespaceName != definingQualification) { usingElement.AddError(ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.NotInNamespaceAlias(unqualifiedTypeName, namespaceName, definingQualification)); } else { usingElement.AddError(ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.NotInNamespaceNoAlias(unqualifiedTypeName, namespaceName)); } } return(false); } // For ssdl and provider manifest, make sure that the type is present in this schema or primitive schema else if (this.DataModel != SchemaDataModelOption.EntityDataModel && type.Schema != this && type.Schema != this.SchemaManager.PrimitiveSchema) { Debug.Assert(type.Namespace != this.Namespace, "Using element is not allowed in the schema of ssdl and provider manifest"); usingElement.AddError(ErrorCode.InvalidNamespaceOrAliasSpecified, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidNamespaceOrAliasSpecified(actualQualification)); return(false); } return(true); }