protected void setName( Name name ) { this.name = name; int snsIndex = 1; if (parent != null) { snsIndex = parent.getNextSnsForChildNamed(name); } pathToThisNode = pathFactory.create(pathToParent, name, snsIndex); }
public Segment segment( String segment ) { return paths.createSegment(segment); }
/** * Returns the path to the given node * * @param node the node for which the path should be returned; may not be null * @return the path to that node */ protected Path pathTo( NodeType node ) { if (node.getParent() == null) { return pathFactory.createRootPath(); } return pathFactory.create(node.getParent(), node.getName()); }
private Path pathFor( PathFactory pathFactory, ClassMetadata cmd ) { List<Segment> segments = new LinkedList<Segment>(); for (String segment : cmd.getClassName().split("\\.")) { segments.add(pathFactory.createSegment(segment)); } return pathFactory.createRelativePath(segments); }
@Test public void shouldReturnRootPathsThatAreAlwaysEquivalent() { path = paths.createRootPath(); for (int i = 0; i != 10; ++i) { assertThat(paths.createRootPath(), is(path)); } }
@Test public void shouldCreateRelativePathWithOnlySelfSegment() { path = paths.createRelativePath(name(".")); assertThat(path.isAbsolute(), is(false)); assertThat(path.getSegment(0), is(Path.SELF_SEGMENT)); assertThat(path.size(), is(1)); }
/** * {@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); }
@Test public void shouldCreateRootPathWithNoSegments() { assertThat(paths.createRootPath().getSegmentsList().isEmpty(), is(true)); assertThat(paths.createRootPath().getSegmentsList().size(), is(0)); assertThat(paths.createRootPath().getSegmentsArray().length, is(0)); assertThat(paths.createRootPath().size(), is(0)); }
/** * 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); }
@Test public void shouldNormalizeRelativePathWithMultipleSegmentIncludingSelfAndParent() { assertThat(paths.create("A/B/C[1]/../D[2]/./E/..").getNormalizedPath(), is(paths.create("A/B/D[2]"))); assertThat(paths.create("A/B/C[1]/././D[2]").getNormalizedPath(), is(paths.create("A/B/C/D[2]"))); assertThat(paths.create("A/../../../B").getNormalizedPath(), is(paths.create("../../B"))); assertThat(paths.create("../../B").getNormalizedPath(), is(paths.create("../../B"))); assertThat(paths.create("./B").getNormalizedPath(), is(paths.create("B"))); assertThat(paths.create("A/./../../B/.").getNormalizedPath(), is(paths.create("../B"))); }
protected Path getPath() { if (parent == null) return pathFactory().createRootPath(); return pathFactory().create(parent.getPath(), name); }
/** * Index all of the content in the named workspace within the {@link #getSourceName() source}. This method operates * synchronously and returns when the requested indexing is completed. * * @param workspaceName the name of the workspace * @return this object for convenience in method chaining; never null * @throws IllegalArgumentException if the context or workspace name is null, or if the depth per read is not positive * @throws RepositorySourceException if there is a problem accessing the content * @throws SearchEngineException if there is a problem updating the indexes * @throws InvalidWorkspaceException if the workspace does not exist */ public SearchEngineIndexer index( String workspaceName ) throws RepositorySourceException, SearchEngineException { Path rootPath = context.getValueFactories().getPathFactory().createRootPath(); index(workspaceName, Location.create(rootPath)); return this; }
@Factory public static Matcher<Iterable<Segment>> hasSegment( PathFactory pathFactory, String element ) { Path.Segment segment = pathFactory.createSegment(element); return hasSegment(equalTo(segment)); }
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; }
@Test public void shouldProjectPathBelowSourcePathIntoPathBelowRepositoryPath() { Path pathInRepository = pathFactory.create(repositoryPath, "m/n"); Path pathInSource = pathFactory.create(sourcePath, "m/n"); assertThat(rule.projectPathInSourceToPathInRepository(pathInSource, pathFactory), is(pathInRepository)); pathInRepository = pathFactory.create(repositoryPath, "m"); pathInSource = pathFactory.create(sourcePath, "m"); assertThat(rule.projectPathInSourceToPathInRepository(pathInSource, pathFactory), is(pathInRepository)); pathInRepository = pathFactory.create(repositoryPath, "m/n[3]"); pathInSource = pathFactory.create(sourcePath, "m/n[3]"); assertThat(rule.projectPathInSourceToPathInRepository(pathInSource, pathFactory), is(pathInRepository)); }
@Test public void shouldParsePathRuleFromDefinitionWithRootRepositoryPathAndNonRootSourcePath() { Projection.Rule rule = Projection.parsePathRule("/ => /b", context); assertThat(rule, is(instanceOf(Projection.PathRule.class))); Projection.PathRule pathRule = (Projection.PathRule)rule; assertThat(pathRule.getPathInRepository(), is(pathFactory.createRootPath())); assertThat(pathRule.getPathInSource(), is(pathFactory.create("/b"))); }
protected BaseTransaction( ExecutionContext context, Repository<NodeType, WorkspaceType> repository, UUID rootNodeUuid ) { this.rootNodeUuid = rootNodeUuid; this.context = context; this.propertyFactory = context.getPropertyFactory(); this.valueFactories = context.getValueFactories(); this.pathFactory = valueFactories.getPathFactory(); this.nameFactory = valueFactories.getNameFactory(); this.repository = repository; this.rootLocation = Location.create(pathFactory.createRootPath(), rootNodeUuid); }
/** * Utility to create a {@link Path.Segment} from a string, where there will be no index * * @param name the string form of the path segment, which may include a 1-based same-name-sibling index * @return the path object * @throws ValueFormatException if a path could not be created from the supplied string */ protected Path.Segment segment( String name ) { return context.getValueFactories().getPathFactory().createSegment(name); }
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()); }
@Test public void shouldGetPathsInSourceGivenPathInRepositoryAndMultipleApplicableRules() { Path pathInRepository = pathFactory.create("/a/b/c"); Path pathInSource1 = pathFactory.create("/d/e/f"); Path pathInSource2 = pathFactory.create("/d/e/g"); Path pathInSource3 = pathFactory.create("/d/e/h"); when(mockRule1.getPathInSource(pathInRepository, pathFactory)).thenReturn(pathInSource1); when(mockRule2.getPathInSource(pathInRepository, pathFactory)).thenReturn(pathInSource2); when(mockRule3.getPathInSource(pathInRepository, pathFactory)).thenReturn(pathInSource3); Set<Path> pathsInSource = projection.getPathsInSource(pathInRepository, pathFactory); assertThat(pathsInSource, hasItems(pathInSource1, pathInSource2, pathInSource3)); }