protected int countNodes( Subgraph subgraph ) { return countNodes(subgraph.getRoot(), subgraph); }
/** * 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(); }
for (Location nsLocation : nsGraph.getRoot().getChildren()) { Node ns = nsGraph.getNode(nsLocation); Path path = nsLocation.getPath();
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); } }
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); }
Subgraph nsGraph = store.getSubgraphOfDepth(2).at(parentOfNamespaceNodes); ValueFactory<String> stringFactory = store.getContext().getValueFactories().getStringFactory(); for (Location nsLocation : nsGraph.getRoot().getChildren()) { Node ns = nsGraph.getNode(nsLocation);
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());
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());
@Ignore @Test public void shouldReadSubgraphStartingAtRootAndWithMaximumDepthOfThree() { Subgraph subgraph = graph.getSubgraphOfDepth(3).at("/"); assertThat(subgraph, is(notNullValue())); // Verify that the root node is the same as getting it directly ... Node root = subgraph.getRoot(); assertSameNode(root, graph.getNodeAt("/")); // Verify the first-level children ... List<Location> children = graph.getChildren().of("/"); assertThat(children, is(notNullValue())); for (Location childLocation : children) { // Verify the child in the subgraph matches the same node obtained directly from the graph ... Node child = subgraph.getNode(childLocation); assertSameNode(child, graph.getNodeAt(childLocation)); // Now get the second-level children ... List<Location> grandChildren = graph.getChildren().of(childLocation); assertThat(grandChildren, is(notNullValue())); for (Location grandchildLocation : grandChildren) { // Verify the grandchild in the subgraph matches the same node obtained directly from the graph ... Node grandchild = subgraph.getNode(grandchildLocation); assertSameNode(grandchild, graph.getNodeAt(grandchildLocation)); // The subgraph should contain the children locations and properties for the grandchildren. // However, the subgraph should not a node for the children of the grandchildren ... for (Location greatGrandchild : grandchild.getChildren()) { assertThat(subgraph.getNode(greatGrandchild), is(nullValue())); } } } }
cache.nodeOperations.materialize(subgraph.getRoot(), this);