コード例 #1
0
ファイル: Schema.cs プロジェクト: ItsVeryWindy/mono
 public Schema(SchemaManager schemaManager)
     : base(null)
 {
     Debug.Assert(schemaManager != null, "SchemaManager parameter should never be null");
     _schemaManager = schemaManager;
     _errors = new List<EdmSchemaError>();
 }
コード例 #2
0
        public PrimitiveSchema(SchemaManager schemaManager)
            : base(schemaManager)
        {
            Schema = this;

            DbProviderManifest providerManifest = ProviderManifest;
            if (providerManifest == null)
            {
                AddError(new EdmSchemaError(System.Data.Entity.Strings.FailedToRetrieveProviderManifest,
                                                   (int)ErrorCode.FailedToRetrieveProviderManifest,
                                                   EdmSchemaErrorSeverity.Error));
            }
            else
            {
                IList<PrimitiveType> primitiveTypes = providerManifest.GetStoreTypes();

                // EDM Spatial types are only available to V3 and above CSDL.
                if (schemaManager.DataModel == SchemaDataModelOption.EntityDataModel &&
                    schemaManager.SchemaVersion < XmlConstants.EdmVersionForV3)
                {
                    primitiveTypes = primitiveTypes.Where(t => !Helper.IsSpatialType(t))
                                                   .ToList();
                }

                foreach (PrimitiveType entry in primitiveTypes)
                {
                    TryAddType(new ScalarType(this, entry.Name, entry), false /*doNotAddErrorForEmptyName*/);
                }
            }
        }
コード例 #3
0
        public static IList <EdmSchemaError> ParseAndValidate(IEnumerable <XmlReader> xmlReaders,
                                                              IEnumerable <string> sourceFilePaths, SchemaDataModelOption dataModel,
                                                              AttributeValueNotification providerNotification,
                                                              AttributeValueNotification providerManifestTokenNotification,
                                                              ProviderManifestNeeded providerManifestNeeded,
                                                              out IList <Schema> schemaCollection)
        {
            SchemaManager schemaManager   = new SchemaManager(dataModel, providerNotification, providerManifestTokenNotification, providerManifestNeeded);
            var           errorCollection = new List <EdmSchemaError>();

            schemaCollection = new List <Schema>();
            bool errorEncountered = false;

            List <string> filePathList;

            if (sourceFilePaths != null)
            {
                filePathList = new List <string>(sourceFilePaths);
            }
            else
            {
                filePathList = new List <string>();
            }

            int index = 0;

            foreach (XmlReader xmlReader in xmlReaders)
            {
                string location = null;
                if (filePathList.Count <= index)
                {
                    TryGetBaseUri(xmlReader, out location);
                }
                else
                {
                    location = filePathList[index];
                }

                Schema schema;
                schema = new Schema(schemaManager);

                var errorsForCurrentSchema = schema.Parse(xmlReader, location);

                CheckIsSameVersion(schema, schemaCollection, errorCollection);

                // If the number of errors exceeded the max error count, then return
                if (UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, errorsForCurrentSchema, ref errorEncountered))
                {
                    return(errorCollection);
                }

                // Add the schema to the collection if there are no errors. There are errors in which schema do not have any namespace.
                // Also if there is an error encountered in one of the schema, we do not need to add the remaining schemas since
                // we will never go to the resolve phase.
                if (!errorEncountered)
                {
                    schemaCollection.Add(schema);
                    schemaManager.AddSchema(schema);
                    var currentSchemaVersion = schema.SchemaVersion;
                    Debug.Assert(schemaCollection.All(s => s.SchemaVersion == currentSchemaVersion || s.SchemaVersion != XmlConstants.UndefinedVersion));
                }
                index++;
            }

            // If there are no errors encountered in the parsing stage, we can proceed to the
            // parsing and validating phase
            if (!errorEncountered)
            {
                foreach (Schema schema in schemaCollection)
                {
                    if (UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, schema.Resolve(), ref errorEncountered))
                    {
                        return(errorCollection);
                    }
                }

                // If there are no errors encountered in the parsing stage, we can proceed to the
                // parsing and validating phase
                if (!errorEncountered)
                {
                    foreach (Schema schema in schemaCollection)
                    {
                        if (UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, schema.ValidateSchema(), ref errorEncountered))
                        {
                            return(errorCollection);
                        }
                    }
                }
            }

            return(errorCollection);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        public static IList<EdmSchemaError> ParseAndValidate(IEnumerable<XmlReader> xmlReaders,
            IEnumerable<string> sourceFilePaths, SchemaDataModelOption dataModel,
            AttributeValueNotification providerNotification,
            AttributeValueNotification providerManifestTokenNotification,
            ProviderManifestNeeded providerManifestNeeded,
            out IList<Schema> schemaCollection)
        {
            SchemaManager schemaManager = new SchemaManager(dataModel, providerNotification, providerManifestTokenNotification, providerManifestNeeded);
            var errorCollection = new List<EdmSchemaError>();
            schemaCollection = new List<Schema>();
            bool errorEncountered = false;

            List<string> filePathList;
            if (sourceFilePaths != null)
            {
                filePathList = new List<string>(sourceFilePaths);
            }
            else
            {
                filePathList = new List<string>();
            }

            int index = 0;
            foreach (XmlReader xmlReader in xmlReaders)
            {
                string location = null;
                if (filePathList.Count <= index)
                {
                    TryGetBaseUri(xmlReader, out location);
                }
                else
                {
                    location = filePathList[index];
                }

                Schema schema;
                schema = new Schema(schemaManager);

                var errorsForCurrentSchema = schema.Parse(xmlReader, location);

                CheckIsSameVersion(schema, schemaCollection, errorCollection);
                
                // If the number of errors exceeded the max error count, then return
                if (UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, errorsForCurrentSchema, ref errorEncountered))
                {
                    return errorCollection;
                }

                // Add the schema to the collection if there are no errors. There are errors in which schema do not have any namespace.
                // Also if there is an error encountered in one of the schema, we do not need to add the remaining schemas since
                // we will never go to the resolve phase.
                if (!errorEncountered)
                {
                    schemaCollection.Add(schema);
                    schemaManager.AddSchema(schema);
                    var currentSchemaVersion = schema.SchemaVersion;
                    Debug.Assert(schemaCollection.All(s => s.SchemaVersion == currentSchemaVersion || s.SchemaVersion != XmlConstants.UndefinedVersion));
                }
                index++;
            }

            // If there are no errors encountered in the parsing stage, we can proceed to the 
            // parsing and validating phase
            if (!errorEncountered)
            {
                foreach (Schema schema in schemaCollection)
                {
                    if (UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, schema.Resolve(), ref errorEncountered))
                    {
                        return errorCollection;
                    }
                }

                // If there are no errors encountered in the parsing stage, we can proceed to the 
                // parsing and validating phase
                if (!errorEncountered)
                {
                    foreach (Schema schema in schemaCollection)
                    {
                        if (UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, schema.ValidateSchema(), ref errorEncountered))
                        {
                            return errorCollection;
                        }
                    }
                }
            }
            
            return errorCollection;
        }