示例#1
0
        // for making new repeat instances; 'from' and 'to' must be unambiguous
        // references EXCEPT 'to' may be ambiguous at its final step
        // return true is successfully copied, false otherwise
        public TreeElement copyNode(TreeElement src, TreeReference to)
        {
            if (!to.isAbsolute())
            {
                throw new InvalidReferenceException("Destination reference must be absolute for copying", to);
            }

            // strip out dest node info and get dest parent
            String        dstName  = to.getNameLast();
            int           dstMult  = to.getMultLast();
            TreeReference toParent = to.getParentRef();

            TreeElement parent = resolveReference(toParent);

            if (parent == null)
            {
                throw new InvalidReferenceException("Null parent reference whle attempting to copy", toParent);
            }
            if (!parent.isChildable())
            {
                throw new InvalidReferenceException("Invalid Parent Node: cannot accept children.", toParent);
            }

            if (dstMult == TreeReference.INDEX_UNBOUND)
            {
                dstMult = parent.getChildMultiplicity(dstName);
            }
            else if (parent.getChild(dstName, dstMult) != null)
            {
                throw new InvalidReferenceException("Destination already exists!", to);
            }

            TreeElement dest = src.deepCopy(false);

            dest.setName(dstName);
            dest.multiplicity = dstMult;
            parent.addChild(dest);
            return(dest);
        }