public void CopyFrom(PropertyNode node)
        {
            if (node == null)
                throw new ArgumentNullException("node");

            node.WriteTo(this);
        }
        public virtual void Visit(PropertyNode node)
        {
            if (node == null)
                throw new ArgumentNullException("node"); // $NON-NLS-1

            node.AcceptVisitor(this);
        }
        public PropertyTreeNodeWriter(PropertyTree tree)
        {
            if (tree == null)
                throw new ArgumentNullException("tree");

            this.currentParent = tree;
            this.root = tree;
        }
        private void AddLast(PropertyNode node)
        {
            if (head == null) {
                this.head = this.tail = node;
                this.head.Position = 0;

            } else {
                this.tail.NextSibling = node;
                node.Position = tail.Position + 1;
                node.PreviousSibling = tail;
                tail = node;
            }

            version++;
            node.parent = this.parent;
        }
        private void AddFirst(PropertyNode node)
        {
            if (head == null) {
                this.head = this.tail = node;
                this.head.Position = 0;

            } else {
                this.head.PreviousSibling = node;
                node.NextSibling = this.head;
                node.PreviousSibling = null;
                this.head = node;
                ApplyPositions(this.head, 0);
            }

            version++;
            node.parent = this.parent;
        }
        internal void Remove(PropertyNode node)
        {
            if (head == node) {
                this.head = node.NextSibling;
            }
            if (tail == node) {
                this.tail = node.PreviousSibling ?? head;
            }

            var prev = node.PreviousSibling;
            var next = node.NextSibling;
            if (prev != null) prev.NextSibling = next;
            if (next != null) {
                next.PreviousSibling = prev;
                ApplyPositions(next, node.Position);
            }

            node.parent = null;
            node.Position = -1;
            node.NextSibling = null;
            node.PreviousSibling = null;
        }
Example #7
0
 protected virtual void DefaultVisit(PropertyNode node)
 {
 }
 public override void MoveToRoot()
 {
     this.current = this.current.Root;
 }
 private void PopParent()
 {
     this.currentParent = this.currentParent.Parent;
 }
        public void WriteNode(PropertyNode node)
        {
            if (node == null)
                throw new ArgumentNullException("node"); // $NON-NLS-1

            var reader = node.ReadNode();
            reader.Read();
            WriteNode(reader);
        }
        internal void Clear()
        {
            foreach (var node in this) {
                Exit(node);
            }

            this.head = null;
            this.tail = null;
        }
        public override bool Read()
        {
            switch (this.state) {
                case ReadState.Initial:
                    this.state = ReadState.Interactive;
                    return true;

                case ReadState.Interactive:
                    PropertyNode next = this.node;

                    while (next != null) {
                        if (next.NextSibling != null) {
                            this.node = next.NextSibling;
                            return true;
                        }

                        next = next.Parent;
                    }

                    return false;

                case ReadState.Error:
                case ReadState.EndOfFile:
                case ReadState.Closed:
                default:
                    return false;
            }
        }
 public PropertyTreeNodeReader(PropertyNode node)
 {
     this.node = node;
     this.state = ReadState.Initial;
 }
 public DocumentPTNavigator(PropertyNode current)
 {
     this.current = current;
 }
        private bool MoveToSibling(PropertyNode start,
                                   Func<PropertyNode, bool> predicate)
        {
            PropertyNode node = start;
            if (node != null) {
                while (!(predicate(node))) {
                    node = node.NextSibling;
                    if (node == null)
                        return false;
                }

                this.current = node;
                return true;
            }
            return false;
        }
        private bool MoveToGeneric(PropertyNode node)
        {
            if (node == null)
                return false;

            this.current = node;
            return true;
        }
 private void ApplyPositions(PropertyNode node, int position)
 {
     while (node != null) {
         node.Position = position++;
         node = node.NextSibling;
     }
 }
        public override void WriteStartTree(string localName, string ns)
        {
            Require.NotNullOrEmptyString("localName", localName);
            StartImplicitly();
            PropertyTree newTree = new PropertyTree();
            newTree.Name = localName;
            newTree.Namespace = ns;
            CopyLineInfo(newTree);

            if (this.root == null) {
                this.root = newTree;
                this.currentParent = newTree;
            } else
                PushParent(newTree);
        }
 private void Exit(PropertyNode node)
 {
     node.NextSibling = null;
     node.PreviousSibling = null;
     node.Position = -1;
     node.parent = null;
 }
        public override bool MoveTo(PropertyTreeNavigator other)
        {
            if (other == null)
                throw new ArgumentNullException("other");

            DocumentPTNavigator otherNav = other as DocumentPTNavigator;
            if (otherNav != null && this.current.Root == otherNav.current.Root) {
                this.current = otherNav.current;
                return true;
            }
            return false;
        }
 public override void WriteEndDocument()
 {
     this.currentParent = null;
 }
 protected virtual void DefaultVisit(PropertyNode node)
 {
 }
 private void CopyLineInfo(PropertyNode node)
 {
     node.InitFrom(lineInfo, uriContext, prefixMap, isExpressNamespace);
 }
        internal void InsertBefore(PropertyNode node, PropertyNode before)
        {
            before.PreviousSibling.NextSibling = node;
            node.PreviousSibling = before.PreviousSibling;
            before.PreviousSibling = node;
            node.NextSibling = before;
            node.parent = this.parent;
            version++;

            ApplyPositions(node, before.Position);
        }
        private void PushParent(PropertyNode newParent)
        {
            if (this.currentParent == null)
                throw PropertyTreesFailure.WouldCreateMalformedDocument();

            this.currentParent.AppendChild(newParent);
            this.currentParent = newParent;
        }
        internal void InsertInternal(int index, PropertyNode node)
        {
            if (index == 0) {
                AddFirst(node);

            } else if (index == Count) {
                AddLast(node);

            } else {
                var before = this[index];
                InsertBefore(node, before);
            }
        }
 // TODO PropertyTreeFlattener
 public NameValueCollection DoVisit(PropertyNode node)
 {
     this.result = new PropertyCollection();
     Visit(node);
     return result;
 }
Example #28
0
 public PropertyTreeNodeReader(PropertyNode node)
 {
     this.node  = node;
     this.state = ReadState.Initial;
 }