Exemplo n.º 1
0
 /// <summary>
 ///   Adds a reference.
 /// </summary>
 /// <param name = "item">The item.</param>
 public void AddReference(IIBItem item)
 {
     if (!String.IsNullOrEmpty(item.Id))
     {
         this.references.Add(item.Id, item);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 ///   Adds a reference.
 /// </summary>
 /// <param name = "item">The item.</param>
 public void AddReference(IIBItem item)
 {
     if (!String.IsNullOrEmpty(item.Id))
     {
         this.references.Add(item.Id, item);
     }
 }
Exemplo n.º 3
0
        private void CollectOutlets(IIBReferenceResolver resolver)
        {
            IBDictionary dict = this.Find <IBDictionary>("outlets");

            if (dict == null)
            {
                return;
            }

            foreach (String key in dict.Keys)
            {
                IBString itemKey = dict[key] as IBString;
                if (itemKey == null)
                {
                    continue;
                }

                IIBItem     itemValue = dict[key];
                IBReference reference = itemValue as IBReference;
                if ((resolver != null) && (reference != null))
                {
                    itemValue = resolver.ResolveReference(reference);
                }
                this.outlets.Add(new IBOutletDescriptor(key, itemValue.ToString()));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Loads a <see cref = "IBDocument" /> from a Xml content.
        /// </summary>
        /// <param name = "reader">The reader.</param>
        /// <returns>An instance of <see cref = "IBDocument" /></returns>
        public static IBDocument LoadFromXml(XmlReader reader)
        {
            IBDocument           document = new IBDocument();
            IIBReferenceResolver resolver = new IBReferenceResolver();

            // The XML parsing is based on a top-down stack exploration
            StringBuilder   tempContent = new StringBuilder();
            Stack <IIBItem> stack       = new Stack <IIBItem>();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                {
                    String name  = reader.Name;
                    bool   empty = reader.IsEmptyElement;

                    // Collect all the attributes
                    Dictionary <String, String> attributes = new Dictionary <String, String>();
                    if (reader.HasAttributes)
                    {
                        for (int i = 0; i < reader.AttributeCount; i++)
                        {
                            reader.MoveToAttribute(i);
                            attributes.Add(reader.Name, reader.Value);
                        }
                    }

                    // Create an object corresponding to the node
                    IIBItem item = Create(name, attributes);
                    if (String.Equals("archive", name))
                    {
                        // The "archive" node has a special treatment
                        document.Root = item as IBArchive;
                    }
                    else
                    {
                        // Append the node to the current parent node
                        IIBItem current = stack.Peek();
                        current.AppendChild(item);
                    }

                    // If the node has an id, then add it to the resolver for latter processing
                    resolver.AddReference(item);

                    // Push the new node in the context stack
                    stack.Push(item);

                    // Prepare the content collector for node with text
                    tempContent = new StringBuilder();

                    // An empty node is pop right-away from the context stack
                    if (empty)
                    {
                        stack.Pop();
                        item.SetValue(tempContent.ToString());
                        item.Finish(resolver);
                    }
                }
                break;

                case XmlNodeType.EndElement:
                {
                    // When the node ends, it is pop from the context stack and its content is set
                    // After that, the node can perform additionnal processing.
                    IIBItem item = stack.Pop();
                    item.SetValue(tempContent.ToString());
                    item.Finish(resolver);
                }
                break;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.SignificantWhitespace:
                {
                    // Collect text content between start and end of the node
                    String value = reader.Value;
                    tempContent.Append(value);
                }
                break;
                }
            }

            return(document);
        }
Exemplo n.º 5
0
 /// <summary>
 ///   Appends a child to this instance.
 /// </summary>
 /// <param name = "item">The item to append.</param>
 public virtual void AppendChild(IIBItem item)
 {
 }