Exemple #1
0
        public void Parse(String filename)
        {
            FileInfo file = new FileInfo(filename);

            if (!file.Exists)
            {
                throw new FileNotFoundException("Could not load config file", filename);
            }
            isValid = true;
            ValidateSchema(filename);

            doc = new XmlDocument();
            Stream filestream = XIncludeReader.GetStream(filename);

            doc.Load(filestream);
            filestream.Close();

            if (doc == null)
            {
                throw new InvalidOperationException("Could not parse xml document: " + filename);
            }

            // event handler for all of the ParseFromXml methods
            ParserValidationDelegate vd = new ParserValidationDelegate(ParserValidationEventHandler);

            XmlNode root = doc.DocumentElement["config"];

            if (root != null)
            {
                this.options = new Configuration(root, vd);
            }
            else
            {
                this.options = new Configuration();
            }

            sqltypes = SqlTypeElement.ParseFromXml(doc, vd);
            types    = TypeElement.ParseFromXml(options, doc, vd);

            // parse generate/task information so that type registration will happen before other types are loaded
            generator = GeneratorElement.ParseFromXml(options, doc, vd);
            TaskElement.RegisterTypes(doc, options, generator.Tasks, types);

            // see if we want to generate collections for all entities
            XmlNodeList collectionElement = doc.DocumentElement.GetElementsByTagName("collections");
            XmlNode     collectionNode    = collectionElement[0];

            if (collectionNode.Attributes["generateall"] == null)
            {
                options.GenerateAllCollections = false;
            }
            else
            {
                options.GenerateAllCollections = Boolean.Parse(collectionNode.Attributes["generateall"].Value.ToString());
            }

            // if the root directory is not specified, make it the directory the config file is loaded from
            if (options.RootDirectory.Equals(String.Empty))
            {
                options.RootDirectory = file.DirectoryName + "\\";
            }
            if (!options.RootDirectory.EndsWith("\\"))
            {
                options.RootDirectory += "\\";
            }

            enumtypes         = EnumElement.ParseFromXml(options, doc, sqltypes, types, vd);
            databases         = DatabaseElement.ParseFromXml(options, doc, sqltypes, types, vd);
            entities          = EntityElement.ParseFromXml(options, doc, sqltypes, types, DatabaseElement.GetAllSqlEntities(databases), vd);
            messages          = MessageElement.ParseFromXml(options, doc, sqltypes, types, DatabaseElement.GetAllSqlEntities(databases), vd);
            reportExtractions = ReportExtractionElement.ParseFromXml(options, doc, sqltypes, types, entities, vd);
            ArrayList collectableClasses  = new ArrayList();
            ArrayList autoGenerateClasses = new ArrayList();

            collectableClasses.AddRange(entities);
            collectableClasses.AddRange(reportExtractions);
            autoGenerateClasses.AddRange(entities);
            autoGenerateClasses.AddRange(reportExtractions);
            collections = CollectionElement.ParseFromXml(options, doc, sqltypes, types, vd, collectableClasses, autoGenerateClasses, (ArrayList)entities);

            CreateSqlElementAssociations(vd);
            CreateEntityElementAssociations(vd);
            Validate(vd);
        }
Exemple #2
0
        public ConfigParser(String filename)
        {
            FileInfo file = new FileInfo(filename);

            if (!file.Exists)
            {
                throw new FileNotFoundException("Could not load config file", filename);
            }
            isValid = true;
            ValidateSchema(filename);

            doc = new XmlDocument();
            Stream filestream = XIncludeReader.GetStream(filename);

            doc.Load(filestream);
            filestream.Close();

            if (doc == null)
            {
                throw new InvalidOperationException("Could not parse xml document: " + filename);
            }

            // event handler for all of the ParseFromXml methods
            ParserValidationDelegate vd = new ParserValidationDelegate(ParserValidationEventHandler);

            XmlNode root = doc.DocumentElement["config"];

            if (root != null)
            {
                this.options = new Configuration(root, vd);
            }
            else
            {
                this.options = new Configuration();
            }

            // If the root directory is not specified, make it the directory the config file is loaded from.
            if (options.RootDirectory.Equals(String.Empty))
            {
                options.RootDirectory = file.DirectoryName + "\\";
            }
            if (!options.RootDirectory.EndsWith("\\"))
            {
                options.RootDirectory += "\\";
            }

            parser    = ParserElement.ParseFromXml(options, doc, vd);
            generator = GeneratorElement.ParseFromXml(options, doc, vd);
            sqltypes  = SqlTypeElement.ParseFromXml(doc, vd);
            types     = TypeElement.ParseFromXml(options, doc, vd);

            if (parser.Class.Equals(String.Empty))
            {
                enumtypes   = EnumElement.ParseFromXml(options, doc, sqltypes, types, vd);
                databases   = DatabaseElement.ParseFromXml(options, doc, sqltypes, types, vd);
                entities    = EntityElement.ParseFromXml(options, doc, sqltypes, types, DatabaseElement.GetAllSqlEntities(databases), vd);
                collections = CollectionElement.ParseFromXml(options, doc, sqltypes, types, vd, (ArrayList)entities);
            }
            else
            {
                Object o = null;
                try {
                    System.Type clazz = System.Type.GetType(parser.Class, true);
                    Object[]    args  = { parser, options, doc, sqltypes, types, vd };
                    o = System.Activator.CreateInstance(clazz, args);
                } catch (Exception ex) {
                    Console.Out.WriteLine("ERROR: could not create class " + parser.Class + ".\n" + ex.ToString());
                }

                if (o is IParser)
                {
                    IParser p = (IParser)o;
                    enumtypes   = (ArrayList)p.Enums;
                    collections = (ArrayList)p.Collections;
                    databases   = (ArrayList)p.Databases;
                    entities    = (ArrayList)p.Entities;
                }
                else
                {
                    Console.Out.WriteLine("ERROR: class " + parser.Class + " does not support IParser interface.\n");
                }
            }

            Validate(vd);
        }