Author: rhauch
Date: 2009-06-10 17:22:01 -0400 (Wed, 10 Jun 2009)
New Revision: 1032
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/federation/FederatedRepositorySource.java
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
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencer/SequencingServiceTest.java
Log:
DNA-449 Federation connector does not find it's configuration when imported using the
JcrConfiguration
Changed how the FederatedRepositorySource is reading its configuration to use the new
RepositoryContext approach.
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:21:36 UTC (rev 1031)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositoryContext.java 2009-06-10
21:22:01 UTC (rev 1032)
@@ -24,7 +24,9 @@
package org.jboss.dna.graph.connector;
import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.Graph;
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
@@ -54,4 +56,19 @@
* @return the observer, or null if the are no listeners and publishing is not
required/requested
*/
Observer getObserver();
+
+ /**
+ * Get a graph to the configuration content, already configured to the correct
workspace.
+ *
+ * @return the configuration graph, 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();
}
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:21:36 UTC (rev 1031)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/FederatedRepositorySource.java 2009-06-10
21:22:01 UTC (rev 1032)
@@ -74,24 +74,13 @@
*/
public static final int DEFAULT_RETRY_LIMIT = 0;
- /**
- * The default path to the node defining the configuration for a source.
- */
- public static final String DEFAULT_CONFIGURATION_PATH = "/";
-
protected static final String SOURCE_NAME = "sourceName";
protected static final String RETRY_LIMIT = "retryLimit";
- protected static final String CONFIGURATION_SOURCE_NAME =
"configurationSourceName";
- protected static final String CONFIGURATION_PATH = "configurationPath";
- protected static final String CONFIGURATION_WORKSPACE_NAME =
"configurationWorkspaceName";
private static final long serialVersionUID = 1L;
private volatile String name;
private volatile int retryLimit;
- private volatile String configurationSourceName;
- private volatile String configurationWorkspaceName;
- private volatile String configurationPath = DEFAULT_CONFIGURATION_PATH;
private volatile RepositorySourceCapabilities capabilities = new
RepositorySourceCapabilities(true, true, false, false, true);
private volatile transient FederatedRepository configuration;
private volatile transient RepositoryContext context;
@@ -140,114 +129,6 @@
}
/**
- * Get the name of the {@link RepositorySource} that should be used to create the
{@link FederatedRepository federated
- * repository configuration} as the configuration repository.
- * <p>
- * This is a required property.
- * </p>
- *
- * @return the name of the {@link RepositorySource} instance that should be used for
the configuration
- * @see #setConfigurationSourceName(String)
- * @see #getConfigurationWorkspaceName()
- * @see #getConfigurationPath()
- */
- public String getConfigurationSourceName() {
- return configurationSourceName;
- }
-
- /**
- * Set the name of the {@link RepositorySource} that should be used to create the
{@link FederatedRepository federated
- * repository configuration} as the configuration repository. The instance will be
retrieved from the
- * {@link RepositoryConnectionFactory} instance inside the {@link
RepositoryContext#getRepositoryConnectionFactory()
- * repository context} supplied during {@link
RepositorySource#initialize(RepositoryContext) initialization}.
- * <p>
- * This is a required property.
- * </p>
- *
- * @param sourceName the name of the {@link RepositorySource} instance that should be
used for the configuration, or null if
- * the federated repository instance is to be found in JNDI
- * @see #getConfigurationSourceName()
- * @see #setConfigurationPath(String)
- * @see #setConfigurationWorkspaceName(String)
- */
- public synchronized void setConfigurationSourceName( String sourceName ) {
- if (this.configurationSourceName == sourceName || this.configurationSourceName !=
null
- && this.configurationSourceName.equals(sourceName)) return; //
unchanged
- this.configurationSourceName = sourceName;
- changeConfiguration();
- }
-
- /**
- * Get the name of the workspace in the {@link #getConfigurationSourceName() source}
containing the configuration content for
- * this source. If this workspace name is null, the default workspace as defined by
that source will be used.
- *
- * @return the name of the configuration workspace, or null if the default workspace
for the
- * {@link #getConfigurationSourceName() configuration source} should be used
- * @see #getConfigurationSourceName()
- * @see #setConfigurationWorkspaceName(String)
- * @see #getConfigurationPath()
- */
- public String getConfigurationWorkspaceName() {
- return configurationWorkspaceName;
- }
-
- /**
- * Set the name of the workspace in the {@link #getConfigurationSourceName() source}
containing the configuration content for
- * this source. If this workspace name is null, the default workspace as defined by
that source will be used.
- *
- * @param workspaceName the name of the configuration workspace, or null if the
default workspace for the
- * {@link #getConfigurationSourceName() configuration source} should be used
- * @see #setConfigurationSourceName(String)
- * @see #setConfigurationPath(String)
- * @see #getConfigurationWorkspaceName()
- */
- public synchronized void setConfigurationWorkspaceName( String workspaceName ) {
- if (this.configurationWorkspaceName == workspaceName ||
this.configurationWorkspaceName != null
- && this.configurationWorkspaceName.equals(workspaceName)) return; //
unchanged
- this.configurationWorkspaceName = workspaceName;
- changeConfiguration();
- }
-
- /**
- * Get the path in the {@link #getConfigurationWorkspaceName() workspace} of the
{@link #getConfigurationSourceName()
- * configuration source} where this source can find the content defining its
configuration.
- * <p>
- * This is a required property.
- * </p>
- *
- * @return the string array of projection rules, or null if the projection rules
haven't yet been set or if the federated
- * repository instance is to be found in JNDI
- * @see #getConfigurationSourceName()
- * @see #getConfigurationWorkspaceName()
- * @see #setConfigurationPath(String)
- */
- public String getConfigurationPath() {
- return configurationPath;
- }
-
- /**
- * Set the path in the {@link #getConfigurationWorkspaceName() workspace} of the
{@link #getConfigurationSourceName()
- * configuration source} where this source can find the content defining its
configuration.
- * <p>
- * This is a required property.
- * </p>
- *
- * @param pathInSourceToConfigurationRoot the path within the configuration source to
the node that should be the root of the
- * configuration information, or null if the {@link
#DEFAULT_CONFIGURATION_PATH default path} should be used
- * @see #getConfigurationPath()
- * @see #setConfigurationSourceName(String)
- * @see #setConfigurationWorkspaceName(String)
- */
- public void setConfigurationPath( String pathInSourceToConfigurationRoot ) {
- if (this.configurationPath == pathInSourceToConfigurationRoot ||
this.configurationPath != null
- && this.configurationPath.equals(pathInSourceToConfigurationRoot))
return;
- String path = pathInSourceToConfigurationRoot != null ?
pathInSourceToConfigurationRoot : DEFAULT_CONFIGURATION_PATH;
- // Ensure one leading slash and one trailing slashes ...
- this.configurationPath = path = ("/" +
path).replaceAll("^/+", "/").replaceAll("/+$", "")
+ "/";
- changeConfiguration();
- }
-
- /**
* {@inheritDoc}
*
* @see org.jboss.dna.graph.connector.RepositorySource#getCapabilities()
@@ -296,16 +177,15 @@
I18n msg = GraphI18n.federatedRepositorySourceMustBeInitialized;
throw new RepositorySourceException(getName(),
msg.text("name", name));
}
- String configSource = getConfigurationSourceName();
- String configWorkspace = getConfigurationWorkspaceName();
- String configPath = getConfigurationPath();
- if (configSource == null) {
+
+ // Make sure there is a configuration ...
+ if (repositoryContext.getConfiguration() == null) {
I18n msg =
GraphI18n.propertyIsRequiredForFederatedRepositorySource;
- throw new RepositorySourceException(getName(),
msg.text("configuration source name", name));
+ throw new RepositorySourceException(getName(),
msg.text("configuration", name));
}
// Load the configuration ...
- this.configuration = loadRepository(name, repositoryContext,
configSource, configWorkspace, configPath);
+ this.configuration = loadRepository(name, repositoryContext);
}
config = this.configuration;
}
@@ -326,9 +206,6 @@
ref.add(new StringRefAddr(SOURCE_NAME, getName()));
ref.add(new StringRefAddr(RETRY_LIMIT, Integer.toString(getRetryLimit())));
- ref.add(new StringRefAddr(CONFIGURATION_SOURCE_NAME,
getConfigurationSourceName()));
- ref.add(new StringRefAddr(CONFIGURATION_WORKSPACE_NAME,
getConfigurationWorkspaceName()));
- ref.add(new StringRefAddr(CONFIGURATION_PATH, getConfigurationPath()));
return ref;
}
@@ -356,16 +233,10 @@
}
String sourceName = values.get(SOURCE_NAME);
String retryLimit = values.get(RETRY_LIMIT);
- String configSourceName = values.get(CONFIGURATION_SOURCE_NAME);
- String configSourceWorkspace = values.get(CONFIGURATION_WORKSPACE_NAME);
- String configSourcePath = values.get(CONFIGURATION_PATH);
// Create the source instance ...
FederatedRepositorySource source = new FederatedRepositorySource();
if (sourceName != null) source.setName(sourceName);
- if (configSourceName != null)
source.setConfigurationSourceName(configSourceName);
- if (configSourceWorkspace != null)
source.setConfigurationWorkspaceName(configSourceWorkspace);
- if (configSourcePath != null) source.setConfigurationPath(configSourcePath);
if (retryLimit != null) source.setRetryLimit(Integer.parseInt(retryLimit));
return source;
}
@@ -408,23 +279,17 @@
}
/**
- * Utility to load the current configuration for this source from the {@link
#getConfigurationSourceName() configuration
- * repository}. This method may only be called after the source is {@link
#initialize(RepositoryContext) initialized}.
+ * Utility to load the current configuration for this source from the {@link
RepositoryContext#getConfiguration()
+ * configuration repository}. This method may only be called after the source is
{@link #initialize(RepositoryContext)
+ * initialized}.
*
* @param name the name of the source; may not be null
* @param repositoryContext the repository context; may not be null
- * @param configSource the name of the configuration source; may not be null
- * @param configWorkspace the name of the workspace in the configuration source, or
null if the configuration source's default
- * workspace should be used
- * @param configPath the path to the node in the configuration workspace that defines
the source; may not be null
* @return the configuration; never null
* @throws RepositorySourceException if there is a problem with the configuration
*/
protected FederatedRepository loadRepository( String name,
- RepositoryContext repositoryContext,
- String configSource,
- String configWorkspace,
- String configPath ) throws
RepositorySourceException {
+ RepositoryContext repositoryContext )
throws RepositorySourceException {
// All the required properties have been set ...
ExecutionContext executionContext = repositoryContext.getExecutionContext();
RepositoryConnectionFactory connectionFactory =
repositoryContext.getRepositoryConnectionFactory();
@@ -434,14 +299,12 @@
ProjectionParser projectionParser = ProjectionParser.getInstance();
NamespaceRegistry registry = executionContext.getNamespaceRegistry();
- try {
- Graph config = Graph.create(configSource, connectionFactory,
executionContext);
- if (configWorkspace != null) {
- configWorkspace = config.useWorkspace(configWorkspace).getName();
- } else {
- configWorkspace = config.getCurrentWorkspaceName();
- }
+ 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
// Level 2: the "dna:workspaces" node
@@ -449,7 +312,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(configPath);
+ Subgraph repositories = config.getSubgraphOfDepth(5).at(pathOfSource);
// Get the name of the default workspace ...
String defaultWorkspaceName = null;
@@ -473,8 +336,8 @@
I18n msg = GraphI18n.requiredNodeDoesNotExistRelativeToNode;
throw new
RepositorySourceException(msg.text(DnaLexicon.WORKSPACES.getString(registry),
repositories.getLocation().getPath().getString(registry),
- configWorkspace,
- configSource));
+
config.getCurrentWorkspaceName(),
+ config.getSourceName()));
}
// Level 3: The workspace nodes ...
@@ -502,8 +365,8 @@
workspaceNode.getLocation()
.getPath()
.getString(registry),
-
configWorkspace,
-
configSource));
+
config.getCurrentWorkspaceName(),
+
config.getSourceName()));
}
// Level 5: the projection nodes ...
@@ -531,6 +394,9 @@
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);
}
}
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:21:36 UTC (rev 1031)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/AbstractFederatedRepositorySourceIntegrationTest.java 2009-06-10
21:22:01 UTC (rev 1032)
@@ -43,6 +43,7 @@
import org.jboss.dna.graph.connector.RepositoryContext;
import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
import org.jboss.dna.graph.connector.test.AbstractConnectorTest;
+import org.jboss.dna.graph.observe.Observer;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.PathNotFoundException;
@@ -72,10 +73,9 @@
protected ExecutionContext context;
private Map<String, InMemoryRepositorySource> sources;
protected Graph federated;
+ private RepositoryContext repositoryContext;
@Mock
private RepositoryConnectionFactory connectionFactory;
- @Mock
- private RepositoryContext repositoryContext;
/**
* @throws java.lang.Exception
@@ -88,16 +88,6 @@
configurationWorkspaceName = "configSpace";
repositoryName = "Test Repository";
- // Set up the source ...
- source = new FederatedRepositorySource();
- source.setName(repositoryName);
- sourceName = "federated source";
- source.setName(sourceName);
- source.setConfigurationSourceName(configurationSourceName);
- source.setConfigurationWorkspaceName(configurationWorkspaceName);
- source.setConfigurationPath("/a/b/Test Repository");
- source.initialize(repositoryContext);
-
// Set up the configuration repository ...
configRepositorySource = new InMemoryRepositorySource();
configRepositorySource.setName("Configuration Repository");
@@ -108,13 +98,44 @@
config.create("/a/b/Test Repository");
config.create("/a/b/Test Repository/dna:workspaces");
+ repositoryContext = new RepositoryContext() {
+ public ExecutionContext getExecutionContext() {
+ return context;
+ }
+
+ public Observer getObserver() {
+ return null;
+ }
+
+ @SuppressWarnings( "synthetic-access" )
+ public RepositoryConnectionFactory getRepositoryConnectionFactory() {
+ return connectionFactory;
+ }
+
+ @SuppressWarnings( "synthetic-access" )
+ public Graph getConfiguration() {
+ Graph result = Graph.create(configRepositorySource, context);
+ result.useWorkspace(configurationWorkspaceName);
+ return result;
+ }
+
+ public Path getPathInConfiguration() {
+ return
context.getValueFactories().getPathFactory().create("/a/b/Test Repository");
+ }
+ };
+
+ // Set up the source ...
+ source = new FederatedRepositorySource();
+ source.setName(repositoryName);
+ sourceName = "federated source";
+ source.setName(sourceName);
+ source.initialize(repositoryContext);
+
// Set up the map of sources ...
sources = new HashMap<String, InMemoryRepositorySource>();
// Stub the RepositoryContext and RepositoryConnectionFactory instances ...
configRepositoryConnection = configRepositorySource.getConnection();
- stub(repositoryContext.getExecutionContext()).toReturn(context);
-
stub(repositoryContext.getRepositoryConnectionFactory()).toReturn(connectionFactory);
stub(connectionFactory.createConnection(configurationSourceName)).toReturn(configRepositoryConnection);
stub(connectionFactory.createConnection(sourceName)).toAnswer(new
Answer<RepositoryConnection>() {
public RepositoryConnection answer( InvocationOnMock invocation ) throws
Throwable {
@@ -151,16 +172,19 @@
CheckArg.isNotNull(sourceName, "sourceName");
CheckArg.isNotNull(workspaceName, "workspaceName");
CheckArg.isNotEmpty(projectionRules, "projectionRules");
- assertThat(source.getConfigurationPath().endsWith("/"), is(true));
- String wsPath = source.getConfigurationPath() + "dna:workspaces/" +
federatedWorkspace;
+ String configPath =
repositoryContext.getPathInConfiguration().getString(context.getNamespaceRegistry());
+ assertThat(configPath.endsWith("/"), is(false));
+ String wsPath = configPath + "/dna:workspaces/" + federatedWorkspace;
String projectionPath = wsPath + "/dna:projections/" + projectionName;
Graph config = Graph.create(configRepositorySource, context);
config.useWorkspace(configurationWorkspaceName);
config.createIfMissing(wsPath);
config.createIfMissing(wsPath + "/dna:projections");
- config.createAt(projectionPath).with(FederatedLexicon.PROJECTION_RULES,
(Object[])projectionRules).with(FederatedLexicon.SOURCE_NAME,
-
sourceName).with(FederatedLexicon.WORKSPACE_NAME,
-
workspaceName).and();
+ config.createAt(projectionPath)
+ .with(FederatedLexicon.PROJECTION_RULES, (Object[])projectionRules)
+ .with(FederatedLexicon.SOURCE_NAME, sourceName)
+ .with(FederatedLexicon.WORKSPACE_NAME, workspaceName)
+ .and();
// Make sure the source and workspace exist ...
graphFor(sourceName, workspaceName);
}
@@ -258,8 +282,10 @@
Path fedPath = fedNode.getLocation().getPath();
Path sourcePath = sourceNode.getLocation().getPath();
if (!fedPath.isRoot() && !sourcePath.isRoot()) {
- assertThat(fedNode.getLocation().getPath().getLastSegment().getName(),
-
is(sourceNode.getLocation().getPath().getLastSegment().getName()));
+ assertThat(fedNode.getLocation().getPath().getLastSegment().getName(),
is(sourceNode.getLocation()
+
.getPath()
+
.getLastSegment()
+
.getName()));
}
// The children should match ...
List<Path.Segment> fedChildren = new ArrayList<Path.Segment>();
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:21:36 UTC (rev 1031)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/FederatedRepositorySourceTest.java 2009-06-10
21:22:01 UTC (rev 1032)
@@ -46,6 +46,8 @@
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;
@@ -68,7 +70,6 @@
private RepositoryConnection connection;
@Mock
private RepositoryConnectionFactory connectionFactory;
- @Mock
private RepositoryContext repositoryContext;
/**
@@ -80,16 +81,42 @@
context = new ExecutionContext();
configurationSourceName = "configuration";
repositoryName = "Test Repository";
+ configRepositorySource = new InMemoryRepositorySource();
+ configRepositorySource.setName("Configuration Repository");
+
+ repositoryContext = new RepositoryContext() {
+ @SuppressWarnings( "synthetic-access" )
+ public ExecutionContext getExecutionContext() {
+ return context;
+ }
+
+ public Observer getObserver() {
+ return null;
+ }
+
+ @SuppressWarnings( "synthetic-access" )
+ public RepositoryConnectionFactory getRepositoryConnectionFactory() {
+ return connectionFactory;
+ }
+
+ @SuppressWarnings( "synthetic-access" )
+ public Graph getConfiguration() {
+ Graph result = Graph.create(configRepositorySource, context);
+ result.useWorkspace("configSpace");
+ return result;
+ }
+
+ @SuppressWarnings( "synthetic-access" )
+ public Path getPathInConfiguration() {
+ return
context.getValueFactories().getPathFactory().create("/a/b/Test Repository");
+ }
+ };
+
source = new FederatedRepositorySource();
source.setName(repositoryName);
sourceName = "federated source";
source.setName(sourceName);
- source.setConfigurationSourceName(configurationSourceName);
- source.setConfigurationWorkspaceName("configSpace");
- source.setConfigurationPath("/a/b/Test Repository");
source.initialize(repositoryContext);
- configRepositorySource = new InMemoryRepositorySource();
- configRepositorySource.setName("Configuration Repository");
Graph configRepository = Graph.create(configRepositorySource, context);
configRepository.createWorkspace().named("configSpace");
@@ -99,24 +126,26 @@
batch.create("/a/b/Test
Repository").with(FederatedLexicon.DEFAULT_WORKSPACE_NAME,
"fedSpace").and();
batch.create("/a/b/Test Repository/dna:workspaces").and();
batch.create("/a/b/Test Repository/dna:workspaces/fedSpace").and();
- batch.create("/a/b/Test
Repository/dna:workspaces/fedSpace/dna:cache").with(FederatedLexicon.PROJECTION_RULES,
"/ => /").with(FederatedLexicon.SOURCE_NAME,
-
"cache
source").with(FederatedLexicon.WORKSPACE_NAME,
-
"cacheSpace").with(FederatedLexicon.TIME_TO_EXPIRE,
-
100000).and();
+ batch.create("/a/b/Test Repository/dna:workspaces/fedSpace/dna:cache")
+ .with(FederatedLexicon.PROJECTION_RULES, "/ => /")
+ .with(FederatedLexicon.SOURCE_NAME, "cache source")
+ .with(FederatedLexicon.WORKSPACE_NAME, "cacheSpace")
+ .with(FederatedLexicon.TIME_TO_EXPIRE, 100000)
+ .and();
batch.create("/a/b/Test
Repository/dna:workspaces/fedSpace/dna:projections").and();
- batch.create("/a/b/Test
Repository/dna:workspaces/fedSpace/dna:projections/projection1").with(FederatedLexicon.PROJECTION_RULES,
-
"/ => /s1").with(FederatedLexicon.SOURCE_NAME,
-
"source 1").with(FederatedLexicon.WORKSPACE_NAME,
-
"s1 workspace").and();
- batch.create("/a/b/Test
Repository/dna:workspaces/fedSpace/dna:projections/projection2").with(FederatedLexicon.PROJECTION_RULES,
-
"/ => /s2").with(FederatedLexicon.SOURCE_NAME,
-
"source 2").with(FederatedLexicon.WORKSPACE_NAME,
-
"s2 worskspace").and();
+ batch.create("/a/b/Test
Repository/dna:workspaces/fedSpace/dna:projections/projection1")
+ .with(FederatedLexicon.PROJECTION_RULES, "/ => /s1")
+ .with(FederatedLexicon.SOURCE_NAME, "source 1")
+ .with(FederatedLexicon.WORKSPACE_NAME, "s1 workspace")
+ .and();
+ batch.create("/a/b/Test
Repository/dna:workspaces/fedSpace/dna:projections/projection2")
+ .with(FederatedLexicon.PROJECTION_RULES, "/ => /s2")
+ .with(FederatedLexicon.SOURCE_NAME, "source 2")
+ .with(FederatedLexicon.WORKSPACE_NAME, "s2 worskspace")
+ .and();
batch.execute();
configRepositoryConnection = configRepositorySource.getConnection();
- stub(repositoryContext.getExecutionContext()).toReturn(context);
-
stub(repositoryContext.getRepositoryConnectionFactory()).toReturn(connectionFactory);
stub(connectionFactory.createConnection(configurationSourceName)).toReturn(configRepositoryConnection);
}
@@ -199,8 +228,6 @@
int retryLimit = 100;
source.setRetryLimit(retryLimit);
source.setName("Some source");
- source.setConfigurationSourceName("config source");
- source.setConfigurationPath("/a/b/c");
Reference ref = source.getReference();
assertThat(ref.getClassName(), is(FederatedRepositorySource.class.getName()));
@@ -215,11 +242,6 @@
assertThat((String)refAttributes.remove(FederatedRepositorySource.SOURCE_NAME),
is(source.getName()));
assertThat((String)refAttributes.remove(FederatedRepositorySource.RETRY_LIMIT),
is(Integer.toString(retryLimit)));
-
assertThat((String)refAttributes.remove(FederatedRepositorySource.CONFIGURATION_WORKSPACE_NAME),
- is(source.getConfigurationWorkspaceName()));
-
assertThat((String)refAttributes.remove(FederatedRepositorySource.CONFIGURATION_SOURCE_NAME),
- is(source.getConfigurationSourceName()));
-
assertThat((String)refAttributes.remove(FederatedRepositorySource.CONFIGURATION_PATH),
is("/a/b/c/"));
assertThat(refAttributes.isEmpty(), is(true));
// Recreate the object, use a newly constructed source ...
@@ -232,9 +254,6 @@
assertThat(recoveredSource.getName(), is(source.getName()));
assertThat(recoveredSource.getRetryLimit(), is(source.getRetryLimit()));
- assertThat(recoveredSource.getConfigurationSourceName(),
is(source.getConfigurationSourceName()));
- assertThat(recoveredSource.getConfigurationWorkspaceName(),
is(source.getConfigurationWorkspaceName()));
- assertThat(recoveredSource.getConfigurationPath(),
is(source.getConfigurationPath()));
assertThat(recoveredSource.equals(source), is(true));
assertThat(source.equals(recoveredSource), is(true));
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:21:36 UTC (rev 1031)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/AbstractConnectorTest.java 2009-06-10
21:22:01 UTC (rev 1032)
@@ -83,6 +83,7 @@
protected static ExecutionContext context;
protected static RepositorySource source;
protected static Graph graph;
+ protected static RepositorySource configSource;
private static RepositoryConnectionFactory connectionFactory;
private static List<RepositoryConnection> openConnections;
private static boolean running;
@@ -96,6 +97,9 @@
// Set up the execution context ...
context = setUpExecutionContext(new ExecutionContext());
+ // Set up the configuration source ...
+ configSource = setUpConfigurationSource();
+
// Set up the source ...
source = setUpSource();
@@ -128,6 +132,19 @@
public Observer getObserver() {
return null; // no observers here
}
+
+ public Graph getConfiguration() {
+ Graph result = null;
+ if (configSource != null) {
+ result = Graph.create(configSource, getExecutionContext());
+ // use the default workspace
+ }
+ return result;
+ }
+
+ public Path getPathInConfiguration() {
+ return
getExecutionContext().getValueFactories().getPathFactory().create(source.getName());
+ }
});
// And set up the graph instance ...
@@ -200,6 +217,17 @@
}
/**
+ * Set up a {@link RepositorySource} that contains the configuration for the source
being tested (and any other sources, if
+ * needed). The source's default workspace will be used. This implementation
returns null by default.
+ *
+ * @return the configuration source, or null if no configuration is needed
+ * @throws Exception if there is a problem setting up the source
+ */
+ protected RepositorySource setUpConfigurationSource() throws Exception {
+ return null;
+ }
+
+ /**
* Set up a {@link RepositorySource} that should be used for each of the unit tests.
*
* @return the repository source
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:21:36 UTC (rev 1031)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryLibrary.java 2009-06-10
21:22:01 UTC (rev 1032)
@@ -36,6 +36,7 @@
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.connector.RepositoryConnection;
import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
import org.jboss.dna.graph.connector.RepositoryConnectionPool;
@@ -46,6 +47,7 @@
import org.jboss.dna.graph.observe.Changes;
import org.jboss.dna.graph.observe.Observable;
import org.jboss.dna.graph.observe.Observer;
+import org.jboss.dna.graph.property.Path;
import org.jboss.dna.repository.service.AbstractServiceAdministrator;
import org.jboss.dna.repository.service.ServiceAdministrator;
@@ -110,49 +112,56 @@
private final CopyOnWriteArrayList<RepositoryConnectionPool> pools = new
CopyOnWriteArrayList<RepositoryConnectionPool>();
private RepositoryConnectionFactory delegate;
private final ExecutionContext executionContext;
- private final RepositoryContext repositoryContext;
private final ObservationBus observationBus = new InMemoryObservationBus();
+ private final RepositorySource configurationSource;
+ private final String configurationWorkspaceName;
+ private final Path pathToConfigurationRoot;
/**
* Create a new manager instance.
*
- * @param executionContext the execution context, which can be used used by sources
to create other {@link ExecutionContext}
- * instances with different JAAS security contexts
+ * @param configurationSource the {@link RepositorySource} that is the configuration
repository
+ * @param configurationWorkspaceName the name of the workspace in the {@link
RepositorySource} that is the configuration
+ * repository, or null if the default workspace of the source should be used
(if there is one)
+ * @param pathToSourcesConfigurationRoot the path of the node in the configuration
source repository that should be treated by
+ * this service as the root of the service's configuration; if null, then
"/dna:system" is used
+ * @param context the execution context in which this service should run
* @throws IllegalArgumentException if the
<code>executionContextFactory</code> reference is null
*/
- public RepositoryLibrary( final ExecutionContext executionContext ) {
- CheckArg.isNotNull(executionContext, "executionContext");
- this.executionContext = executionContext;
- final ObservationBus observationBus = this.observationBus;
- this.repositoryContext = new RepositoryContext() {
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.connector.RepositoryContext#getExecutionContext()
- */
- public ExecutionContext getExecutionContext() {
- return executionContext;
- }
+ public RepositoryLibrary( RepositorySource configurationSource,
+ String configurationWorkspaceName,
+ Path pathToSourcesConfigurationRoot,
+ final ExecutionContext context ) {
+ CheckArg.isNotNull(configurationSource, "configurationSource");
+ CheckArg.isNotNull(context, "context");
+ CheckArg.isNotNull(pathToSourcesConfigurationRoot,
"pathToSourcesConfigurationRoot");
+ this.executionContext = context;
+ this.configurationSource = configurationSource;
+ this.configurationWorkspaceName = configurationWorkspaceName;
+ this.pathToConfigurationRoot = pathToSourcesConfigurationRoot;
+ }
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.connector.RepositoryContext#getRepositoryConnectionFactory()
- */
- public RepositoryConnectionFactory getRepositoryConnectionFactory() {
- return RepositoryLibrary.this;
- }
+ /**
+ * Get the path to the top-level of the configuration root.
+ *
+ * @return pathToConfigurationRoot
+ */
+ protected Path getPathToConfigurationRoot() {
+ return pathToConfigurationRoot;
+ }
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.connector.RepositoryContext#getObserver()
- */
- public Observer getObserver() {
- return observationBus.hasObservers() ? observationBus : null;
- }
+ /**
+ * @return configurationSource
+ */
+ protected RepositorySource getConfigurationSource() {
+ return configurationSource;
+ }
- };
+ /**
+ * @return configurationWorkspaceName
+ */
+ protected String getConfigurationWorkspaceName() {
+ return configurationWorkspaceName;
}
/**
@@ -350,9 +359,68 @@
if (source == null) return false;
try {
this.sourcesLock.writeLock().lock();
+ final String sourceName = source.getName();
for (RepositoryConnectionPool existingPool : this.pools) {
- if
(existingPool.getRepositorySource().getName().equals(source.getName())) return false;
+ if (existingPool.getRepositorySource().getName().equals(sourceName))
return false;
}
+ // Create a repository context for this source ...
+ final ObservationBus observationBus = this.observationBus;
+ RepositoryContext repositoryContext = new RepositoryContext() {
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.connector.RepositoryContext#getExecutionContext()
+ */
+ public ExecutionContext getExecutionContext() {
+ return getExecutionContext();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.connector.RepositoryContext#getRepositoryConnectionFactory()
+ */
+ public RepositoryConnectionFactory getRepositoryConnectionFactory() {
+ return RepositoryLibrary.this;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositoryContext#getObserver()
+ */
+ public Observer getObserver() {
+ return observationBus.hasObservers() ? observationBus : null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.connector.RepositoryContext#getConfiguration()
+ */
+ public Graph getConfiguration() {
+ Graph result = null;
+ RepositorySource configSource = getConfigurationSource();
+ if (configSource != null) {
+ result = Graph.create(configSource, getExecutionContext());
+ String workspaceName = getConfigurationWorkspaceName();
+ if (workspaceName != null) {
+ result.useWorkspace(workspaceName);
+ }
+ }
+ 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);
this.pools.add(pool);
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java 2009-06-10
21:21:36 UTC (rev 1031)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java 2009-06-10
21:22:01 UTC (rev 1032)
@@ -44,6 +44,7 @@
import org.jboss.dna.graph.connector.RepositorySource;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.property.PathFactory;
import org.jboss.dna.graph.property.PathNotFoundException;
import org.jboss.dna.graph.property.Property;
import org.jboss.dna.graph.property.PropertyType;
@@ -124,10 +125,11 @@
ExecutionContext context ) {
CheckArg.isNotNull(configurationSource, "configurationSource");
CheckArg.isNotNull(context, "context");
- if (pathToConfigurationRoot == null) pathToConfigurationRoot =
context.getValueFactories()
-
.getPathFactory()
-
.create("/dna:system");
- this.sources = new RepositoryLibrary(context);
+ PathFactory pathFactory = context.getValueFactories().getPathFactory();
+ if (pathToConfigurationRoot == null) pathToConfigurationRoot =
pathFactory.create("/dna:system");
+ Path sourcesPath = pathFactory.create(pathToConfigurationRoot,
DnaLexicon.SOURCES);
+
+ this.sources = new RepositoryLibrary(configurationSource,
configurationWorkspaceName, sourcesPath, context);
this.sources.addSource(configurationSource);
this.pathToConfigurationRoot = pathToConfigurationRoot;
this.configurationSourceName = configurationSource.getName();
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencer/SequencingServiceTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencer/SequencingServiceTest.java 2009-06-10
21:21:36 UTC (rev 1031)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencer/SequencingServiceTest.java 2009-06-10
21:22:01 UTC (rev 1032)
@@ -36,6 +36,7 @@
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
+import org.jboss.dna.graph.property.Path;
import org.jboss.dna.repository.RepositoryLibrary;
import org.jboss.dna.repository.service.ServiceAdministrator;
import org.junit.After;
@@ -59,7 +60,12 @@
@Before
public void beforeEach() {
- sources = new RepositoryLibrary(new ExecutionContext());
+ ExecutionContext context = new ExecutionContext();
+ InMemoryRepositorySource configSource = new InMemoryRepositorySource();
+ configSource.setDefaultWorkspaceName("default");
+ Path configPath =
context.getValueFactories().getPathFactory().create("/");
+
+ sources = new RepositoryLibrary(configSource, "default", configPath,
context);
InMemoryRepositorySource source = new InMemoryRepositorySource();
source.setName(REPOSITORY_SOURCE_NAME);
sources.addSource(source);