void followPath()

in xmlschema-walker/src/main/java/org/apache/ws/commons/schema/docpath/XmlSchemaPathManager.java [158:223]


    void followPath(XmlSchemaPathNode<U, V> startNode) {
        if (startNode.getDocumentNode() == null) {
            if (!startNode.getDirection().equals(XmlSchemaPathNode.Direction.CHILD)) {

                throw new IllegalStateException(
                                                "The startNode may only have a null XmlSchemaDocumentNode if it "
                                                    + "represents the root node, and likewise its only valid "
                                                    + "direction is CHILD, not " + startNode.getDirection());
            }

            // startNode is the root node.
            XmlSchemaDocumentNode<U> rootDoc = createDocumentNode(null, startNode.getStateMachineNode());
            startNode.setDocumentNode(rootDoc);
            rootDoc.addVisitor(startNode);
        }

        XmlSchemaPathNode<U, V> prev = startNode;
        XmlSchemaPathNode<U, V> iter = prev.getNext();
        while (iter != null) {
            if (iter.getDocumentNode() == null) {
                if (!iter.getDirection().equals(XmlSchemaPathNode.Direction.CHILD)) {
                    throw new IllegalStateException(
                                                    "XmlSchemaPathNode has a direction of "
                                                        + iter.getDirection()
                                                        + " but it does not have an XmlSchemaDocumentNode to represent"
                                                        + " its state machine (" + iter.getStateMachineNode()
                                                        + ").");
                }

                final XmlSchemaDocumentNode<U> newDocNode = createDocumentNode(prev.getDocumentNode(),
                                                                               iter.getStateMachineNode());

                iter.setDocumentNode(newDocNode);

                final Map<Integer, XmlSchemaDocumentNode<U>> siblings = prev.getDocumentNode().getChildren();

                if (prev.getIndexOfNextNodeState() < 0) {
                    throw new IllegalStateException(
                                                    "Creating a new document node for a node represented by "
                                                        + iter.getStateMachineNode()
                                                        + " but its previous state does not know how to reach me.");
                }

                siblings.put(prev.getIndexOfNextNodeState(), iter.getDocumentNode());
            }

            switch (iter.getDirection()) {
            case CHILD:
            case SIBLING:
                iter.getDocumentNode().addVisitor(iter);
                break;
            default:
            }

            if (iter.getIteration() != iter.getDocIteration()) {
                throw new IllegalStateException("The current path node (representing "
                                                + iter.getStateMachineNode() + ") has an iteration of "
                                                + iter.getIteration()
                                                + ", which does not match the document node iteration of "
                                                + iter.getDocIteration() + '.');
            }

            prev = iter;
            iter = iter.getNext();
        }
    }