public static ArrayList ParseFromXml(XmlNode root, IList entities, IPropertyContainer entity, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd) { ArrayList finders = new ArrayList(); XmlNodeList elements = null; foreach (XmlNode n in root.ChildNodes) { if (n.Name.Equals("finders")) { elements = n.ChildNodes; break; } } if (elements != null) { foreach (XmlNode node in elements) { if (node.NodeType == XmlNodeType.Comment) { continue; } ReportExtractionFinderElement finder = new ReportExtractionFinderElement(); finder.Name = node.Attributes["name"].Value; finder.Fields = PropertyElement.ParseFromXml(GetChildNodeByName(node, PROPERTIES), entities, entity, sqltypes, types, true, vd); BuildElement(node, entity, finder, vd); finders.Add(finder); } } return(finders); }
public static ArrayList ParseFromXml(Configuration options, XmlDocument doc, Hashtable sqltypes, Hashtable types, ArrayList sqlentities, ParserValidationDelegate vd) { ArrayList messages = new ArrayList(); XmlNodeList entities = doc.DocumentElement.GetElementsByTagName("message"); foreach (XmlNode node in entities) { MessageElement message = new MessageElement(); message.Name = node.Attributes["name"].Value; message.Text = node.Attributes["text"].Value; message.fields = PropertyElement.ParseFromXml(GetChildNodeByName(node, PROPERTIES), messages, message, sqltypes, types, false, vd); messages.Add(message); } StringCollection names = new StringCollection(); foreach (MessageElement message in messages) { if (names.Contains(message.Name)) { vd(new ParserValidationArgs(ParserValidationSeverity.ERROR, "duplicate message definition for " + message.Name)); } else { names.Add(message.Name); } } return(messages); }
public static ArrayList ParseFromXml(XmlNode root, IList entities, IPropertyContainer container, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd) { ArrayList comparers = new ArrayList(); XmlNode comparerNode = GetChildNodeByName(root, COMPARERS); if (comparerNode != null) { foreach (XmlNode node in comparerNode.ChildNodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } ComparerElement comparer = new ComparerElement(); if (node.Attributes["name"] == null) { vd(ParserValidationArgs.NewError("ComparerElement in " + container.Name + " has no name attribute.")); continue; } comparer.Name = node.Attributes["name"].Value; comparer.Fields = PropertyElement.ParseFromXml(GetChildNodeByName(node, PROPERTIES), new ArrayList(), container, sqltypes, types, true, vd); comparers.Add(comparer); } } return(comparers); }
/// <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 node, IList entityElements) { if (node != null && entityElements != null) { XmlNodeList entities = node.SelectNodes("entities/entity"); foreach (XmlNode entityNode in entities) { //if (entityNode.NodeType.Equals(XmlNodeType.Element)) { EntityElement entityElement = new EntityElement(); entityElement.Name = GetAttributeValue(entityNode, NAME, entityElement.Name); entityElement.Namespace = GetAttributeValue(entityNode, NAMESPACE, entityElement.Namespace); entityElement.BaseEntity.Name = GetAttributeValue(entityNode, BASE_ENTITY, entityElement.BaseEntity.Name); entityElement.SqlEntity.Name = GetAttributeValue(entityNode, SQLENTITY, entityElement.SqlEntity.Name); entityElement.IsAbstract = Boolean.Parse(GetAttributeValue(entityNode, ABSTRACT, entityElement.IsAbstract.ToString())); entityElement.HasNamespace = !String.IsNullOrEmpty(GetAttributeValue(entityNode, NAMESPACE, entityElement.Namespace.ToString())); entityElement.DoLog = Boolean.Parse(GetAttributeValue(entityNode, LOG, entityElement.DoLog.ToString())); entityElement.ReturnWholeObject = Boolean.Parse(GetAttributeValue(entityNode, RETURNWHOLEOBJECT, entityElement.ReturnWholeObject.ToString())); entityElement.PrepareForInsert = Boolean.Parse(GetAttributeValue(entityNode, PREPAREFORINSERT, entityElement.PrepareForInsert.ToString())); entityElement.JoinTable = Boolean.Parse(GetAttributeValue(entityNode, JOINTABLE, entityElement.JoinTable.ToString())); entityElement.DependentEntity = Boolean.Parse(GetAttributeValue(entityNode, DEPENDENTENTITY, entityElement.DependentEntity.ToString())); PropertyElement.ParseFromXml(GetChildNodeByName(entityNode, PROPERTIES), entityElement.Fields); FinderElement.ParseFromXml(GetChildNodeByName(entityNode, FINDERS), entityElement.Finders); ComparerElement.ParseFromXml(GetChildNodeByName(entityNode, COMPARERS), entityElement.Comparers); entityElements.Add(entityElement); //} } } }
public static void BuildElement(XmlNode finderNode, FinderElement finderElement) { finderElement.Name = GetAttributeValue(finderNode, NAME, finderElement.Name); finderElement.Sort = GetAttributeValue(finderNode, SORT, finderElement.Sort); finderElement.Expression = GetAttributeValue(finderNode, EXPRESSION, finderElement.Expression); finderElement.Unique = Boolean.Parse(GetAttributeValue(finderNode, UNIQUE, finderElement.Unique.ToString())); finderElement.Limit = Boolean.Parse(GetAttributeValue(finderNode, LIMIT, finderElement.Limit.ToString())); PropertyElement.ParseFromXml(GetChildNodeByName(finderNode, PROPERTIES), finderElement.Fields); }
/// <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 node, IList comparerElements) { if (node != null && comparerElements != null) { foreach (XmlNode comparerNode in node.ChildNodes) { if (comparerNode.NodeType.Equals(XmlNodeType.Element)) { ComparerElement comparerElement = new ComparerElement(); comparerElement.Name = GetAttributeValue(comparerNode, NAME, comparerElement.Name); PropertyElement.ParseFromXml(GetChildNodeByName(comparerNode, PROPERTIES), comparerElement.Fields); comparerElements.Add(comparerElement); } } } }
/// <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 containing the enty reference elements.</param> /// <param name="EntityReferenceElements">returned list of entity reference elements parsed.</param> public static void ParseFromXml(XmlNode node, IList entityReferenceElements) { if (node != null && entityReferenceElements != null) { foreach (XmlNode refNode in node.ChildNodes) { if (refNode.NodeType.Equals(XmlNodeType.Element)) { EntityReferenceElement entityReferenceElement = new EntityReferenceElement(); entityReferenceElement.Name = GetAttributeValue(refNode, NAME, entityReferenceElement.Name); entityReferenceElement.Entity.Name = GetAttributeValue(refNode, ENTITY, entityReferenceElement.Entity.Name); entityReferenceElement.AliasPrefix = GetAttributeValue(refNode, ALIAS_PREFIX, entityReferenceElement.AliasPrefix); entityReferenceElement.Hints = GetAttributeValue(refNode, HINTS, entityReferenceElement.Hints); entityReferenceElement.Filter = GetAttributeValue(refNode, FILTER, entityReferenceElement.Filter); entityReferenceElement.JoinModifier = GetAttributeValue(refNode, JOIN_MODIFIER, entityReferenceElement.JoinModifier); PropertyElement.ParseFromXml(GetChildNodeByName(refNode, PROPERTY_REFERENCES), entityReferenceElement.PropertyReferences); entityReferenceElements.Add(entityReferenceElement); } } } }
/// <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> /// 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 void BuildElement(XmlNode messageNode, MessageElement messageElement) { messageElement.Name = GetAttributeValue(messageNode, NAME, messageElement.Name); messageElement.Text = GetAttributeValue(messageNode, TEXT, messageElement.Text); PropertyElement.ParseFromXml(GetChildNodeByName(messageNode, PROPERTIES), messageElement.Fields); }
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); }