/** Traverse a path from a parent node down, by an enumeration of names. * @param start node to start searching at * @param names enumeration of names of nodes * along the path * @return the node with such a path from the start node * @exception NodeNotFoundException if the node with such name * does not exists; the exception contains additional information * about the failure. */ public static Node findPath(Node start, Enumeration<String> names) throws NodeNotFoundException { int depth = 0; while (names.hasMoreElements()) { String name = names.nextElement(); Node next = findChild(start, name); if (next == null) { // no element in list matched the name => fail // fire exception with the last accessed node and the // name of child that does not exists throw new NodeNotFoundException(start, name, depth); } else { // go on next node start = next; } // continue on next depth depth++; } return start; }
/** Find the node. * @return the found node * @exception IOException if the parent cannot be recreated * @exception NodeNotFoundException if the path is not valid (exception may be examined for details) */ public Node getNode() throws java.io.IOException { Node parentNode = parent.getNode(); Node child = parentNode.getChildren().findChild(path); if (child != null) { return child; } else { throw new NodeNotFoundException(parentNode, path, 0); } }
throw new NodeNotFoundException (start, name, depth); } else {
throw new NodeNotFoundException (start, name, depth); } else {
/** Find the node. * @return the found node * @exception IOException if the parent cannot be recreated * @exception NodeNotFoundException if the path is not valid (exception may be examined for details) */ public Node getNode () throws java.io.IOException { Node parentNode = parent.getNode (); Node child = parentNode.getChildren ().findChild (path); if (child != null) return child; else throw new NodeNotFoundException (parentNode, path, 0); }
/** Find the node. * @return the found node * @exception IOException if the parent cannot be recreated * @exception NodeNotFoundException if the path is not valid (exception may be examined for details) */ public Node getNode () throws java.io.IOException { Node parentNode = parent.getNode (); Node child = parentNode.getChildren ().findChild (path); if (child != null) return child; else throw new NodeNotFoundException (parentNode, path, 0); }