public T to( Path desiredPath ) { if (desiredPath.isRoot()) { throw new IllegalArgumentException(GraphI18n.unableToCopyToTheRoot.text(this.from, desiredPath)); } Path parent = desiredPath.getParent(); return submit(this.fromWorkspaceName, this.from, Location.create(parent), desiredPath.getLastSegment().getName()); }
protected ReadableVisitor append( Path path ) { sb.append(SINGLE_QUOTE); sb.append(path.getString(registry)); sb.append(SINGLE_QUOTE); return this; }
/** * {@inheritDoc} */ public URI create( Path value ) { if (value == null) return null; if (value.isAbsolute()) { return create("/" + value.getString(this.namespaceRegistry)); } return create("./" + value.getString(this.namespaceRegistry)); }
public boolean evaluate( Object parentLocation, Object childLocation ) { if (childLocation == null || parentLocation == null) return false; Path childPath = ((Location)childLocation).getPath(); Path parentPath = ((Location)parentLocation).getPath(); if (childPath.isRoot()) return false; return parentPath.isSameAs(childPath.getParent()); } };
public int compare( Object parentLocation, Object childLocation ) { if (parentLocation == null) return parentLocation == null ? 0 : -1; else if (parentLocation == null) return 1; Path childPath = ((Location)childLocation).getPath(); Path parentPath = ((Location)parentLocation).getPath(); if (childPath.isRoot()) return parentPath.isRoot() ? 0 : -1; Path parentOfChild = childPath.getParent(); return pathComparator.compare(parentPath, parentOfChild); } };
@Test public void shouldCreateRelativePathWithOnlySelf() { path = paths.create("."); assertThat(path.isAbsolute(), is(false)); assertThat(path.getSegment(0), is(Path.SELF_SEGMENT)); assertThat(path.size(), is(1)); }
Map<Name, AtomicInteger> existingSnsByNodeName = new HashMap<Name, AtomicInteger>(); for (Location child : children) { Segment childSegment = child.getPath().getLastSegment(); Name childName = childSegment.getName(); AtomicInteger sns = existingSnsByNodeName.get(childName); try { Path derivedFromValue = pathFactory.create(value); if (derivedFromPath.isSameAs(derivedFromValue)) { Segment childSegment = childLocation.getPath().getLastSegment(); Name childName = childSegment.getName(); AtomicInteger sns = existingSnsByNodeName.get(childName); Path absolutePath = targetNodePath.isAbsolute() ? targetNodePath : outputNodePath.resolve(targetNodePath); if (targetNodePath.size() <= 1 && addDerivedMixin && pathsOfTopLevelNodes.add(absolutePath)) { properties = addDerivedProperties(properties, context, derivedFromPath); if (absolutePath.getParent() != null) { buildPathTo(absolutePath.getParent(), context, builtPaths);
@Test public void shouldConstructRelativePath() { assertThat(pathFactory.create("a/b/c").isAbsolute(), is(false)); assertThat(pathFactory.create("a/b/c").isNormalized(), is(true)); assertThat(pathFactory.create("a/b/c").size(), is(3)); assertThat(pathFactory.create("a/b/c").getString(namespaceRegistry), is("a/b/c")); }
@Test public void shouldResolveRelativePaths() { path = pathFactory.create("/a/b/c/d/e/f"); assertThat(path.resolve(pathFactory.create("../../../../../..")), is(ROOT)); assertThat(path.resolve(pathFactory.create("../..")), is(path.getParent().getParent())); assertThat(path.resolve(pathFactory.create("../..")), hasSegments(pathFactory, "a", "b", "c", "d")); assertThat(path.resolve(pathFactory.create("../x/../y/../z/..")), is(path.getParent())); assertThat(path.resolve(pathFactory.create("../x/../y/../z/..")), hasSegments(pathFactory, "a", "b", "c", "d", "e")); assertThat(path.resolve(pathFactory.create("../x")), hasSegments(pathFactory, "a", "b", "c", "d", "e", "x")); }
public Object evaluate( Object[] tuple ) { Location location = (Location)tuple[locationIndex]; if (location == null) return null; Path path = location.getPath(); assert path != null; return path.isRoot() ? "" : stringFactory.create(location.getPath().getLastSegment().getName()); } };
@Test public void shouldResolveAllRelativePathsToTheirAbsolutePath() { List<Path.Segment> segments = new ArrayList<Path.Segment>(); segments.add(new BasicPathSegment(new BasicName("http://example.com", "a"))); Path other = mock(Path.class); when(other.isAbsolute()).thenReturn(false); when(other.getSegmentsList()).thenReturn(segments); when(other.getNormalizedPath()).thenReturn(other); Path resolved = root.resolve(other); assertThat(resolved.getSegmentsList(), is(segments)); assertThat(resolved.isAbsolute(), is(true)); }
@Test public void shouldResolveRelativePathToAbsolutePath() { path = pathFactory.create("/a/b/c/d"); path2 = path.resolve(pathFactory.create("../../e/f")); assertThat(path2, is(pathFactory.create("/a/b/e/f"))); assertThat(path2.isAbsolute(), is(true)); assertThat(path2.isNormalized(), is(true)); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.ChangeRequest#changes(java.lang.String, org.modeshape.graph.property.Path) */ @Override public boolean changes( String workspace, Path path ) { return this.workspaceName.equals(workspace) && at.hasPath() && at.getPath().getParent().isAtOrBelow(path); }
/** * {@inheritDoc} * * @see org.modeshape.graph.property.Path#isDecendantOf(org.modeshape.graph.property.Path) */ @Override public boolean isDecendantOf( Path ancestor ) { if (parent == ancestor) return true; // same instance return parent.isAtOrBelow(ancestor); }
public PathNode createNode( ExecutionContext context, String pathToNewNode, Map<Name, Property> properties, NodeConflictBehavior conflictBehavior ) { PathFactory pathFactory = context.getValueFactories().getPathFactory(); Path newPath = pathFactory.create(pathToNewNode); return createNode(context, getNode(newPath.getParent()), newPath.getLastSegment().getName(), properties, conflictBehavior); }
@Test( expected = InvalidPathException.class ) public void shouldNotResolveRelativePathUsingAnAbsolutePath() { Path other = mock(Path.class); when(other.isAbsolute()).thenReturn(true); root.resolve(other); }
/** * {@inheritDoc} * * @see org.modeshape.graph.property.Path#isSameAs(org.modeshape.graph.property.Path) */ @Override public boolean isSameAs( Path other ) { CheckArg.isNotNull(other, "other"); return other.isIdentifier() && idSegment.equals(other.getLastSegment()); }
/** * {@inheritDoc} */ public Path resolveAgainst( Path absolutePath ) { CheckArg.isNotNull(absolutePath, "absolute path"); return absolutePath.resolve(this); }