using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using CategoryTheory;
using DiagramUI.Interfaces;
namespace DiagramUI.XmlObjectFactory
{
/// <summary>
/// Static Xml object factory
/// </summary>
public static class StaticXmlObjectFactory
{
/// <summary>
/// Creates objects from Xml nodes
/// </summary>
/// <param name="nodes">Nodes</param>
/// <param name="factory">Factory</param>
/// <param name="dictionary">Dictionary</param>
public static void Create(XmlNodeList nodes, IXmlObjectFactory factory, IDictionary<XmlElement, ICategoryObject> dictionary)
{
foreach (XmlNode node in nodes)
{
if (!(node is XmlElement))
{
continue;
}
XmlElement e = node as XmlElement;
ICategoryObject co = null;
factory.Create(e, ref co);
if ((co != null) & (dictionary != null))
{
dictionary[e] = co;
}
}
}
/// <summary>
/// Creates existing objects from Xml nodes
/// </summary>
/// <param name="nodes">Nodes</param>
/// <param name="factory">Factory</param>
/// <param name="dictionary">Dictionary</param>
public static void CreateExisting(XmlNodeList nodes, IXmlObjectFactory factory, IDictionary<XmlElement, ICategoryObject> dictionary)
{
foreach (XmlNode node in nodes)
{
if (!(node is XmlElement))
{
continue;
}
XmlElement e = node as XmlElement;
if (!dictionary.ContainsKey(e))
{
continue;
}
ICategoryObject co = dictionary[e];
factory.Create(e, ref co);
}
}
}
}