Author: rhauch
Date: 2009-06-10 17:22:34 -0400 (Wed, 10 Jun 2009)
New Revision: 1034
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositoryContext.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositorySource.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/FederatedRepositorySource.java
trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/AbstractFederatedRepositorySourceIntegrationTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/FederatedRepositorySourceTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/AbstractConnectorTest.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryLibrary.java
Log:
DNA-449 Federation connector does not find it's configuration when imported using the
JcrConfiguration
Change the RepositoryContext to expose a subgraph snapshot of the configuration. This is
not only easier to use, but it requires less setup and also prevents the RepositorySource
from changing the configuration content. Also added a note to the
RepositorySource.initialize(RepositoryContext) method that it may be called whenever the
configuration changes.
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositoryContext.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositoryContext.java 2009-06-10
21:22:09 UTC (rev 1033)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositoryContext.java 2009-06-10
21:22:34 UTC (rev 1034)
@@ -24,9 +24,8 @@
package org.jboss.dna.graph.connector;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.Subgraph;
import org.jboss.dna.graph.observe.Observer;
-import org.jboss.dna.graph.property.Path;
/**
* The context for a repository. This interface need not be implemented by a {@link
RepositorySource}, as it is normally provided
@@ -58,17 +57,11 @@
Observer getObserver();
/**
- * Get a graph to the configuration content, already configured to the correct
workspace.
+ * Get a snapshot of the current configuration for the {@link RepositorySource}. The
root of the subgraph will be the node in
+ * the configuration that represents the RepositorySource.
*
- * @return the configuration graph, or null if there is no configuration
+ * @param depth the max depth of the configuration subgraph
+ * @return the configuration snapshot as a subgraph, or null if there is no
configuration
*/
- Graph getConfiguration();
-
- /**
- * Get the path within the {@link #getConfiguration() configuration} where the source
is represented.
- *
- * @return the path to the {@link RepositorySource}'s configuration element, or
null if the source is not defined within the
- * configuration
- */
- Path getPathInConfiguration();
+ Subgraph getConfiguration( int depth );
}
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositorySource.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositorySource.java 2009-06-10
21:22:09 UTC (rev 1033)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositorySource.java 2009-06-10
21:22:34 UTC (rev 1034)
@@ -139,9 +139,13 @@
public interface RepositorySource extends Referenceable, Serializable {
/**
- * Initialize this source to use the supplied {@link RepositoryContext}, from which
this source can obtain
- * {@link RepositoryContext#getRepositoryConnectionFactory() connections} to other
{@link RepositorySource sources} as well as
- * {@link RepositoryContext#getExecutionContext() execution contexts}.
+ * Initialize this source to use the supplied {@link RepositoryContext}, from which
this source can obtain the
+ * {@link RepositoryContext#getConfiguration(int) configuration} defining this
source,
+ * {@link RepositoryContext#getRepositoryConnectionFactory() connections} to other
{@link RepositorySource sources}, and the
+ * {@link RepositoryContext#getExecutionContext() execution context}.
+ * <p>
+ * This method may be called each time the configuration changes, allowing the source
to update itself.
+ * </p>
*
* @param context
* @throws RepositorySourceException
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/FederatedRepositorySource.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/FederatedRepositorySource.java 2009-06-10
21:22:09 UTC (rev 1033)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/FederatedRepositorySource.java 2009-06-10
21:22:34 UTC (rev 1034)
@@ -43,7 +43,6 @@
import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.GraphI18n;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.Node;
@@ -178,12 +177,6 @@
throw new RepositorySourceException(getName(),
msg.text("name", name));
}
- // Make sure there is a configuration ...
- if (repositoryContext.getConfiguration() == null) {
- I18n msg =
GraphI18n.propertyIsRequiredForFederatedRepositorySource;
- throw new RepositorySourceException(getName(),
msg.text("configuration", name));
- }
-
// Load the configuration ...
this.configuration = loadRepository(name, repositoryContext);
}
@@ -279,7 +272,7 @@
}
/**
- * Utility to load the current configuration for this source from the {@link
RepositoryContext#getConfiguration()
+ * Utility to load the current configuration for this source from the {@link
RepositoryContext#getConfiguration(int)
* configuration repository}. This method may only be called after the source is
{@link #initialize(RepositoryContext)
* initialized}.
*
@@ -299,11 +292,6 @@
ProjectionParser projectionParser = ProjectionParser.getInstance();
NamespaceRegistry registry = executionContext.getNamespaceRegistry();
- Graph config = repositoryContext.getConfiguration();
- Path pathOfSource = repositoryContext.getPathInConfiguration();
- assert config != null;
- assert pathOfSource != null;
-
try {
// Read the configuration for the federated repository:
// Level 1: the node representing the federated repository
@@ -312,7 +300,7 @@
// Level 4: the "dna:projections" nodes
// Level 5: a node below "dna:projections" for each projection,
with properties for the source name,
// workspace name, cache expiration time, and projection rules
- Subgraph repositories = config.getSubgraphOfDepth(5).at(pathOfSource);
+ Subgraph repositories = repositoryContext.getConfiguration(5);
// Get the name of the default workspace ...
String defaultWorkspaceName = null;
@@ -336,8 +324,8 @@
I18n msg = GraphI18n.requiredNodeDoesNotExistRelativeToNode;
throw new
RepositorySourceException(msg.text(DnaLexicon.WORKSPACES.getString(registry),
repositories.getLocation().getPath().getString(registry),
-
config.getCurrentWorkspaceName(),
- config.getSourceName()));
+
repositories.getGraph().getCurrentWorkspaceName(),
+
repositories.getGraph().getSourceName()));
}
// Level 3: The workspace nodes ...
@@ -365,8 +353,8 @@
workspaceNode.getLocation()
.getPath()
.getString(registry),
-
config.getCurrentWorkspaceName(),
-
config.getSourceName()));
+
repositories.getGraph().getCurrentWorkspaceName(),
+
repositories.getGraph().getSourceName()));
}
// Level 5: the projection nodes ...
@@ -394,10 +382,7 @@
throw t; // rethrow
} catch (Throwable t) {
I18n msg = GraphI18n.errorReadingConfigurationForFederatedRepositorySource;
- String configSource = config.getSourceName();
- String configWorkspace = config.getCurrentWorkspaceName();
- String configPath = pathOfSource.getString(registry);
- throw new RepositorySourceException(getName(), msg.text(name, configSource,
configWorkspace, configPath), t);
+ throw new RepositorySourceException(getName(), msg.text(name), t);
}
}
Modified: trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties
===================================================================
--- trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties 2009-06-10
21:22:09 UTC (rev 1033)
+++ trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties 2009-06-10
21:22:34 UTC (rev 1034)
@@ -87,7 +87,7 @@
namePropertyIsRequiredForFederatedRepositorySource = The "{0}" property is
required on each federated repository source
propertyIsRequiredForFederatedRepositorySource = The "{0}" property is required
on the "{1}" federated repository source
federatedRepositorySourceMustBeInitialized = The "{0}" federated repository
source must be initialized before it can be used
-errorReadingConfigurationForFederatedRepositorySource = Error with the "{0}"
federated repository source's configuration at "{3}" in the "{2}"
workspace of "{1}"
+errorReadingConfigurationForFederatedRepositorySource = Error with the "{0}"
federated repository source's configuration
errorAddingProjectionRuleParseMethod = Error while adding a parsing method for a
federation projection rule
requiredNodeDoesNotExistRelativeToNode = The required node "{0}" does not exist
relative to "{1}" in "{2}" workspace of the "{3}"
repository
unableToObtainConnectionToFederatedSource = Unable to obtain a connection to source
"{0}" being federated by the "{1}" workspace of the "{2}"
federated repository
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/AbstractFederatedRepositorySourceIntegrationTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/AbstractFederatedRepositorySourceIntegrationTest.java 2009-06-10
21:22:09 UTC (rev 1033)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/AbstractFederatedRepositorySourceIntegrationTest.java 2009-06-10
21:22:34 UTC (rev 1034)
@@ -113,15 +113,11 @@
}
@SuppressWarnings( "synthetic-access" )
- public Graph getConfiguration() {
+ public Subgraph getConfiguration( int depth ) {
Graph result = Graph.create(configRepositorySource, context);
result.useWorkspace(configurationWorkspaceName);
- return result;
+ return result.getSubgraphOfDepth(depth).at("/a/b/Test
Repository");
}
-
- public Path getPathInConfiguration() {
- return
context.getValueFactories().getPathFactory().create("/a/b/Test Repository");
- }
};
// Set up the source ...
@@ -172,7 +168,10 @@
CheckArg.isNotNull(sourceName, "sourceName");
CheckArg.isNotNull(workspaceName, "workspaceName");
CheckArg.isNotEmpty(projectionRules, "projectionRules");
- String configPath =
repositoryContext.getPathInConfiguration().getString(context.getNamespaceRegistry());
+ String configPath = repositoryContext.getConfiguration(1)
+ .getLocation()
+ .getPath()
+ .getString(context.getNamespaceRegistry());
assertThat(configPath.endsWith("/"), is(false));
String wsPath = configPath + "/dna:workspaces/" + federatedWorkspace;
String projectionPath = wsPath + "/dna:projections/" + projectionName;
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/FederatedRepositorySourceTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/FederatedRepositorySourceTest.java 2009-06-10
21:22:09 UTC (rev 1033)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/FederatedRepositorySourceTest.java 2009-06-10
21:22:34 UTC (rev 1034)
@@ -42,12 +42,12 @@
import javax.security.auth.callback.CallbackHandler;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.Subgraph;
import org.jboss.dna.graph.connector.RepositoryConnection;
import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
import org.jboss.dna.graph.connector.RepositoryContext;
import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
import org.jboss.dna.graph.observe.Observer;
-import org.jboss.dna.graph.property.Path;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
@@ -100,16 +100,11 @@
}
@SuppressWarnings( "synthetic-access" )
- public Graph getConfiguration() {
+ public Subgraph getConfiguration( int depth ) {
Graph result = Graph.create(configRepositorySource, context);
result.useWorkspace("configSpace");
- return result;
+ return result.getSubgraphOfDepth(depth).at("/a/b/Test
Repository");
}
-
- @SuppressWarnings( "synthetic-access" )
- public Path getPathInConfiguration() {
- return
context.getValueFactories().getPathFactory().create("/a/b/Test Repository");
- }
};
source = new FederatedRepositorySource();
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/AbstractConnectorTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/AbstractConnectorTest.java 2009-06-10
21:22:09 UTC (rev 1033)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/AbstractConnectorTest.java 2009-06-10
21:22:34 UTC (rev 1034)
@@ -133,18 +133,15 @@
return null; // no observers here
}
- public Graph getConfiguration() {
- Graph result = null;
+ public Subgraph getConfiguration( int depth ) {
+ Subgraph result = null;
if (configSource != null) {
- result = Graph.create(configSource, getExecutionContext());
- // use the default workspace
+ Graph config = Graph.create(configSource,
getExecutionContext());
+ config.useWorkspace(null); // default workspace
+ result = config.getSubgraphOfDepth(depth).at(source.getName());
}
return result;
}
-
- public Path getPathInConfiguration() {
- return
getExecutionContext().getValueFactories().getPathFactory().create(source.getName());
- }
});
// And set up the graph instance ...
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryLibrary.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryLibrary.java 2009-06-10
21:22:09 UTC (rev 1033)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryLibrary.java 2009-06-10
21:22:34 UTC (rev 1034)
@@ -37,6 +37,7 @@
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.Subgraph;
import org.jboss.dna.graph.connector.RepositoryConnection;
import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
import org.jboss.dna.graph.connector.RepositoryConnectionPool;
@@ -396,30 +397,24 @@
/**
* {@inheritDoc}
*
- * @see
org.jboss.dna.graph.connector.RepositoryContext#getConfiguration()
+ * @see
org.jboss.dna.graph.connector.RepositoryContext#getConfiguration(int)
*/
- public Graph getConfiguration() {
- Graph result = null;
+ public Subgraph getConfiguration( int depth ) {
+ Subgraph result = null;
RepositorySource configSource = getConfigurationSource();
if (configSource != null) {
- result = Graph.create(configSource, getExecutionContext());
+ Graph config = Graph.create(configSource,
getExecutionContext());
String workspaceName = getConfigurationWorkspaceName();
if (workspaceName != null) {
- result.useWorkspace(workspaceName);
+ config.useWorkspace(workspaceName);
}
+ Path configPath = getPathToConfigurationRoot();
+ Path sourcePath =
getExecutionContext().getValueFactories().getPathFactory().create(configPath,
+
sourceName);
+ result = config.getSubgraphOfDepth(depth).at(sourcePath);
}
return result;
}
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.connector.RepositoryContext#getPathInConfiguration()
- */
- public Path getPathInConfiguration() {
- Path configPath = getPathToConfigurationRoot();
- return
getExecutionContext().getValueFactories().getPathFactory().create(configPath,
sourceName);
- }
};
source.initialize(repositoryContext);
RepositoryConnectionPool pool = new RepositoryConnectionPool(source);