예제 #1
0
        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);
        }
예제 #2
0
        /// <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);
                    //}
                }
            }
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <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);
                    }
                }
            }
        }
예제 #5
0
        /// <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);
                    }
                }
            }
        }
예제 #6
0
        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);
        }