예제 #1
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);
                    //}
                }
            }
        }
예제 #2
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);
        }