public static Hashtable ParseFromXml(XmlDocument doc, ParserValidationDelegate vd) { Hashtable sqltypes = new Hashtable(); XmlNodeList elements = doc.DocumentElement.GetElementsByTagName("sqltype"); foreach (XmlNode node in elements) { if (node.NodeType == XmlNodeType.Comment) { continue; } SqlTypeElement sqltype = new SqlTypeElement(); sqltype.Name = node.Attributes["name"].Value; sqltype.SqlDbType = sqltype.Name.Substring(0, 1).ToUpper() + sqltype.Name.Substring(1); if (node.Attributes["type"] != null) { sqltype.Type = node.Attributes["type"].Value; } if (node.Attributes["length"] != null) { sqltype.Length = Int32.Parse(node.Attributes["length"].Value); } if (node.Attributes["scale"] != null) { sqltype.Scale = Int32.Parse(node.Attributes["scale"].Value); } if (node.Attributes["precision"] != null) { sqltype.Precision = Int32.Parse(node.Attributes["precision"].Value); } if (node.Attributes["readermethodformat"] != null) { sqltype.ReaderMethodFormat = node.Attributes["readermethodformat"].Value; } if (node.Attributes["sqldbtype"] != null) { sqltype.SqlDbType = node.Attributes["sqldbtype"].Value; } if (node.Attributes["dbtype"] != null) { sqltype.DbType = node.Attributes["dbtype"].Value; } if (node.Attributes["declarationformat"] != null) { sqltype.DeclarationFormat = node.Attributes["declarationformat"].Value; } if (sqltypes.ContainsKey(sqltype.Name)) { vd(ParserValidationArgs.NewWarning("Ignoring duplicate definition of sqltype: " + sqltype.Name)); } else { sqltypes.Add(sqltype.Name, sqltype); } } return(sqltypes); }
public Configuration(XmlNode root, ParserValidationDelegate vd) { if (root.HasChildNodes) { for (Int32 i = 0; i < root.ChildNodes.Count; i++) { XmlNode node = root.ChildNodes[i]; if (node.Name.Equals("setting")) { switch (node.Attributes["name"].Value.ToLower()) { case "rootnamespace": this.rootNameSpace = node.Attributes["value"].Value; break; case "rootdirectory": this.rootDirectory = node.Attributes["value"].Value; break; case "typesclassdirectory": this.typesClassDirectory = node.Attributes["value"].Value; break; case "daoclassdirectory": this.daoClassDirectory = node.Attributes["value"].Value; break; case "doclassdirectory": this.doClassDirectory = node.Attributes["value"].Value; break; case "collectionclassdirectory": this.collectionClassDirectory = node.Attributes["value"].Value; break; case "generatedataobjectclasses": this.generateDataObjectClasses = Boolean.Parse(node.Attributes["value"].Value); break; case "dataobjectbaseclass": this.dataObjectBaseClass = node.Attributes["value"].Value; break; case "daobaseclass": this.daoBaseClass = node.Attributes["value"].Value; break; case "enumbaseclass": this.enumBaseClass = node.Attributes["value"].Value; break; case "testclassdirectory": this.testClassDirectory = node.Attributes["value"].Value; break; default: vd(ParserValidationArgs.NewWarning("Unrecognized configuration option: " + node.Attributes["name"].Value + " = " + node.Attributes["value"].Value)); break; } } } } }
public static Hashtable ParseFromXml(Configuration options, XmlNode doc, ParserValidationDelegate vd) { Hashtable types = new Hashtable(); XmlNodeList nodes = doc.SelectNodes("DataTierGenerator/types/type"); foreach (XmlNode node in nodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } TypeElement type = new TypeElement(); type.Name = node.Attributes["name"].Value; type.ConcreteType = type.Name; if (node.Attributes["concretetype"] != null) { type.ConcreteType = node.Attributes["concretetype"].Value; } if (node.Attributes["namespace"] != null) { type.Package = node.Attributes["namespace"].Value; } if (node.Attributes["newinstanceformat"] != null) { type.NewInstanceFormat = node.Attributes["newinstanceformat"].Value; type.NullInstanceFormat = type.NewInstanceFormat; } if (node.Attributes["nullinstanceformat"] != null) { type.NullInstanceFormat = node.Attributes["nullinstanceformat"].Value; } if (node.Attributes["converttosqltypeformat"] != null) { type.ConvertToSqlTypeFormat = node.Attributes["converttosqltypeformat"].Value; } if (node.Attributes["convertfromsqltypeformat"] != null) { type.ConvertFromSqlTypeFormat = node.Attributes["convertfromsqltypeformat"].Value; } if (node.Attributes[CONVERT_FOR_COMPARE] != null) { type.ConvertForCompare = node.Attributes[CONVERT_FOR_COMPARE].Value; } if (types.ContainsKey(type.Name)) { vd(ParserValidationArgs.NewWarning("ignoring duplicate definition of type: " + type.Name)); } else { types.Add(type.Name, type); } } // // add entities as data objects to types if not already defined // elements = doc.DocumentElement.GetElementsByTagName("entity"); // foreach (XmlNode node in elements) { // if (node.NodeType == XmlNodeType.Comment) { // continue; // } // if (!types.Contains(node.Attributes["name"].Value + "Data")) { // TypeElement type = new TypeElement(); // type.Name = node.Attributes["name"].Value + "Data"; // type.ConcreteType = type.Name; // type.Package = options.GetDONameSpace(""); // type.NewInstanceFormat = "new " + type.Name + "()"; // types.Add(type.Name, type); // } // // // TODO: needs review, hacked for Dave // // add interfaces - use new x() for empty instance constructor // if (!types.Contains("I" + node.Attributes["name"].Value)) { // TypeElement type = new TypeElement(); // type.Name = "I" + node.Attributes["name"].Value; // type.ConcreteType = type.Name; // type.Package = options.GetDONameSpace(""); // type.NewInstanceFormat = "new " + node.Attributes["name"].Value + "()"; // types.Add(type.Name, type); // } // // // TODO: needs review, hacked for Dave // // add business entities - use new x() for empty instance constructor // if (!types.Contains(node.Attributes["name"].Value)) { // TypeElement type = new TypeElement(); // type.Name = node.Attributes["name"].Value; // type.ConcreteType = type.Name; // type.Package = options.GetBusinessLogicNameSpace(); // type.NewInstanceFormat = "new " + type.Name + "()"; // types.Add(type.Name, type); // } // } // // // // add enums to types if not already defined // elements = doc.DocumentElement.GetElementsByTagName("enum"); // foreach (XmlNode node in elements) { // if (node.NodeType == XmlNodeType.Comment) { // continue; // } // if (!types.Contains(node.Attributes["name"].Value)) { // TypeElement type = new TypeElement(); // type.Name = node.Attributes["name"].Value; // type.ConcreteType = type.Name; // type.Package = options.GetTypeNameSpace(""); // type.ConvertToSqlTypeFormat = "{1}.DBValue"; // type.ConvertFromSqlTypeFormat = type.Name + ".GetInstance({2})"; // type.NewInstanceFormat = type.Name + ".DEFAULT"; // type.NullInstanceFormat = type.Name + ".UNSET"; // types.Add(type.Name, type); // } // } // // // see if we want to generate collections for all entities // XmlNodeList collectionElement = doc.DocumentElement.GetElementsByTagName ("collections"); // XmlNode collectionNode = collectionElement[0]; // Boolean generateAll = false; // if (collectionNode.Attributes["generateall"] != null) { // generateAll = Boolean.Parse (collectionNode.Attributes["generateall"].Value.ToString ()); // } // // if (generateAll) { // // add collections for all entities as data objects to types if not already defined // elements = doc.DocumentElement.GetElementsByTagName ("entity"); // foreach (XmlNode node in elements) { // if (node.NodeType == XmlNodeType.Comment) { // continue; // } // if (!types.Contains (node.Attributes["name"].Value + "List")) { // TypeElement type = new TypeElement (); // type.Name = node.Attributes["name"].Value + "List"; // type.ConcreteType = type.Name; // type.Package = options.GetDONameSpace (""); // type.NewInstanceFormat = type.Name + ".DEFAULT"; // type.NullInstanceFormat = type.Name + ".UNSET"; // types.Add (type.Name, type); // } // } // } else { // // add collections as data objects to types if not already defined // elements = doc.DocumentElement.GetElementsByTagName("collection"); // foreach (XmlNode node in elements) { // if (node.NodeType == XmlNodeType.Comment) { // continue; // } // if (!types.Contains(node.Attributes["name"].Value)) { // TypeElement type = new TypeElement(); // type.Name = node.Attributes["name"].Value; // type.ConcreteType = type.Name; // type.Package = options.GetDONameSpace(""); // //type.NewInstanceFormat = "new " + type.Name + "()"; // type.NewInstanceFormat = type.Name + ".DEFAULT"; // type.NullInstanceFormat = type.Name + ".UNSET"; // types.Add(type.Name, type); // } // } // } return(types); }