示例#1
0
        private void addChild(TreeElement child, Boolean checkDuplicate)
        {
            if (!isChildable())
            {
                throw new SystemException("Can't add children to node that has data value!");
            }

            if (child.multiplicity == TreeReference.INDEX_UNBOUND)
            {
                throw new SystemException("Cannot add child with an unbound index!");
            }

            if (checkDuplicate)
            {
                TreeElement existingChild = getChild(child.name, child.multiplicity);
                if (existingChild != null)
                {
                    throw new SystemException("Attempted to add duplicate child!");
                }
            }

            // try to keep things in order
            int i = children.Count;

            if (child.getMult() == TreeReference.INDEX_TEMPLATE)
            {
                TreeElement anchor = getChild(child.getName(), 0);
                if (anchor != null)
                {
                    i = children.IndexOf(anchor);
                }
            }
            else
            {
                TreeElement anchor = getChild(child.getName(),
                                              (child.getMult() == 0 ? TreeReference.INDEX_TEMPLATE : child.getMult() - 1));
                if (anchor != null)
                {
                    i = children.IndexOf(anchor) + 1;
                }
            }
            children.Insert(i, child);
            child.setParent(this);

            child.setRelevant(isRelevant(), true);
            child.setEnabled(isEnabled(), true);
        }