public static ArrayList ParseFromXml(XmlDocument doc, 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; } FinderElement finder = new FinderElement(); 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); }
/// <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> /// 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="finderElements"></param> public static void ParseFromXml(XmlNode node, IList finderElements) { if (node != null && finderElements != null) { foreach (XmlNode finderNode in node.ChildNodes) { if (finderNode.NodeType.Equals(XmlNodeType.Element)) { FinderElement finderElement = new FinderElement(); BuildElement(finderNode, finderElement); finderElements.Add(finderElement); } } } }
public static void BuildElement(XmlNode node, IPropertyContainer entity, FinderElement finder, ParserValidationDelegate vd) { if (node.Attributes["sort"] != null) { finder.Sort = node.Attributes["sort"].Value; } if (node.Attributes[EXPRESSION] != null) { finder.Expression = node.Attributes[EXPRESSION].Value; } if (node.Attributes["unique"] != null) { finder.Unique = Boolean.Parse(node.Attributes["unique"].Value); } if (node.Attributes[LIMIT] != null) { finder.Limit = Boolean.Parse(node.Attributes[LIMIT].Value); } // Default sort to all finder properties if none specified. if (finder.Sort == String.Empty) { foreach (PropertyElement p in finder.Fields) { if (finder.Sort != String.Empty) { finder.Sort += ", "; } finder.Sort += p.GetSqlAlias(); } } //Adds all attributes including all non defined by element class foreach (XmlAttribute attribute in node.Attributes) { if (!finder.Attributes.ContainsKey(attribute.Name)) { finder.Attributes.Add(attribute.Name, attribute.Value); } } finder.container = entity; // Make sure the parameter names are specified and unique.unique. for (int nameChanging = 0; nameChanging < finder.Fields.Count; nameChanging++) { PropertyElement field = (PropertyElement)(finder.Fields[nameChanging]); if (field.ParameterName == String.Empty) { field.ParameterName = field.Name; } int sequence = 1; string pName = field.ParameterName; bool changedName = true; while (changedName) { changedName = false; for (int nameChecking = 0; nameChecking < nameChanging; nameChecking++) { PropertyElement p = (PropertyElement)(finder.Fields[nameChecking]); if (pName.Equals(p.ParameterName)) { sequence++; pName = pName + sequence.ToString(); changedName = true; } } } field.ParameterName = pName; } // Validate the expression, if any. if (finder.Expression != String.Empty) { finder.Expression = Configuration.PrepareExpression(finder.Expression, finder, " finder " + finder.Name + " in " + entity.Name + " ", vd); } }
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); }