/** * {@inheritDoc} * * @see org.modeshape.graph.connector.base.Transaction#pathFor(org.modeshape.graph.connector.base.Workspace, * org.modeshape.graph.connector.base.Node) */ public Path pathFor( WorkspaceType workspace, NodeType node ) { assert node != null; assert pathFactory != null; LinkedList<Path.Segment> segments = new LinkedList<Path.Segment>(); do { segments.addFirst(node.getName()); node = getParent(workspace, node); } while (node != null); segments.removeFirst(); // remove the root name, which is meaningless return pathFactory.createAbsolutePath(segments); }
/** * Returns the absolute path to the given node * * @param pathFactory the path factory to use to create the path from the list of names of all of the nodes on the path from * the root node to the given node * @param node the node for which the path should be returned * @return the absolute path to the given node */ public Path pathFor( PathFactory pathFactory, MapNode node ) { assert node != null; assert pathFactory != null; LinkedList<Path.Segment> segments = new LinkedList<Path.Segment>(); MapNode root = getRoot(); do { segments.addFirst(node.getName()); node = node.getParent(); } while (!node.equals(root)); return pathFactory.createAbsolutePath(segments); }
protected NodeType getNode( WorkspaceType workspace, Path path, Location location ) { NodeType node = getRootNode(workspace); for (Path.Segment segment : path) { NodeType child = getChild(workspace, node, segment); if (child == null) { List<Path.Segment> segments = new LinkedList<Path.Segment>(); for (Path.Segment seg : path) { if (seg != segment) segments.add(seg); else break; } Path lowestExisting = pathFactory.createAbsolutePath(segments); throw new PathNotFoundException(location, lowestExisting, GraphI18n.nodeDoesNotExist.text(path)); } node = child; } return node; }
protected Location getActualLocation( Location location, MapNode node ) { Path path = location.getPath(); if (path == null) { // Find the path on the node ... LinkedList<Path.Segment> segments = new LinkedList<Path.Segment>(); MapNode n = node; while (n != null) { if (n.getParent() == null) break; segments.addFirst(n.getName()); n = n.getParent(); } path = pathFactory.createAbsolutePath(segments); } // If there is a UUID in the location, it should match the node's. assert location.getUuid() == null || location.getUuid().equals(node.getUuid()); if (location.hasIdProperties()) { return location.with(path); } return Location.create(path, node.getUuid()); }
current = current.getParent(); newParentPath = getExecutionContext().getValueFactories().getPathFactory().createAbsolutePath(segments);