/// <summary> /// Validates whether facets are declared correctly. /// </summary> /// <param name="element">Schema element being validated. Must not be null.</param> /// <param name="type">Resolved type (from declaration on the element). Possibly null.</param> /// <param name="typeUsageBuilder">TypeUsageBuilder for the current element. Must not be null.</param> internal static void ValidateFacets(SchemaElement element, SchemaType type, TypeUsageBuilder typeUsageBuilder) { Debug.Assert(element != null); Debug.Assert(typeUsageBuilder != null); if (type != null) { var schemaEnumType = type as SchemaEnumType; if (schemaEnumType != null) { typeUsageBuilder.ValidateEnumFacets(schemaEnumType); } else if(!(type is ScalarType) && typeUsageBuilder.HasUserDefinedFacets) { Debug.Assert(!(type is SchemaEnumType), "Note that enums should have already been handled."); // Non-scalar type should not have Facets. element.AddError(ErrorCode.FacetOnNonScalarType, EdmSchemaErrorSeverity.Error, Strings.FacetsOnNonScalarType(type.FQName)); } } else { if(typeUsageBuilder.HasUserDefinedFacets) { // Type attribute not specified but facets exist. element.AddError(ErrorCode.IncorrectlyPlacedFacet, EdmSchemaErrorSeverity.Error, Strings.FacetDeclarationRequiresTypeAttribute); } } }
internal static void GetElementLocationInfo(System.Data.EntityModel.SchemaObjectModel.Schema schema, string itemIdentity, out int lineNumber, out int linePosition) { System.Data.EntityModel.SchemaObjectModel.SchemaElement element = GetSchemaElement(schema, itemIdentity); if (null != element) { lineNumber = element.LineNumber; linePosition = element.LinePosition; } else { lineNumber = linePosition = -1; } }
/// <summary> /// Validated whether a type is declared correctly. /// </summary> /// <param name="element">Schema element being validated. Must not be null.</param> /// <param name="type">Resolved type (from declaration on the element). Possibly null.</param> /// <param name="typeSubElement">Child schema element. Possibly null.</param> /// <remarks> /// For some elements (e.g. ReturnType) we allow the type to be defined inline in an attribute on the element itself or /// by using nested elements. These definitions are mutually exclusive. /// </remarks> internal static void ValidateTypeDeclaration(SchemaElement element, SchemaType type, SchemaElement typeSubElement) { Debug.Assert(element != null); if (type == null && typeSubElement == null) { //Type not declared as either attribute or subelement element.AddError(ErrorCode.TypeNotDeclared, EdmSchemaErrorSeverity.Error, Strings.TypeMustBeDeclared); } if (type != null && typeSubElement != null) { //Both attribute and sub-element declarations exist element.AddError(ErrorCode.TypeDeclaredAsAttributeAndElement, EdmSchemaErrorSeverity.Error, Strings.TypeDeclaredAsAttributeAndElement); } }
internal static void GetElementLocationInfo(System.Data.EntityModel.SchemaObjectModel.Schema schema, string parentIdentity, string itemIdentity, out int lineNumber, out int linePosition) { lineNumber = linePosition = -1; System.Data.EntityModel.SchemaObjectModel.SchemaElement element = GetSchemaElement(schema, parentIdentity); System.Data.EntityModel.SchemaObjectModel.StructuredType elementWithProperty = element as System.Data.EntityModel.SchemaObjectModel.StructuredType; if (null != elementWithProperty && elementWithProperty.Properties.ContainsKey(itemIdentity)) { lineNumber = elementWithProperty.Properties[itemIdentity].LineNumber; linePosition = elementWithProperty.Properties[itemIdentity].LinePosition; } else if (null != element) { lineNumber = element.LineNumber; linePosition = element.LinePosition; } }
/// <summary> /// /// </summary> /// <param name="parentElement"></param> internal SchemaElement(SchemaElement parentElement) { if ( parentElement != null ) { ParentElement = parentElement; for ( SchemaElement element = parentElement; element != null; element = element.ParentElement ) { Schema schema = element as Schema; if ( schema != null ) { Schema = schema; break; } } if (Schema == null) { throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.AllElementsMustBeInSchema); } } }
internal virtual SchemaElement Clone(SchemaElement parentElement) { throw Error.NotImplemented(); }
/// <summary> /// validate the following negative scenarios: /// ReturnType="Collection(EntityTypeA)" /// ReturnType="Collection(EntityTypeA)" EntitySet="ESet.EType is not oftype EntityTypeA" /// EntitySet="A" /// ReturnType="Collection(ComplexTypeA)" EntitySet="something" /// ReturnType="Collection(ComplexTypeA)", but the ComplexTypeA has a nested complexType property, this scenario will be handle in the runtime /// </summary> private void ValidateFunctionImportReturnType(SchemaElement owner, SchemaType returnType, EntityContainerEntitySet entitySet, bool entitySetPathDefined) { // If entity type, verify specification of entity set and that the type is appropriate for the entity set SchemaEntityType entityType = returnType as SchemaEntityType; if (entitySet != null && entitySetPathDefined) { owner.AddError(ErrorCode.FunctionImportEntitySetAndEntitySetPathDeclared, EdmSchemaErrorSeverity.Error, Strings.FunctionImportEntitySetAndEntitySetPathDeclared(this.FQName)); } if (null != entityType) { // entity type if (null == entitySet) { // ReturnType="Collection(EntityTypeA)" owner.AddError(ErrorCode.FunctionImportReturnsEntitiesButDoesNotSpecifyEntitySet, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.FunctionImportReturnEntitiesButDoesNotSpecifyEntitySet(this.FQName)); } else if (null != entitySet.EntityType && !entityType.IsOfType(entitySet.EntityType)) { // ReturnType="Collection(EntityTypeA)" EntitySet="ESet.EType is not oftype EntityTypeA" owner.AddError(ErrorCode.FunctionImportEntityTypeDoesNotMatchEntitySet, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.FunctionImportEntityTypeDoesNotMatchEntitySet( this.FQName, entitySet.EntityType.FQName, entitySet.Name)); } } else { // complex type SchemaComplexType complexType = returnType as SchemaComplexType; if (complexType != null) { if (entitySet != null || entitySetPathDefined) { // ReturnType="Collection(ComplexTypeA)" EntitySet="something" owner.AddError( ErrorCode.ComplexTypeAsReturnTypeAndDefinedEntitySet, EdmSchemaErrorSeverity.Error, owner.LineNumber, owner.LinePosition, System.Data.Entity.Strings.ComplexTypeAsReturnTypeAndDefinedEntitySet(this.FQName, complexType.Name)); } } else { Debug.Assert(returnType == null || returnType is ScalarType || returnType is SchemaEnumType || returnType is Relationship, "null return type, scalar return type, enum return type or relationship expected here."); // scalar type or no return type if (entitySet != null || entitySetPathDefined) { // EntitySet="A" owner.AddError(ErrorCode.FunctionImportSpecifiesEntitySetButDoesNotReturnEntityType, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.FunctionImportSpecifiesEntitySetButNotEntityType(this.FQName)); } } } }
/// <summary> /// /// </summary> /// <param name="parentElement"></param> public DocumentationElement(SchemaElement parentElement) : base(parentElement) { }
internal ModelFunctionTypeElement(SchemaElement parentElement) : base(parentElement) { _typeUsageBuilder = new TypeUsageBuilder(this); }
internal void ResolveEntitySet(SchemaElement owner, string unresolvedEntitySet, ref EntityContainerEntitySet entitySet) { Debug.Assert(IsFunctionImport, "Only FunctionImport elkements specify EntitySets"); Debug.Assert(null != _container, "function imports must know container"); // resolve entity set if (null == entitySet && null != unresolvedEntitySet) { entitySet = _container.FindEntitySet(unresolvedEntitySet); if (null == entitySet) { owner.AddError(ErrorCode.FunctionImportUnknownEntitySet, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.FunctionImportUnknownEntitySet(unresolvedEntitySet, this.FQName)); } } }
internal TypeUsageBuilder(SchemaElement element) { _element = element; _facetValues = new Dictionary <string, object>(); }
/// <summary> /// Initializes a new instance of the <see cref="SchemaEnumMember"/> class. /// </summary> /// <param name="parentElement"> /// Parent element. /// </param> public SchemaEnumMember(SchemaElement parentElement) : base(parentElement) { }
private bool InternalHandleAttribute(XmlReader reader) { if (SchemaElement.CanHandleAttribute(reader, EdmProviderManifest.NullableFacetName)) { HandleNullableAttribute(reader); return(true); } else if (SchemaElement.CanHandleAttribute(reader, XmlConstants.DefaultValueAttribute)) { HandleDefaultAttribute(reader); return(true); } else if (SchemaElement.CanHandleAttribute(reader, EdmProviderManifest.PrecisionFacetName)) { HandlePrecisionAttribute(reader); return(true); } else if (SchemaElement.CanHandleAttribute(reader, EdmProviderManifest.ScaleFacetName)) { HandleScaleAttribute(reader); return(true); } else if (SchemaElement.CanHandleAttribute(reader, EdmProviderManifest.StoreGeneratedPatternFacetName)) { HandleStoreGeneratedPatternAttribute(reader); return(true); } else if (SchemaElement.CanHandleAttribute(reader, EdmProviderManifest.ConcurrencyModeFacetName)) { HandleConcurrencyModeAttribute(reader); return(true); } else if (SchemaElement.CanHandleAttribute(reader, EdmProviderManifest.MaxLengthFacetName)) { HandleMaxLengthAttribute(reader); return(true); } else if (SchemaElement.CanHandleAttribute(reader, EdmProviderManifest.UnicodeFacetName)) { HandleUnicodeAttribute(reader); return(true); } else if (SchemaElement.CanHandleAttribute(reader, EdmProviderManifest.CollationFacetName)) { HandleCollationAttribute(reader); return(true); } else if (SchemaElement.CanHandleAttribute(reader, EdmProviderManifest.FixedLengthFacetName)) { HandleIsFixedLengthAttribute(reader); return(true); } else if (SchemaElement.CanHandleAttribute(reader, EdmProviderManifest.NullableFacetName)) { HandleNullableAttribute(reader); return(true); } else if (SchemaElement.CanHandleAttribute(reader, EdmProviderManifest.SridFacetName)) { HandleSridAttribute(reader); return(true); } return(false); }
internal SchemaElement(SchemaElement parentElement, string name) : this(parentElement) { _name = name; }
/// <summary> /// /// </summary> /// <param name="errorCode"></param> /// <param name="severity"></param> /// <param name="element"></param> /// <param name="message"></param> internal void AddError(ErrorCode errorCode, EdmSchemaErrorSeverity severity, SchemaElement element, object message) { AddError(errorCode, severity, element.Schema.Location, element.LineNumber, element.LinePosition, message); }
/// <summary> /// /// </summary> /// <param name="parentElement"></param> public TextElement(SchemaElement parentElement) : base(parentElement) { }
internal TypeUsageBuilder(SchemaElement element) { _element = element; _facetValues = new Dictionary<string, object>(); }
/// <summary> /// /// </summary> /// <param name="parentElement"></param> internal CollectionTypeElement(SchemaElement parentElement) : base(parentElement) { }
/// <summary> /// /// </summary> /// <param name="parentElement"></param> internal RowTypeElement(SchemaElement parentElement) : base(parentElement) { }
/// <summary> /// /// </summary> /// <param name="parentElement"></param> internal ReferenceTypeElement(SchemaElement parentElement) : base(parentElement) { }
/// <summary> /// /// </summary> /// <param name="parentElement"></param> internal TypeRefElement(SchemaElement parentElement) : base(parentElement) { }
internal FacetEnabledSchemaElement(SchemaElement parentElement) : base(parentElement) { }
/// <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; }
private void ValidateFunctionImportReturnType(SchemaElement owner, SchemaType returnType, CollectionKind returnTypeCollectionKind, EntityContainerEntitySet entitySet, bool entitySetPathDefined) { if (returnType != null && !ReturnTypeMeetsFunctionImportBasicRequirements(returnType, returnTypeCollectionKind)) { owner.AddError(ErrorCode.FunctionImportUnsupportedReturnType, EdmSchemaErrorSeverity.Error, owner, GetReturnTypeErrorMessage(Schema.SchemaVersion, this.Name) ); } ValidateFunctionImportReturnType(owner, returnType, entitySet, entitySetPathDefined); }
internal RowTypePropertyElement(SchemaElement parentElement) : base(parentElement) { _typeUsageBuilder = new TypeUsageBuilder(this); }
internal override SchemaElement Clone(SchemaElement parentElement) { FunctionImportElement function = new FunctionImportElement((EntityContainer)parentElement); CloneSetFunctionFields(function); function._container = _container; function._entitySet = _entitySet; function._unresolvedEntitySet = _unresolvedEntitySet; function._entitySetPathDefined = _entitySetPathDefined; return function; }
/// <summary> /// /// </summary> /// <param name="errorCode"></param> /// <param name="severity"></param> /// <param name="element"></param> /// <param name="message"></param> internal void AddError( ErrorCode errorCode, EdmSchemaErrorSeverity severity, SchemaElement element, object message ) { AddError(errorCode,severity,element.Schema.Location,element.LineNumber,element.LinePosition,message); }
internal override SchemaElement Clone(SchemaElement parentElement) { ReturnType parameter = new ReturnType((Function)parentElement); parameter._type = _type; parameter.Name = this.Name; parameter._typeUsageBuilder = this._typeUsageBuilder; parameter._unresolvedType = this._unresolvedType; parameter._unresolvedEntitySet = this._unresolvedEntitySet; parameter._entitySetPathDefined = this._entitySetPathDefined; parameter._entitySet = this._entitySet; return parameter; }
internal override SchemaElement Clone(SchemaElement parentElement) { EntityContainerAssociationSetEnd setEnd = new EntityContainerAssociationSetEnd((EntityContainerAssociationSet)parentElement); setEnd._unresolvedRelationshipEndRole = _unresolvedRelationshipEndRole; setEnd.EntitySet = this.EntitySet; return setEnd; }
internal override SchemaElement Clone(SchemaElement parentElement) { var associationSet = new EntityContainerAssociationSet((EntityContainer)parentElement); associationSet.Name = Name; associationSet.Relationship = Relationship; foreach (EntityContainerAssociationSetEnd end in Ends) { var clonedEnd = (EntityContainerAssociationSetEnd)end.Clone(associationSet); associationSet._relationshipEnds.Add(clonedEnd.Role, clonedEnd); } return associationSet; }
/// <summary> /// construct a KeyProperty object /// </summary> /// <param name="parentElement"></param> public PropertyRefElement(SchemaElement parentElement) : base(parentElement) { }
internal override SchemaElement Clone(SchemaElement parentElement) { // We only support clone for FunctionImports. throw Error.NotImplemented(); }
/// <summary> /// Validate that reference type is an entity type. /// </summary> /// <param name="element">Schema element being validated. Must not be null.</param> /// <param name="type">Resolved type (from declaration on the element). Possibly null.</param> internal static void ValidateRefType(SchemaElement element, SchemaType type) { Debug.Assert(element != null); if (type != null && !(type is SchemaEntityType)) { // Ref type refers to non entity type. element.AddError(ErrorCode.ReferenceToNonEntityType, EdmSchemaErrorSeverity.Error, Strings.ReferenceToNonEntityType(type.FQName)); } }
internal override SchemaElement Clone(SchemaElement parentElement) { Parameter parameter = new Parameter((Function)parentElement); parameter._collectionKind = _collectionKind; parameter._parameterDirection = _parameterDirection; parameter._type = _type; parameter.Name = this.Name; parameter._typeUsageBuilder = this._typeUsageBuilder; return parameter; }
/// <summary> /// Add a member to the type /// </summary> /// <param name="newMember">the member being added</param> protected void AddMember(SchemaElement newMember) { Debug.Assert(newMember != null, "newMember parameter is null"); if (string.IsNullOrEmpty(newMember.Name)) { // this is an error condition that has already been reported. return; } if (this.Schema.DataModel != SchemaDataModelOption.ProviderDataModel && Utils.CompareNames(newMember.Name, Name) == 0) { newMember.AddError(ErrorCode.BadProperty, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidMemberNameMatchesTypeName(newMember.Name, FQName)); } NamedMembers.Add(newMember, true, Strings.PropertyNameAlreadyDefinedDuplicate); }
/// <summary> /// See if a name is a member in a type or any of its base types /// </summary> /// <param name="name">name to look for</param> /// <param name="definingType">if defined, the type that defines it</param> /// <param name="definingMember">if defined, the member that defines it</param> /// <returns>how name was defined</returns> private HowDefined DefinesMemberName(string name, out StructuredType definingType, out SchemaElement definingMember) { if (NamedMembers.ContainsKey(name)) { definingType = this; definingMember = NamedMembers[name]; return HowDefined.AsMember; } definingMember = NamedMembers.LookUpEquivalentKey(name); Debug.Assert(definingMember == null, "we allow the scenario that members can have same name but different cases"); if (IsTypeHierarchyRoot) { definingType = null; definingMember = null; return HowDefined.NotDefined; } return BaseType.DefinesMemberName(name, out definingType, out definingMember); }
private void DuplicateOrEquivalentMemberNameWhileExtendingEntityContainer(SchemaElement schemaElement, AddErrorKind error) { Debug.Assert(error != AddErrorKind.MissingNameError, "Since entity container members are already resolved, name must never be empty"); Debug.Assert(this.ExtendingEntityContainer != null, "ExtendingEntityContainer must not be null"); if (error != AddErrorKind.Succeeded) { Debug.Assert(error == AddErrorKind.DuplicateNameError, "Error must be duplicate name error"); schemaElement.AddError(ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.DuplicateMemberNameInExtendedEntityContainer( schemaElement.Name, ExtendingEntityContainer.Name, this.Name)); } }
/// <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); }