/// <summary> /// Handler for the using element /// </summary> /// <param name="reader"> </param> private void HandleUsingElement(XmlReader reader) { var 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 (var 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) { DebugCheck.NotNull(usingElement); DebugCheck.NotNull(typeName); type = null; // get the schema(s) that match the namespace/alias string actualQualification; string unqualifiedTypeName; Utils.ExtractNamespaceAndName(typeName, out actualQualification, out unqualifiedTypeName); var definingQualification = actualQualification; if (definingQualification == null) { definingQualification = ProviderManifest == null ? _namespaceName : 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, Strings.NotNamespaceQualified(typeName)); } else if (!SchemaManager.IsValidNamespaceName(namespaceName)) { usingElement.AddError( ErrorCode.BadNamespace, EdmSchemaErrorSeverity.Error, Strings.BadNamespaceOrAlias(actualQualification)); } else { // if the type name was alias qualified if (namespaceName != definingQualification) { usingElement.AddError( ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, Strings.NotInNamespaceAlias(unqualifiedTypeName, namespaceName, definingQualification)); } else { usingElement.AddError( ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, 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 (DataModel != SchemaDataModelOption.EntityDataModel && type.Schema != this && type.Schema != SchemaManager.PrimitiveSchema) { Debug.Assert(type.Namespace != Namespace, "Using element is not allowed in the schema of ssdl and provider manifest"); usingElement.AddError( ErrorCode.InvalidNamespaceOrAliasSpecified, EdmSchemaErrorSeverity.Error, Strings.InvalidNamespaceOrAliasSpecified(actualQualification)); return(false); } return(true); }