示例#1
0
        // recursive helper function for expandReference
        // sourceRef: original path we're matching against
        // node: current node that has matched the sourceRef thus far
        // templateRef: explicit path that refers to the current node
        // refs: Vector to collect matching paths; if 'node' is a target node that
        // matches sourceRef, templateRef is added to refs
        private void expandReference(TreeReference sourceRef, TreeElement node, List <TreeReference> refs, Boolean includeTemplates)
        {
            int depth = node.getDepth();

            if (depth == sourceRef.size())
            {
                refs.Add(node.getRef());
            }
            else
            {
                String             name = sourceRef.getName(depth);
                int                mult = sourceRef.getMultiplicity(depth);
                List <TreeElement> set  = new List <TreeElement>();

                if (node.getNumChildren() > 0)
                {
                    if (mult == TreeReference.INDEX_UNBOUND)
                    {
                        int count = node.getChildMultiplicity(name);
                        for (int i = 0; i < count; i++)
                        {
                            TreeElement child = node.getChild(name, i);
                            if (child != null)
                            {
                                set.Add(child);
                            }
                            else
                            {
                                throw new InvalidOperationException(); // missing/non-sequential
                                // nodes
                            }
                        }
                        if (includeTemplates)
                        {
                            TreeElement template = node.getChild(name, TreeReference.INDEX_TEMPLATE);
                            if (template != null)
                            {
                                set.Add(template);
                            }
                        }
                    }
                    else if (mult != TreeReference.INDEX_ATTRIBUTE)
                    {
                        //TODO: Make this test mult >= 0?
                        //If the multiplicity is a simple integer, just get
                        //the appropriate child
                        TreeElement child = node.getChild(name, mult);
                        if (child != null)
                        {
                            set.Add(child);
                        }
                    }
                }

                if (mult == TreeReference.INDEX_ATTRIBUTE)
                {
                    TreeElement attribute = node.getAttribute(null, name);
                    set.Add(attribute);
                }

                for (IEnumerator e = set.GetEnumerator(); e.MoveNext();)
                {
                    expandReference(sourceRef, (TreeElement)e.Current, refs, includeTemplates);
                }
            }
        }