Property defaultWorkspaceNameProperty = repositories.getRoot().getProperty(ModeShapeLexicon.DEFAULT_WORKSPACE_NAME); if (defaultWorkspaceNameProperty != null) { Property timeToExpire = repositories.getRoot().getProperty(ModeShapeLexicon.TIME_TO_EXPIRE); if (timeToExpire != null && !timeToExpire.isEmpty()) { long timeToCacheInMillis = longs.create(timeToExpire.getFirstValue()); Node workspacesNode = repositories.getNode(ModeShapeLexicon.WORKSPACES); if (workspacesNode == null) { I18n msg = GraphI18n.requiredNodeDoesNotExistRelativeToNode; throw new RepositorySourceException(msg.text(ModeShapeLexicon.WORKSPACES.getString(registry), repositories.getLocation().getPath().getString(registry), repositories.getGraph().getCurrentWorkspaceName(), repositories.getGraph().getSourceName())); SubgraphNode workspaceNode = repositories.getNode(workspace); Property workspaceNameProperty = workspaceNode.getProperty(ModeShapeLexicon.WORKSPACE_NAME); if (workspaceNameProperty != null) { .getPath() .getString(registry), repositories.getGraph().getCurrentWorkspaceName(), repositories.getGraph().getSourceName())); Node projectionNode = repositories.getNode(projection); sourceProjections.add(createProjection(executionContext, projectionParser, projectionNode));
/** * {@inheritDoc} * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals( Object obj ) { if (obj instanceof SubgraphResults) { SubgraphResults that = (SubgraphResults)obj; return getLocation().equals(that.getLocation()) && request.equals(that.request); } else if (obj instanceof Subgraph) { Subgraph that = (Subgraph)obj; if (!getLocation().equals(that.getLocation())) return false; Iterator<SubgraphNode> thisIter = this.iterator(); Iterator<SubgraphNode> thatIter = that.iterator(); while (thisIter.hasNext() && thatIter.hasNext()) { SubgraphNode thisNode = thisIter.next(); SubgraphNode thatNode = thatIter.next(); if (!thisNode.getLocation().equals(thatNode.getLocation())) return false; if (!thisNode.getProperties().equals(thatNode.getProperties())) return false; if (!thisNode.getChildren().equals(thatNode.getChildren())) return false; } if (thisIter.hasNext() || thatIter.hasNext()) return false; return true; } return false; }
if (subgraph1.getLocation().isSame(subgraph2.getLocation())) return; Path rootPath1 = subgraph1.getRoot().getLocation().getPath(); Path rootPath2 = subgraph2.getRoot().getLocation().getPath(); Iterator<SubgraphNode> iter1 = subgraph1.iterator(); Iterator<SubgraphNode> iter2 = subgraph2.iterator(); while (iter1.hasNext() && iter2.hasNext()) { Node node1 = iter1.next();
assertThat(subgraph.getMaximumDepth(), is(2)); assertThat(subgraph.getLocation(), is(Location.create(validPath))); Node root = subgraph.getNode(Location.create(validPath)); assertThat(root.getChildren(), hasItems(child1, child2, child3)); assertThat(root.getProperties(), hasItems(validIdProperty1, validIdProperty2)); Node node1 = subgraph.getNode(child1); assertThat(node1.getChildren(), hasItems(child11, child12, child13)); assertThat(node1.getProperties(), hasItems(validIdProperty1)); Node node2 = subgraph.getNode(child2); assertThat(node2.getChildren().isEmpty(), is(true)); assertThat(node2.getProperties(), hasItems(validIdProperty2)); Node node3 = subgraph.getNode(child3); assertThat(node3.getChildren().isEmpty(), is(true)); assertThat(node3.getProperties().isEmpty(), is(true)); assertThat(subgraph.getNode(child123), is(nullValue())); root = subgraph.getNode("./"); assertThat(root.getChildren(), hasItems(child1, child2, child3)); assertThat(root.getProperties(), hasItems(validIdProperty1, validIdProperty2)); node1 = subgraph.getNode("x"); assertThat(node1.getChildren(), hasItems(child11, child12, child13)); assertThat(node1.getProperties(), hasItems(validIdProperty1));
protected int countNodes( Subgraph subgraph ) { return countNodes(subgraph.getRoot(), subgraph); }
Location actualLocation = subgraph.getLocation(); if (!this.location.isSame(actualLocation)) { cache.nodeOperations.materialize(subgraph.getRoot(), this);
assertThat(subgraph.getMaximumDepth(), is(2)); Node root = subgraph.getNode("./"); assertThat(root.getChildren(), hasItems(child1, child2, child3)); assertThat(subgraph.toString(), is(expectedToStringValue));
CheckArg.isNotEmpty(projectionRules, "projectionRules"); String configPath = repositoryContext.getConfiguration(1) .getLocation() .getPath() .getString(context.getNamespaceRegistry());
/** * Traverse the saved configuration graph treating it as an XML document and calling the corresponding SAX event on the * provided {@link ContentHandler}. Changes made without calling {@link #save()} will not be written to the stream. * * @param handler the content handler that will receive the SAX events * @throws SAXException if there is an error saving the configuration */ public void storeTo( ContentHandler handler ) throws SAXException { Subgraph allContent = configurationGraph().getSubgraphOfDepth(ReadBranchRequest.NO_MAXIMUM_DEPTH).at("/"); Set<NamespaceRegistry.Namespace> namespaces = this.context.getNamespaceRegistry().getNamespaces(); Stack<String> mappedNamespacePrefixes = new Stack<String>(); handler.startDocument(); for (NamespaceRegistry.Namespace namespace : namespaces) { handler.startPrefixMapping(namespace.getPrefix(), namespace.getNamespaceUri()); mappedNamespacePrefixes.push(namespace.getPrefix()); } exportNode(handler, allContent, allContent.getRoot()); while (!mappedNamespacePrefixes.isEmpty()) { handler.endPrefixMapping(mappedNamespacePrefixes.pop()); } handler.endDocument(); }
protected boolean doUnregister( String uri ) { // Read the store ... ValueFactory<String> stringFactory = store.getContext().getValueFactories().getStringFactory(); boolean result = false; try { Subgraph nsGraph = store.getSubgraphOfDepth(2).at(parentOfNamespaceNodes); // Iterate over the existing mappings, looking for one that uses the prefix and uri ... Set<Location> locationsToRemove = new HashSet<Location>(); for (Location nsLocation : nsGraph.getRoot().getChildren()) { Node ns = nsGraph.getNode(nsLocation); String actualUri = stringFactory.create(ns.getProperty(uriPropertyName).getFirstValue()); if (actualUri.equals(uri)) { locationsToRemove.add(ns.getLocation()); result = true; } } // Remove any other nodes that have the same URI ... Graph.Batch batch = store.batch(); for (Location namespaceToRemove : locationsToRemove) { batch.delete(namespaceToRemove).and(); } // Execute all these changes ... batch.execute(); } catch (PathNotFoundException e) { // Nothing stored yet, so do nothing ... } return result; }
protected synchronized void startService() { if (this.started.get() == false) { // ------------------------------------------------------------------------------------ // Read the configuration ... // ------------------------------------------------------------------------------------ // Read the configuration and repository source nodes (children under "/dna:sources") ... Graph graph = Graph.create(getConfigurationSourceName(), sources, context); Path pathToSourcesNode = context.getValueFactories() .getPathFactory() .create(pathToConfigurationRoot, ModeShapeLexicon.SOURCES); try { String workspaceName = getConfigurationWorkspaceName(); if (workspaceName != null) graph.useWorkspace(workspaceName); Subgraph sourcesGraph = graph.getSubgraphOfDepth(ReadBranchRequest.NO_MAXIMUM_DEPTH).at(pathToSourcesNode); // Iterate over each of the children, and create the RepositorySource ... for (Location location : sourcesGraph.getRoot().getChildren()) { sources.addSource(createRepositorySource(sourcesGraph, location, problems)); } } catch (PathNotFoundException e) { // No sources were found, and this is okay! } catch (Throwable err) { throw new ModeShapeConfigurationException(RepositoryI18n.errorStartingRepositoryService.text(), err); } this.started.set(true); } }
Node clusterNode = subgraph.getNode(ModeShapeLexicon.CLUSTERING); if (clusterNode != null) {
ValueFactory<Boolean> booleanFactory = store.getContext().getValueFactories().getBooleanFactory(); Set<String> generatedPrefixes = null; for (Location nsLocation : nsGraph.getRoot().getChildren()) { Node ns = nsGraph.getNode(nsLocation); String prefix = getPrefixFor(nsLocation.getPath()); String uri = stringFactory.create(ns.getProperty(uriPropertyName).getFirstValue());
protected void merge( Graph actualGraph, Graph.Batch batch ) { CheckArg.isNotNull(actualGraph, "actualGraph"); // Read the initial content ... Subgraph subgraph = this.initialContent.getSubgraphOfDepth(Integer.MAX_VALUE).at("/"); SubgraphNode desiredNode = subgraph.getRoot(); // Go through all of the areas and ensure the nodes exist ... boolean checkProperties = true; if (desiredNode.getLocation().getPath().isRoot()) { // Don't need to check the root's properties ... checkProperties = false; } Path path = desiredNode.getLocation().getPath(); Node actualNode = actualGraph.getNodeAt(path); matchNode(batch, actualGraph, actualNode, desiredNode, checkProperties, true); }
protected void assertInitialData() { // Now check that the data is all there ... Subgraph subgraph = graph.getSubgraphOfDepth(10).at("/"); assertThat(subgraph, is(notNullValue())); assertThat(subgraph.getNode("/a").getProperty("propB").isSingle(), is(true)); assertThat(subgraph.getNode("/a").getProperty("propB").getFirstValue(), is((Object)"valueB")); assertThat(subgraph.getNode("/a").getProperty("propC").isSingle(), is(true)); assertThat(subgraph.getNode("/a").getProperty("propC").getFirstValue(), is((Object)"valueC")); assertThat(subgraph.getNode("/a/b").getProperty("propB").isSingle(), is(true)); assertThat(subgraph.getNode("/a/b").getProperty("propB").getFirstValue(), is((Object)"valueB")); assertThat(subgraph.getNode("/a/b").getProperty("propC").isSingle(), is(true)); assertThat(subgraph.getNode("/a/b").getProperty("propC").getFirstValue(), is((Object)"valueC")); assertThat(subgraph.getNode("/a/b/c").getProperty("propB").isSingle(), is(true)); assertThat(subgraph.getNode("/a/b/c").getProperty("propB").getFirstValue(), is((Object)"valueB")); assertThat(subgraph.getNode("/a/b/c").getProperty("propC").isSingle(), is(true)); assertThat(subgraph.getNode("/a/b/c").getProperty("propC").getFirstValue(), is((Object)"valueC")); assertThat(subgraph.getNode("/a/b/d").getProperty("propB").isSingle(), is(true)); assertThat(subgraph.getNode("/a/b/d").getProperty("propB").getFirstValue(), is((Object)"valueB")); assertThat(subgraph.getNode("/a/b/d").getProperty("propC").isSingle(), is(true)); assertThat(subgraph.getNode("/a/b/d").getProperty("propC").getFirstValue(), is((Object)"valueC")); assertThat(subgraph.getNode("/a").getChildrenSegments().size(), is(1)); assertThat(subgraph.getNode("/a").getChildrenSegments().get(0), is(segment("b"))); assertThat(subgraph.getNode("/a/b").getChildrenSegments().size(), is(2)); assertThat(subgraph.getNode("/a/b").getChildrenSegments().get(0), is(segment("c"))); assertThat(subgraph.getNode("/a/b").getChildrenSegments().get(1), is(segment("d"))); assertThat(subgraph.getNode("/a/b/c").getChildrenSegments().isEmpty(), is(true)); assertThat(subgraph.getNode("/a/b/d").getChildrenSegments().isEmpty(), is(true)); }