/** * {@inheritDoc} * * @see org.modeshape.graph.property.Path#hasSameAncestor(org.modeshape.graph.property.Path) */ @Override public boolean hasSameAncestor( Path that ) { CheckArg.isNotNull(that, "that"); if (parent.equals(that.getParent())) return true; return super.hasSameAncestor(that); }
/** * {@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.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.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); }
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); } };
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 boolean evaluate( Object childLocation, Object parentLocation ) { 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 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()); }
public T to( Location desiredLocation ) { if (!desiredLocation.hasPath()) { throw new IllegalArgumentException(GraphI18n.unableToCopyToLocationWithoutAPath.text(this.from, desiredLocation)); } Path desiredPath = desiredLocation.getPath(); if (desiredPath.isRoot()) { throw new IllegalArgumentException(GraphI18n.unableToCopyToTheRoot.text(this.from, desiredLocation)); } Path parent = desiredPath.getParent(); return submit(this.fromWorkspaceName, this.from, Location.create(parent), desiredPath.getLastSegment().getName()); }
public void create( Path path, Iterable<Property> properties ) { assert path != null; Path parent = path.getParent(); Name child = path.getLastSegment().getName(); requests.add(new CreateNodeRequest(Location.create(parent), workspace, child, properties)); }
@Test public void shouldReturnNoAncestorForRoot() { assertThat(RootPath.INSTANCE.getParent(), nullValue()); }
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 public void shouldReturnParentForAncestorOfDegreeOne() { assertThat(path.getAncestor(1), is(sameInstance(parent))); assertThat(path.getParent(), is(sameInstance(parent))); }
@Test public void shouldReadTheChildrenOfTheRootNode() { List<Location> children = graph.getChildren().of("/"); assertThat(children, is(notNullValue())); for (Location child : children) { // Check the location has a path that has the root as a parent ... assertThat(child.hasPath(), is(true)); assertThat(child.getPath().getParent().isRoot(), is(true)); // Verify that each node can be read multiple ways ... readNodeThoroughly(child); } }
@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")); }
@Test public void shouldCreateNodeAtPathWithPropertiesAndReturnLocation() { Location actual = graph.createAt(validPath).with(validIdProperty1).getLocation(); assertThat(actual, is(notNullValue())); assertThat(numberOfExecutions, is(1)); assertNextRequestIsCreate(Location.create(validPath.getParent()), "c", validIdProperty1); assertNoMoreRequests(); actual = graph.createAt(validPath).with(validIdProperty1).and(validIdProperty2).getLocation(); assertThat(actual, is(notNullValue())); assertThat(numberOfExecutions, is(1)); assertNextRequestIsCreate(Location.create(validPath.getParent()), "c", validIdProperty1, validIdProperty2); assertNoMoreRequests(); }
@Test public void shouldResolveRelativePathToParent() { path = pathFactory.create("/a/b/c/d/e/f"); assertThat(path.resolve(pathFactory.create("..")), is(path.getParent())); assertThat(path.resolve(pathFactory.create("..")), hasSegments(pathFactory, "a", "b", "c", "d", "e")); }
@Test public void shouldCreateNodeAndReturnGraph() { graph.create(validPath).and().getNodeAt(validPath); assertThat(numberOfExecutions, is(2)); assertNextRequestIsCreate(Location.create(validPath.getParent()), "c"); assertNextRequestReadNode(Location.create(validPath)); assertNoMoreRequests(); }
private MockPathNode pathNodeFor( InternalNode node ) { if (node.getParent() == null) { new MockPathNode(node.getUuid(), null, node.getName(), node.getProperties(), node.getChildren()); } return new MockPathNode(node.getUuid(), node.getPath().getParent(), node.getName(), node.getProperties(), node.getChildren()); }