public static void RegisterTypes(XmlNode root, Configuration options, IList tasks, Hashtable types) { foreach (TaskElement task in tasks) { String xpath = String.Empty; if (task.Element.Equals("entity")) { xpath = "DataTierGenerator/entities/entity"; } else if (task.Element.Equals("enum")) { xpath = "DataTierGenerator/enums/enum"; } else if (task.Element.Equals("collection")) { xpath = "DataTierGenerator/collections/collection"; } if (xpath.Length > 0) { foreach (XmlNode node in root.SelectNodes(xpath)) { foreach (TypeElement type in task.Types) { TypeElement t = new TypeElement(); t.ConcreteType = type.ConcreteType.Replace("{element.Name}", node.Attributes["name"].Value); t.ConvertForCompare = type.ConvertForCompare.Replace("{element.Name}", node.Attributes["name"].Value); t.ConvertFromSqlTypeFormat = type.ConvertFromSqlTypeFormat.Replace("{element.Name}", node.Attributes["name"].Value); t.ConvertToSqlTypeFormat = type.ConvertToSqlTypeFormat.Replace("{element.Name}", node.Attributes["name"].Value); t.Name = type.Name.Replace("{element.Name}", node.Attributes["name"].Value); t.NewInstanceFormat = type.NewInstanceFormat.Replace("{element.Name}", node.Attributes["name"].Value); t.NullInstanceFormat = type.NullInstanceFormat.Replace("{element.Name}", node.Attributes["name"].Value); if (type.Package.Equals("")) { t.Package = options.RootNameSpace + "." + task.Directory.Replace("\\", "."); } else { t.Package = type.Package; } if (!types.Contains(t.Name)) { {} types.Add(t.Name, t); } else { throw new Exception(t.Name + " already registered as type :: \n" + node.OuterXml); } } } } } }
public override void Validate(RootElement root) { // A property should specify either a type or an entity, but not both. // A concrete type should only be declared if a type is declared not if an entity is declared. if (!this.Type.Name.Equals(String.Empty) && !this.EntityType.Name.Equals(String.Empty)) { root.AddValidationMessage(ParserValidationMessage.NewWarning(String.Format("Both a type ({0}) and an entity ({1}) were specified for property ({2})", this.Type.Name, this.entityType.Name, this.Name))); } TypeElement typeElement = root.FindType(this.Type.Name); EntityElement entityType = root.FindEntity(this.EntityType.Name); if (!this.Type.Name.Equals(String.Empty) && typeElement == null) { root.AddValidationMessage(ParserValidationMessage.NewError("Type " + Type.Name + " was not defined")); } else { this.Type = typeElement; } if (this.ConcreteType.Name.Equals(String.Empty)) { this.concreteType = this.Type; } else { TypeElement concreteTypeElement = root.FindType(this.ConcreteType.Name); if (concreteTypeElement == null) { root.AddValidationMessage(ParserValidationMessage.NewError("ConcreteType " + ConcreteType.Name + " was not defined")); } else { this.ConcreteType = concreteTypeElement; } } if (!this.EntityType.Name.Equals(String.Empty) && entityType == null) { root.AddValidationMessage(ParserValidationMessage.NewError("Entity " + EntityType.Name + " was not defined")); } else { this.EntityType = entityType; } if (typeElement == null && entityType == null) { root.AddValidationMessage(ParserValidationMessage.NewError(String.Format("No type or entity was specified for property {0} on entity {1}.", this.Name, this.containingEntity.Name))); } }
private RootElement(XmlNode rootNode) { // Parse entities. foreach (XmlNode node in GetChildNodes(rootNode, ENTITIES, EntityElement.ENTITY)) { entityElements.Add(new EntityElement(node)); } // Parse collections. foreach (XmlNode node in GetChildNodes(rootNode, COLLECTIONS, CollectionElement.COLLECTION)) { collectionElements.Add(new CollectionElement(node)); } // Parse enums. foreach (XmlNode node in GetChildNodes(rootNode, ENUMS, EnumElement.ENUM)) { enumElements.Add(new EnumElement(node)); } // Parse types. foreach (XmlNode node in GetChildNodes(rootNode, TYPES, TypeElement.TYPE)) { TypeElement typeElement = new TypeElement(node); typeElements.Add(typeElement.Name, typeElement); } // Parse SQL types. foreach (XmlNode node in GetChildNodes(rootNode, SQLTYPES, SqlTypeElement.SQLTYPE)) { sqlTypeElements.Add(new SqlTypeElement(node)); } // Parse databases. XmlNode databasesNode = GetChildNodeByName(rootNode, DATABASES); SqlEntityData databaseDefaults = new SqlEntityData(databasesNode, new SqlEntityData()); foreach (XmlNode node in GetChildNodes(rootNode, DATABASES, DatabaseElement.DATABASE)) { databaseElements.Add(new DatabaseElement(node, databaseDefaults)); } // Parse generator. foreach (XmlNode node in GetChildNodes(rootNode, GeneratorElement.GENERATOR)) { generatorElements.Add(new GeneratorElement(node)); } }
/// <summary> /// Parse only method. Parses and adds all entities found in the given node and adds them to the given /// list. /// </summary> /// <param name="node"></param> /// <param name="entityElements"></param> public static void ParseFromXml(XmlNode rootNode) { if (rootNode != null) { RootElement rootElement = new RootElement(); // ConfigElement.ParseFromXml(GetChildNodeByName(rootNode, "config"), rootElement.ConfigElements); ReportExtractionElement.ParseFromXml(GetChildNodeByName(rootNode, "reportextractions"), rootElement.ReportExtractions); EntityElement.ParseFromXml(GetChildNodeByName(rootNode, "entities"), rootElement.EntityElements); CollectionElement.ParseFromXml(GetChildNodeByName(rootNode, "collections"), rootElement.CollectionElements); EnumElement.ParseFromXml(GetChildNodeByName(rootNode, "enums"), rootElement.EnumElements); TypeElement.ParseFromXml(GetChildNodeByName(rootNode, "types"), rootElement.TypeElements); SqlTypeElement.ParseFromXml(GetChildNodeByName(rootNode, "sqltypes"), rootElement.SqlTypeElements); DatabaseElement.ParseFromXml(GetChildNodeByName(rootNode, "databases"), rootElement.DatabaseElements); GeneratorElement.ParseFromXml(GetChildNodeByName(rootNode, "generator"), rootElement.GeneratorElements); } }
public static ArrayList ParseFromXml(Configuration options, XmlNode root, ParserValidationDelegate vd) { ArrayList list = new ArrayList(); XmlNodeList nodes = root.SelectNodes("tasks/task"); foreach (XmlNode node in nodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } TaskElement task = new TaskElement(); task.Name = node.Attributes["name"].Value; task.Element = node.Attributes["element"].Value; task.Template = node.Attributes["template"].Value; task.Directory = node.Attributes["directory"].Value; task.FileNameFormat = node.Attributes["filenameformat"].Value; if (node.Attributes[BACKUP_DIRECTORY] != null) { task.BackupDirectory = node.Attributes["backupdirectory"].Value; } else { task.BackupDirectory = task.Directory; } if (!node.InnerText.Equals(String.Empty)) { task.Description = node.InnerText; } task.Includes = IncludeElement.ParseFromXml(options, node, vd); task.Excludes = ExcludeElement.ParseFromXml(options, node, vd); task.Parameters = ParameterElement.ParseFromXml(options, node, vd); task.Writer = GetAttributeValue(node, WRITER, task.Writer); task.Styler = GetAttributeValue(node, STYLER, task.Styler); TypeElement.ParseFromXml(node, task.Types); list.Add(task); } return(list); }
/// <summary> /// Parse only method. Parses and adds all entities found in the given node and adds them to the given /// list. /// </summary> /// <param name="node"></param> /// <param name="typeElements"></param> public static void ParseFromXml(XmlNode node, IList typeElements) { if (node != null && typeElements != null) { foreach (XmlNode typeNode in node.SelectNodes("type")) { if (typeNode.NodeType.Equals(XmlNodeType.Element)) { TypeElement typeElement = new TypeElement(); typeElement.Name = GetAttributeValue(typeNode, NAME, typeElement.Name); typeElement.ConcreteType = GetAttributeValue(typeNode, CONCRETE_TYPE, typeElement.ConcreteType); typeElement.NewInstanceFormat = GetAttributeValue(typeNode, NEW_INSTANCE_FORMAT, typeElement.NewInstanceFormat); typeElement.Package = GetAttributeValue(typeNode, NAMESPACE, typeElement.Package); typeElement.ConvertToSqlTypeFormat = GetAttributeValue(typeNode, CONVERT_TO_SQLTYPE_FORMAT, typeElement.ConvertToSqlTypeFormat); typeElement.ConvertFromSqlTypeFormat = GetAttributeValue(typeNode, CONVERT_FROM_SQLTYPE_FORMAT, typeElement.ConvertFromSqlTypeFormat); typeElement.NullInstanceFormat = GetAttributeValue(typeNode, NULL_INSTANCE_FORMAT, typeElement.NullInstanceFormat); typeElements.Add(typeElement); } } } }
public static PropertyElement BuildElement(XmlNode node, Hashtable types, Hashtable sqltypes, IPropertyContainer entity, bool isReference, ParserValidationDelegate vd) { PropertyElement field = new PropertyElement(); if (node.Attributes["name"] != null) { field.Name = node.Attributes["name"].Value; } else { vd(ParserValidationArgs.NewError("Property in " + entity.Name + " has no name.")); } if (isReference && field.Name != "*") { PropertyElement refProperty = entity.FindFieldByName(field.Name); if (refProperty == null) { vd(ParserValidationArgs.NewError("Property " + field.Name + " in " + entity.Name + " refers to a property that does not exist.")); } else { field = (PropertyElement)(refProperty.Clone()); } } if (node.Attributes["column"] != null) { if (node.Attributes["column"].Value.Equals("*")) { field.Column.Name = field.Name; } else { field.Column.Name = node.Attributes["column"].Value; } // Column only occurs on entity eement. SqlEntityElement sqlEntity = ((EntityElement)entity).SqlEntity; ColumnElement column = sqlEntity.FindColumnByName(field.Column.Name); if (column != null) { field.Column = (ColumnElement)column.Clone(); if (types.Contains(field.Column.SqlType.Type)) { field.Type = (TypeElement)((TypeElement)types[field.Column.SqlType.Type]).Clone(); } else { vd(ParserValidationArgs.NewError("Type " + field.Column.SqlType.Type + " was not defined [property=" + field.name + "]")); } } else { vd(ParserValidationArgs.NewError("column (" + field.Column.Name + ") specified for property (" + field.Name + ") on entity (" + entity.Name + ") was not found in sql entity (" + sqlEntity.Name + ")")); } } field.Description = node.InnerText.Trim(); if (node.Attributes["accessmodifier"] != null) { field.AccessModifier = node.Attributes["accessmodifier"].Value; } // the concrete type is the *real* type, type can be the same or can be in interface or coersable type if (node.Attributes["type"] != null) { String type = node.Attributes[TYPE].Value; String concreteType = type; if (node.Attributes[CONCRETE_TYPE] != null) { concreteType = node.Attributes[CONCRETE_TYPE].Value; } // if the data type is defined, default it as the property and left be overridden if (types.Contains(concreteType)) { field.Type = (TypeElement)((TypeElement)types[concreteType]).Clone(); field.Type.Name = type; } else { vd(ParserValidationArgs.NewError("Type " + concreteType + " was not defined for property " + field.Name + " in " + entity.Name + ".")); } String dataObjectTypeName = concreteType + "Data"; if (types.Contains(dataObjectTypeName)) { field.DataObjectType = (TypeElement)((TypeElement)types[dataObjectTypeName]).Clone(); } else { field.DataObjectType = field.Type; } } if (node.Attributes["convertfromsqltypeformat"] != null) { field.Type.ConvertFromSqlTypeFormat = node.Attributes["convertfromsqltypeformat"].Value; } if (node.Attributes["converttosqltypeformat"] != null) { field.Type.ConvertToSqlTypeFormat = node.Attributes["converttosqltypeformat"].Value; } if (node.Attributes[PARAMETER_NAME] != null) { field.ParameterName = node.Attributes[PARAMETER_NAME].Value; } if (node.Attributes[EXPRESSION] != null) { field.Expression = node.Attributes[EXPRESSION].Value; } if (node.Attributes[GROUP_FUNCTION] != null) { field.GroupFunction = node.Attributes[GROUP_FUNCTION].Value; if (field.GroupFunction.ToLower() != GROUP_FUNCTION_SUM && field.GroupFunction.ToLower() != GROUP_FUNCTION_MIN && field.GroupFunction.ToLower() != GROUP_FUNCTION_MAX && field.GroupFunction.ToLower() != GROUP_FUNCTION_AVG && field.GroupFunction.ToLower() != GROUP_FUNCTION_STDEV && field.GroupFunction.ToLower() != GROUP_FUNCTION_STDEVP && field.GroupFunction.ToLower() != GROUP_FUNCTION_VAR && field.GroupFunction.ToLower() != GROUP_FUNCTION_VARP) { vd(ParserValidationArgs.NewError("Invalid group function specified for entity reference property " + field.Name + " in " + entity.Name)); } } if (node.Attributes[GROUP_BY] != null) { field.GroupBy = Boolean.Parse(node.Attributes[GROUP_BY].Value); } if (node.Attributes[SQL_TYPE] != null) { field.Column.SqlType.Name = node.Attributes[SQL_TYPE].Value; if (sqltypes.ContainsKey(field.Column.SqlType.Name)) { field.Column.SqlType = (SqlTypeElement)((SqlTypeElement)sqltypes[field.Column.SqlType.Name]).Clone(); } else { vd(ParserValidationArgs.NewError("SqlType " + field.Column.SqlType.Name + " was not defined in " + entity.Name + " for property " + field.Name + ".")); } } if (node.Attributes[ALIAS] != null) { field.Alias = node.Attributes[ALIAS].Value; } field.container = entity; if (node.Attributes["readable"] != null) { field.Readable = Boolean.Parse(node.Attributes["readable"].Value); } if (node.Attributes["writable"] != null) { field.Writable = Boolean.Parse(node.Attributes["writable"].Value); } if (node.Attributes["derived"] != null) { field.Derived = Boolean.Parse(node.Attributes["derived"].Value); } if (node.Attributes["encrypted"] != null) { field.Encrypted = Boolean.Parse(node.Attributes["encrypted"].Value); } if (node.Attributes["log"] != null) { field.DoLog = Boolean.Parse(node.Attributes["log"].Value); } if (node.Attributes["returnasidentity"] != null) { field.ReturnAsIdentity = Boolean.Parse(node.Attributes["returnasidentity"].Value); } if (node.Attributes[DIRECTION] == null) { field.Direction = ASCENDING; } else if (node.Attributes["direction"].Value != ASCENDING && node.Attributes["direction"].Value != DESCENDING) { vd(ParserValidationArgs.NewError("Comparer in entity " + entity.Name + " has direction value other than 'ascending' or 'descending'")); } else { field.Direction = node.Attributes[DIRECTION].Value; } if (node.Attributes[CONVERT_FOR_COMPARE] != null) { field.Type.ConvertForCompare = node.Attributes[CONVERT_FOR_COMPARE].Value; } if (node.Attributes[USE_ENTITY_DAO] != null) { field.UseEntityDao = Boolean.Parse(node.Attributes[USE_ENTITY_DAO].Value); } if (node.Attributes["entity"] != null) { field.Entity.Name = node.Attributes["entity"].Value; } if (node.Attributes["prefix"] != null) { field.Prefix = node.Attributes["prefix"].Value; } else { field.Prefix = field.Entity.Name + "_"; } return(field); }
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); }
/// <summary> /// Sets up type collection and does anything else that is needed for the /// validation step. /// </summary> private void PreValidate() { // Add types to the type collection. foreach (EntityElement elem in entityElements) { if (!typeElements.Contains(elem.Name + "Data")) { TypeElement type = new TypeElement(); type.Name = elem.Name + "Data"; type.Package = Configuration.GetDONameSpace(""); type.NewInstanceFormat = "new " + type.Name + "()"; typeElements.Add(type.Name, type); } // TODO: needs review, hacked for Dave // add interfaces - use new x() for empty instance constructor if (!typeElements.Contains("I" + elem.Name)) { TypeElement type = new TypeElement(); type.Name = "I" + elem.Name; type.ConcreteType = type.Name; type.Package = Configuration.GetDONameSpace(""); type.NewInstanceFormat = "new " + elem.Name + "()"; typeElements.Add(type.Name, type); } // TODO: needs review, hacked for Dave // add business entities - use new x() for empty instance constructor if (!typeElements.Contains(elem.Name)) { TypeElement type = new TypeElement(); type.Name = elem.Name; type.ConcreteType = type.Name; type.Package = Configuration.GetBusinessLogicNameSpace(); type.NewInstanceFormat = "new " + type.Name + "()"; typeElements.Add(type.Name, type); } } // Add enums to types if not already defined. foreach (EnumElement elem in enumElements) { if (!typeElements.Contains(elem.Name)) { TypeElement type = new TypeElement(); type.Name = elem.Name; type.ConcreteType = type.Name; type.Package = Configuration.GetTypeNameSpace(""); type.ConvertToSqlTypeFormat = "{1}.DBValue"; type.ConvertFromSqlTypeFormat = type.Name + ".GetInstance({2})"; type.NewInstanceFormat = type.Name + ".DEFAULT"; type.NullInstanceFormat = type.Name + ".UNSET"; typeElements.Add(type.Name, type); } } // Add collections as data objects to types if not already defined. foreach (CollectionElement elem in collectionElements) { if (!typeElements.Contains(elem.Name)) { TypeElement type = new TypeElement(); type.Name = elem.Name; type.ConcreteType = type.Name; type.Package = Configuration.GetDONameSpace(""); //type.NewInstanceFormat = "new " + type.Name + "()"; type.NewInstanceFormat = type.Name + ".DEFAULT"; type.NullInstanceFormat = type.Name + ".UNSET"; typeElements.Add(type.Name, type); } } }