public static ArrayList ParseFromXml(XmlNode propertiesNode, IList entities, IPropertyContainer entity, Hashtable sqltypes, Hashtable types, bool isReference, ParserValidationDelegate vd) { ArrayList fields = new ArrayList(); if (propertiesNode != null) { foreach (XmlNode node in propertiesNode.ChildNodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } PropertyElement field = BuildElement(node, types, sqltypes, entity, isReference, vd); //Adds all attributes including all non defined by element class foreach (XmlAttribute attribute in node.Attributes) { if (!field.Attributes.ContainsKey(attribute.Name)) { field.Attributes.Add(attribute.Name, attribute.Value); } } fields.Add(field); // Add in any subfields... if (field.Entity.Name.Length > 0 && !field.UseEntityDao) { String subEntityName = node.Attributes["entity"].Value; EntityElement subentity = EntityElement.FindEntityByName((ArrayList)entities, subEntityName); // check to see if subentity is self if (subentity == null && entity.Name == subEntityName) { subentity = (EntityElement)entity; } if (subentity != null) { // Only entity elements have entity atttribute SqlEntityElement sqlEntity = ((EntityElement)entity).SqlEntity; String prefix = subentity.Name + "_"; if (node.Attributes["prefix"] != null) { prefix = node.Attributes["prefix"].Value; } foreach (PropertyElement f in subentity.Fields) { PropertyElement subfield = (PropertyElement)f.Clone(); subfield.Name = field.Name + "." + subfield.Name; // if field has sql column defined if (!f.Column.Name.Equals(String.Empty)) { ColumnElement column = sqlEntity.FindColumnByName(prefix + subfield.Column.Name); if (column != null) { subfield.Column = (ColumnElement)column.Clone(); } else { vd(ParserValidationArgs.NewError("column (" + prefix + subfield.Column.Name + ") specified for property (" + subfield.Name + ") on entity (" + entity.Name + ") was not found in sql entity (" + sqlEntity.Name + ")")); } } fields.Add(subfield); } } else { vd(ParserValidationArgs.NewError("Entity " + entity.Name + " referenced another entity that was not defined (or defined below this one): " + node.Attributes["entity"].Value)); } } } } return(fields); }
/// <summary> /// Second pass parsing and validation. /// </summary> /// <param name="options">Configuration options</param> /// <param name="reportExtractionNode">Node contaiing the entity references.</param> /// <param name="reportExtraction">ReportExtraction element to contain the parsed entity references.</param> /// <param name="types">List of .Net types defined.</param> /// <param name="entities">List of entities defined.</param> /// <param name="vd">Validation delegate for error reporting.</param> /// <returns>List of entity references parsed.</returns> public static ArrayList ParseFromXml(Configuration options, XmlNode reportExtractionNode, ReportExtractionElement reportExtraction, Hashtable types, Hashtable sqltypes, IList entities, ParserValidationDelegate vd) { ArrayList entityReferences = new ArrayList(); foreach (XmlNode node in reportExtractionNode.ChildNodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } EntityReferenceElement entityReference = new EntityReferenceElement(reportExtraction); if (entityReference.Name != null) { entityReference.Name = node.Attributes[NAME].Value; } else { vd(ParserValidationArgs.NewError("Entity reference specified in report extraction " + reportExtraction.Name + " with no name.")); } if (node.Attributes[ENTITY] != null) { EntityElement ee = EntityElement.FindEntityByName(entities, node.Attributes[ENTITY].Value); if (ee != null) { entityReference.Entity = ee; if (entityReference.Entity.SqlEntity.Name == String.Empty) { vd(ParserValidationArgs.NewError("Entity Reference " + entityReference.Name + " refers to entity " + node.Attributes[ENTITY].Value + " which does not have an associated SQL entity.")); } } else { vd(ParserValidationArgs.NewError("Entity Reference " + entityReference.Name + " refers to entity " + node.Attributes[ENTITY].Value + " which does not exist.")); } } else { vd(ParserValidationArgs.NewError("Entity Reference " + node.Attributes[NAME].Value + " has no entity attribute.")); } if (node.Attributes[ALIAS_PREFIX] != null) { entityReference.aliasPrefix = node.Attributes[ALIAS_PREFIX].Value; } if (node.Attributes[HINTS] != null) { entityReference.Hints = node.Attributes[HINTS].Value; } if (node.Attributes[FILTER] != null) { entityReference.Filter = node.Attributes[FILTER].Value; } if (node.Attributes[JOIN_MODIFIER] != null) { entityReference.JoinModifier = node.Attributes[JOIN_MODIFIER].Value; if (entityReference.JoinModifier.ToUpper() != JOIN_LEFT && entityReference.JoinModifier.ToUpper() != JOIN_RIGHT && entityReference.JoinModifier.ToUpper() != JOIN_FULL) { vd(ParserValidationArgs.NewError("Entity Reference " + node.Attributes[NAME].Value + " has join modifier other than left, right or full.")); } } entityReference.ReportExtraction = reportExtraction; // Note we pass entityReference.Entity because the fields refer to fields in the entity. entityReference.propertyReferences = PropertyElement.ParseFromXml(GetChildNodeByName(node, PROPERTY_REFERENCES), entities, entityReference.Entity, sqltypes, types, true, vd); entityReference.ProcessAsteriskName(vd); entityReference.AdjustSqlAlias(); entityReferences.Add(entityReference); } return(entityReferences); }
public static ArrayList ParseFromXml(Configuration options, XmlDocument doc, Hashtable sqltypes, Hashtable types, ArrayList sqlentities, ParserValidationDelegate vd) { ArrayList entities = new ArrayList(); XmlNode entitiesNode = doc.DocumentElement.Cast <XmlNode>().FirstOrDefault(x => x.Name.ToLowerInvariant() == "entities"); if (entitiesNode == null) { return(entities); } IEnumerable <XmlNode> elements = entitiesNode.ChildNodes.Cast <XmlNode>().Where(x => x.Name.ToLowerInvariant() == "entity"); foreach (XmlNode node in elements) { if (node.NodeType == XmlNodeType.Comment) { continue; } EntityElement entity = new EntityElement(); entity.Name = node.Attributes["name"].Value; if (node.Attributes["namespace"] != null) { entity.Namespace = node.Attributes["namespace"].Value; } if (node.Attributes["sqlentity"] != null) { SqlEntityElement sqlentity = SqlEntityElement.FindByName(sqlentities, node.Attributes["sqlentity"].Value); if (sqlentity != null) { entity.SqlEntity = (SqlEntityElement)sqlentity.Clone(); } else { entity.SqlEntity.Name = node.Attributes["sqlentity"].Value; vd(ParserValidationArgs.NewError("sqlentity (" + entity.SqlEntity.Name + ") specified in entity " + entity.Name + " could not be found as an defined sql entity")); } } if (node.Attributes["baseentity"] != null) { EntityElement baseentity = EntityElement.FindEntityByName(entities, node.Attributes["baseentity"].Value); if (baseentity != null) { entity.BaseEntity = (EntityElement)baseentity.Clone(); } else { entity.BaseEntity.Name = node.Attributes["baseentity"].Value; vd(ParserValidationArgs.NewError("baseentity (" + entity.BaseEntity.Name + ") specified in entity " + entity.Name + " could not be found as an defined entity (or is defined after this entity in the config file)")); } } if (node.Attributes["abstract"] != null) { entity.IsAbstract = Boolean.Parse(node.Attributes["abstract"].Value); } if (node.Attributes["namespace"] != null) { entity.HasNamespace = !String.IsNullOrEmpty(node.Attributes["namespace"].Value); } if (node.Attributes["log"] != null) { entity.DoLog = Boolean.Parse(node.Attributes["log"].Value); } if (node.Attributes["returnwholeobject"] != null) { entity.ReturnWholeObject = Boolean.Parse(node.Attributes["returnwholeobject"].Value); } if (node.Attributes["prepareforinsert"] != null) { entity.PrepareForInsert = Boolean.Parse(node.Attributes["prepareforinsert"].Value); } if (node.Attributes["dependententity"] != null) { entity.DependentEntity = Boolean.Parse(node.Attributes["dependententity"].Value); } if (node.Attributes["jointable"] != null) { entity.JoinTable = Boolean.Parse(node.Attributes["jointable"].Value); } XmlNode descriptionNode = node.SelectSingleNode(DESCRIPTION); if (descriptionNode != null) { entity.Description = descriptionNode.InnerText.Trim(); } //Adds all attributes including all not defined by element class foreach (XmlAttribute attribute in node.Attributes) { if (!entity.Attributes.ContainsKey(attribute.Name)) { entity.Attributes.Add(attribute.Name, attribute.Value); } } entity.dependents = ParseDependentsFromXml(node, vd); entity.fields = PropertyElement.ParseFromXml(doc, entities, entity, sqltypes, types, vd); entity.finders = FinderElement.ParseFromXml(doc, node, entities, entity, sqltypes, types, vd); entity.comparers = ComparerElement.ParseFromXml(node, entities, entity, sqltypes, types, vd); entities.Add(entity); } StringCollection names = new StringCollection(); foreach (EntityElement entity in entities) { if (names.Contains(entity.Name)) { vd(new ParserValidationArgs(ParserValidationSeverity.ERROR, "duplicate entity definition for " + entity.Name)); } else { names.Add(entity.Name); } } return(entities); }