/// <summary> /// Second pass parse and validation. /// </summary> /// <param name="options">Configuration options.</param> /// <param name="doc">Document being parsed.</param> /// <param name="sqltypes">List of sql types defined.</param> /// <param name="types">List of .Net types defined.</param> /// <param name="entities">List of EntityElement objects defined.</param> /// <param name="vd">Validation delegate for error reporting.</param> /// <returns>Validated list of report extractions.</returns> public static ArrayList ParseFromXml(Configuration options, XmlDocument doc, Hashtable sqltypes, Hashtable types, IList entities, ParserValidationDelegate vd) { ArrayList reportExtractions = new ArrayList(); XmlNodeList elements = doc.DocumentElement.GetElementsByTagName("reportextraction"); foreach (XmlNode node in elements) { if (node.NodeType == XmlNodeType.Comment) { continue; } ReportExtractionElement reportExtraction = new ReportExtractionElement(); if (node.Attributes[NAME] != null) { reportExtraction.Name = node.Attributes[NAME].Value; } else { vd(ParserValidationArgs.NewError("A report extraction must have a name.")); } if (node.Attributes[HINTS] != null) { reportExtraction.Hints = (string)(node.Attributes[HINTS].Value); } if (node.Attributes[HAVING] != null) { reportExtraction.Having = (string)(node.Attributes[HAVING].Value); } reportExtraction.EntityReferences = EntityReferenceElement.ParseFromXml(options, GetChildNodeByName(node, ENTITY_REFERENCES), reportExtraction, types, sqltypes, entities, vd); XmlNode computedProperties = GetChildNodeByName(node, COMPUTED_PROPERTIES); if (computedProperties != null) { reportExtraction.ComputedProperties = PropertyElement.ParseFromXml(computedProperties, entities, reportExtraction, sqltypes, types, false, vd); } reportExtraction.ValidateFilters(vd); reportExtraction.ValidateExpressions(vd); reportExtraction.ValidateUniqueNames(vd); reportExtraction.ValidateDatabases(vd); reportExtractions.Add(reportExtraction); reportExtraction.Having = Configuration.PrepareExpression(reportExtraction.Having, reportExtraction, "having attribute in report extraction " + reportExtraction.Name, vd); // Make sure finders get prepared expressions! reportExtraction.Comparers = ComparerElement.ParseFromXml(node, entities, reportExtraction, sqltypes, types, vd); reportExtraction.Finders = ReportExtractionFinderElement.ParseFromXml(node, entities, reportExtraction, sqltypes, types, vd); } return(reportExtractions); }
/// <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); } }
/// <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">Node to look in for the report extractions.</param> /// <param name="ReportExtractionElements">List of report extractions created (returned)</param> public static void ParseFromXml(XmlNode node, IList ReportExtractionElements) { if (node != null && ReportExtractionElements != null) { foreach (XmlNode entityNode in node.ChildNodes) { if (entityNode.NodeType.Equals(XmlNodeType.Element)) { ReportExtractionElement reportExtractionElement = new ReportExtractionElement(); reportExtractionElement.Name = GetAttributeValue(entityNode, NAME, reportExtractionElement.Name); reportExtractionElement.Hints = GetAttributeValue(entityNode, HINTS, reportExtractionElement.Name); reportExtractionElement.Having = GetAttributeValue(entityNode, HAVING, reportExtractionElement.Name); EntityReferenceElement.ParseFromXml(GetChildNodeByName(entityNode, ENTITY_REFERENCES), reportExtractionElement.entityReferences); PropertyElement.ParseFromXml(GetChildNodeByName(entityNode, COMPUTED_PROPERTIES), reportExtractionElement.ComputedProperties); ComparerElement.ParseFromXml(GetChildNodeByName(entityNode, COMPARERS), reportExtractionElement.Comparers); ReportExtractionFinderElement.ParseFromXml(GetChildNodeByName(entityNode, FINDERS), reportExtractionElement.Finders); ReportExtractionElements.Add(reportExtractionElement); } } } }
/// <summary> /// Constructor to default values from the report extraction. /// </summary> /// <param name="data">Report extraction containing the entity reference.</param> public EntityReferenceElement(ReportExtractionElement data) { this.Hints = data.Hints; }
/// <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); }