[dna-commits] DNA SVN: r511 - in trunk: dna-repository/src/test/java/org/jboss/dna/repository and 3 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Tue Sep 9 12:06:10 EDT 2008


Author: rhauch
Date: 2008-09-09 12:06:09 -0400 (Tue, 09 Sep 2008)
New Revision: 511

Added:
   trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/executor/SingleSourceCommandExecutor.java
Modified:
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositorySourceManager.java
   trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
   trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java
   trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
Log:
Removed some dependencies on the federation connector in the RepositoryService.

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	2008-09-09 15:58:30 UTC (rev 510)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java	2008-09-09 16:06:09 UTC (rev 511)
@@ -22,11 +22,8 @@
 package org.jboss.dna.repository;
 
 import java.lang.reflect.InvocationTargetException;
-import java.util.Collections;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import net.jcip.annotations.ThreadSafe;
@@ -36,14 +33,11 @@
 import org.jboss.dna.common.component.StandardClassLoaderFactory;
 import org.jboss.dna.common.util.ArgCheck;
 import org.jboss.dna.common.util.Reflection;
-import org.jboss.dna.connector.federation.FederatedRepositorySource;
 import org.jboss.dna.connector.federation.FederationException;
-import org.jboss.dna.connector.federation.Projection;
-import org.jboss.dna.connector.federation.executor.FederatingCommandExecutor;
-import org.jboss.dna.connector.federation.executor.SingleProjectionCommandExecutor;
 import org.jboss.dna.repository.services.AbstractServiceAdministrator;
 import org.jboss.dna.repository.services.AdministeredService;
 import org.jboss.dna.repository.services.ServiceAdministrator;
+import org.jboss.dna.spi.DnaLexicon;
 import org.jboss.dna.spi.ExecutionContext;
 import org.jboss.dna.spi.connector.RepositorySource;
 import org.jboss.dna.spi.graph.Name;
@@ -55,7 +49,7 @@
 import org.jboss.dna.spi.graph.ValueFactory;
 import org.jboss.dna.spi.graph.commands.GraphCommand;
 import org.jboss.dna.spi.graph.commands.executor.CommandExecutor;
-import org.jboss.dna.spi.graph.commands.executor.NoOpCommandExecutor;
+import org.jboss.dna.spi.graph.commands.executor.SingleSourceCommandExecutor;
 import org.jboss.dna.spi.graph.commands.impl.BasicCompositeCommand;
 import org.jboss.dna.spi.graph.commands.impl.BasicGetChildrenCommand;
 import org.jboss.dna.spi.graph.commands.impl.BasicGetNodeCommand;
@@ -66,12 +60,6 @@
 @ThreadSafe
 public class RepositoryService implements AdministeredService {
 
-    protected static final String CLASSNAME_PROPERTY_NAME = "dna:classname";
-    protected static final String CLASSPATH_PROPERTY_NAME = "dna:classpath";
-    protected static final String PROJECTION_RULES_PROPERTY_NAME = "dna:projectionRules";
-    protected static final String CACHE_POLICY_TIME_TO_EXPIRE = "dna:timeToExpire";
-    protected static final String CACHE_POLICY_TIME_TO_CACHE = "dna:timeToCache";
-
     /**
      * The administrative component for this service.
      * 
@@ -114,16 +102,17 @@
     private final ClassLoaderFactory classLoaderFactory;
     private final ExecutionContext context;
     private final RepositorySourceManager sources;
-    private final Projection configurationProjection;
+    private final String configurationSourceName;
+    private final Path pathToConfigurationRoot;
     private final Administrator administrator = new Administrator();
     private final AtomicBoolean started = new AtomicBoolean(false);
 
     /**
-     * Create a federation service instance
+     * Create a service instance, reading the configuration describing new {@link RepositorySource} instances from the source with
+     * the supplied name.
      * 
      * @param sources the source manager
-     * @param configurationProjection the projection defining where the service can find configuration information for the
-     *        different repositories that it is to manage
+     * @param configurationSourceName the name of the {@link RepositorySource} that is the configuration repository
      * @param context the execution context in which this service should run
      * @param classLoaderFactory the class loader factory used to instantiate {@link RepositorySource} instances; may be null if
      *        this instance should use a default factory that attempts to load classes first from the
@@ -132,14 +121,39 @@
      * @throws IllegalArgumentException if the bootstrap source is null or the execution context is null
      */
     public RepositoryService( RepositorySourceManager sources,
-                              Projection configurationProjection,
+                              String configurationSourceName,
                               ExecutionContext context,
                               ClassLoaderFactory classLoaderFactory ) {
-        ArgCheck.isNotNull(configurationProjection, "configurationProjection");
+        this(sources, configurationSourceName, null, context, classLoaderFactory);
+    }
+
+    /**
+     * Create a service instance, reading the configuration describing new {@link RepositorySource} instances from the source with
+     * the supplied name and path within the repository.
+     * 
+     * @param sources the source manager
+     * @param configurationSourceName the name of the {@link RepositorySource} that is the configuration repository
+     * @param pathToConfigurationRoot 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 "/" is used
+     * @param context the execution context in which this service should run
+     * @param classLoaderFactory the class loader factory used to instantiate {@link RepositorySource} instances; may be null if
+     *        this instance should use a default factory that attempts to load classes first from the
+     *        {@link Thread#getContextClassLoader() thread's current context class loader} and then from the class loader that
+     *        loaded this class.
+     * @throws IllegalArgumentException if the bootstrap source is null or the execution context is null
+     */
+    public RepositoryService( RepositorySourceManager sources,
+                              String configurationSourceName,
+                              Path pathToConfigurationRoot,
+                              ExecutionContext context,
+                              ClassLoaderFactory classLoaderFactory ) {
+        ArgCheck.isNotNull(configurationSourceName, "configurationSourceName");
         ArgCheck.isNotNull(sources, "sources");
         ArgCheck.isNotNull(context, "context");
+        if (pathToConfigurationRoot == null) pathToConfigurationRoot = context.getValueFactories().getPathFactory().createRootPath();
         this.sources = sources;
-        this.configurationProjection = configurationProjection;
+        this.pathToConfigurationRoot = pathToConfigurationRoot;
+        this.configurationSourceName = configurationSourceName;
         this.context = context;
         this.classLoaderFactory = classLoaderFactory != null ? classLoaderFactory : new StandardClassLoaderFactory();
     }
@@ -152,10 +166,10 @@
     }
 
     /**
-     * @return configurationProjection
+     * @return configurationSourceName
      */
-    public Projection getConfigurationProjection() {
-        return configurationProjection;
+    public String getConfigurationSourceName() {
+        return configurationSourceName;
     }
 
     /**
@@ -195,27 +209,12 @@
             PathFactory pathFactory = valueFactories.getPathFactory();
             NameFactory nameFactory = valueFactories.getNameFactory();
 
-            final String configurationSourceName = configurationProjection.getSourceName();
+            // Create a command executor to execute the commands.
+            CommandExecutor executor = new SingleSourceCommandExecutor(context, configurationSourceName, sources);
 
-            // Create a federating command executor to execute the commands and merge the results into a single set of
-            // commands.
-            List<Projection> projections = Collections.singletonList(configurationProjection);
-            CommandExecutor executor = null;
-            if (configurationProjection.getRules().size() == 0) {
-                // There is no projection for the configuration repository, so just use a no-op executor
-                executor = new NoOpCommandExecutor(context, configurationSourceName);
-            } else if (configurationProjection.isSimple()) {
-                // There is just a single projection for the configuration repository, so just use an executor that
-                // translates the paths using the projection
-                executor = new SingleProjectionCommandExecutor(context, configurationSourceName, configurationProjection, sources);
-            } else {
-                // The configuration repository has more than one projection, so we need to merge the results
-                executor = new FederatingCommandExecutor(context, configurationSourceName, projections, sources);
-            }
-
             // Read the configuration and the repository sources, located as child nodes/branches under "/dna:sources",
             // and then instantiate and register each in the "sources" manager
-            Path configurationRoot = pathFactory.create("/");
+            Path configurationRoot = this.pathToConfigurationRoot;
             try {
                 Path sourcesNode = pathFactory.create(configurationRoot, nameFactory.create("dna:sources"));
                 BasicGetChildrenCommand getSources = new BasicGetChildrenCommand(sourcesNode);
@@ -264,14 +263,13 @@
                                                        Map<Name, Property> properties,
                                                        Problems problems ) {
         ValueFactories valueFactories = context.getValueFactories();
-        NameFactory nameFactory = valueFactories.getNameFactory();
         ValueFactory<String> stringFactory = valueFactories.getStringFactory();
 
         // Get the classname and classpath ...
-        Property classnameProperty = properties.get(nameFactory.create(CLASSNAME_PROPERTY_NAME));
-        Property classpathProperty = properties.get(nameFactory.create(CLASSPATH_PROPERTY_NAME));
+        Property classnameProperty = properties.get(DnaLexicon.CLASSNAME);
+        Property classpathProperty = properties.get(DnaLexicon.CLASSPATH);
         if (classnameProperty == null) {
-            problems.addError(RepositoryI18n.requiredPropertyIsMissingFromNode, CLASSNAME_PROPERTY_NAME, path);
+            problems.addError(RepositoryI18n.requiredPropertyIsMissingFromNode, DnaLexicon.CLASSNAME, path);
         }
         // If the classpath property is null or empty, the default classpath will be used
         if (problems.hasErrors()) return null;
@@ -338,21 +336,6 @@
     }
 
     /**
-     * Get the current set of federated repository names.
-     * 
-     * @return the names of the repository, which is a mutable copy of the names that is not backed by the actual sources
-     */
-    public Set<String> getFederatedRepositoryNames() {
-        Set<String> repositoryNames = new HashSet<String>();
-        for (RepositorySource source : sources.getSources()) {
-            if (source instanceof FederatedRepositorySource) {
-                repositoryNames.add(source.getName());
-            }
-        }
-        return repositoryNames;
-    }
-
-    /**
      * {@inheritDoc}
      */
     @Override

Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositorySourceManager.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositorySourceManager.java	2008-09-09 15:58:30 UTC (rev 510)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositorySourceManager.java	2008-09-09 16:06:09 UTC (rev 511)
@@ -102,6 +102,13 @@
 
     /**
      * Create a new manager instance.
+     */
+    public RepositorySourceManager() {
+        this(null);
+    }
+
+    /**
+     * Create a new manager instance.
      * 
      * @param delegate the connection factory to which this instance should delegate in the event that a source is not found in
      *        this manager; may be null if there is no delegate

Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java	2008-09-09 15:58:30 UTC (rev 510)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java	2008-09-09 16:06:09 UTC (rev 511)
@@ -37,7 +37,6 @@
 import org.jboss.dna.common.component.ClassLoaderFactory;
 import org.jboss.dna.common.util.Logger;
 import org.jboss.dna.connector.federation.FederationException;
-import org.jboss.dna.connector.federation.Projection;
 import org.jboss.dna.repository.services.ServiceAdministrator;
 import org.jboss.dna.spi.DnaLexicon;
 import org.jboss.dna.spi.ExecutionContext;
@@ -46,8 +45,6 @@
 import org.jboss.dna.spi.connector.RepositorySource;
 import org.jboss.dna.spi.connector.SimpleRepository;
 import org.jboss.dna.spi.connector.SimpleRepositorySource;
-import org.jboss.dna.spi.graph.Path;
-import org.jboss.dna.spi.graph.PathFactory;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -59,15 +56,7 @@
  */
 public class RepositoryServiceTest {
 
-    public static final String CLASSNAME = RepositoryService.CLASSNAME_PROPERTY_NAME;
-    public static final String CLASSPATH = RepositoryService.CLASSPATH_PROPERTY_NAME;
-    public static final String PROJECTION_RULES = RepositoryService.PROJECTION_RULES_PROPERTY_NAME;
-    public static final String TIME_TO_EXPIRE = RepositoryService.CACHE_POLICY_TIME_TO_EXPIRE;
-    public static final String TIME_TO_CACHE = RepositoryService.CACHE_POLICY_TIME_TO_CACHE;
-
     private RepositoryService service;
-    private Projection configProjection;
-    private PathFactory pathFactory;
     private String configSourceName;
     private SimpleRepository configRepository;
     private SimpleRepositorySource configRepositorySource;
@@ -81,19 +70,14 @@
         MockitoAnnotations.initMocks(this);
         context = new BasicExecutionContext();
         context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
-        pathFactory = context.getValueFactories().getPathFactory();
-        Path pathInRepository = pathFactory.create("/");
-        Path pathInSource = pathFactory.create("/reposX");
         configSourceName = "configSource";
-        Projection.Rule configProjectionRule = new Projection.PathRule(pathInRepository, pathInSource);
-        configProjection = new Projection(configSourceName, configProjectionRule);
         configRepository = SimpleRepository.get("Configuration Repository");
         configRepositorySource = new SimpleRepositorySource();
         configRepositorySource.setRepositoryName(configRepository.getRepositoryName());
         configRepositorySource.setName(configSourceName);
         configRepositoryConnection = configRepositorySource.getConnection();
         stub(sources.createConnection(configSourceName)).toReturn(configRepositoryConnection);
-        service = new RepositoryService(sources, configProjection, context, null);
+        service = new RepositoryService(sources, configSourceName, context, null);
     }
 
     @After
@@ -110,9 +94,9 @@
     }
 
     @Test
-    public void shouldHaveConfigurationRegionAfterInstantiation() {
-        assertThat(service.getConfigurationProjection(), is(notNullValue()));
-        assertThat(service.getConfigurationProjection(), is(sameInstance(configProjection)));
+    public void shouldHaveConfigurationSourceAfterInstantiation() {
+        assertThat(service.getConfigurationSourceName(), is(notNullValue()));
+        assertThat(service.getConfigurationSourceName(), is(configSourceName));
     }
 
     @Test
@@ -129,7 +113,7 @@
     @Test
     public void shouldHaveNonNullClassLoaderFactoryAfterInstantiatingWithClassLoaderFactoryReference() {
         ClassLoaderFactory classLoaderFactory = mock(ClassLoaderFactory.class);
-        service = new RepositoryService(sources, configProjection, context, classLoaderFactory);
+        service = new RepositoryService(sources, configSourceName, context, classLoaderFactory);
         assertThat(service.getClassLoaderFactory(), is(notNullValue()));
         assertThat(service.getClassLoaderFactory(), is(sameInstance(classLoaderFactory)));
     }
@@ -166,22 +150,23 @@
         sources.addSource(configRepositorySource);
         assertThat(sources.getSources(), hasItems((RepositorySource)configRepositorySource));
         assertThat(sources.getSources().size(), is(1));
-        service = new RepositoryService(sources, configProjection, context, null);
+        service = new RepositoryService(sources, configSourceName, context, null);
 
         // Set up the configuration repository to contain 3 sources ...
-        configRepository.create(context, "/reposX/dna:sources");
-        configRepository.setProperty(context, "/reposX/dna:sources/source A", CLASSNAME, SimpleRepositorySource.class.getName());
-        configRepository.setProperty(context, "/reposX/dna:sources/source A", CLASSPATH, "");
-        configRepository.setProperty(context, "/reposX/dna:sources/source A", "repositoryName", "sourceReposA");
-        configRepository.setProperty(context, "/reposX/dna:sources/source A", "retryLimit", 3);
+        final String className = SimpleRepositorySource.class.getName();
+        configRepository.create(context, "/dna:sources");
+        configRepository.setProperty(context, "/dna:sources/source A", DnaLexicon.CLASSNAME, className);
+        configRepository.setProperty(context, "/dna:sources/source A", DnaLexicon.CLASSPATH, "");
+        configRepository.setProperty(context, "/dna:sources/source A", "repositoryName", "sourceReposA");
+        configRepository.setProperty(context, "/dna:sources/source A", "retryLimit", 3);
 
-        configRepository.setProperty(context, "/reposX/dna:sources/source B", CLASSNAME, SimpleRepositorySource.class.getName());
-        configRepository.setProperty(context, "/reposX/dna:sources/source B", CLASSPATH, "");
-        configRepository.setProperty(context, "/reposX/dna:sources/source B", "repositoryName", "sourceReposB");
+        configRepository.setProperty(context, "/dna:sources/source B", DnaLexicon.CLASSNAME, className);
+        configRepository.setProperty(context, "/dna:sources/source B", DnaLexicon.CLASSPATH, "");
+        configRepository.setProperty(context, "/dna:sources/source B", "repositoryName", "sourceReposB");
 
-        configRepository.setProperty(context, "/reposX/dna:sources/source C", CLASSNAME, SimpleRepositorySource.class.getName());
-        configRepository.setProperty(context, "/reposX/dna:sources/source C", CLASSPATH, "");
-        configRepository.setProperty(context, "/reposX/dna:sources/source C", "repositoryName", "sourceReposC");
+        configRepository.setProperty(context, "/dna:sources/source C", DnaLexicon.CLASSNAME, className);
+        configRepository.setProperty(context, "/dna:sources/source C", DnaLexicon.CLASSPATH, "");
+        configRepository.setProperty(context, "/dna:sources/source C", "repositoryName", "sourceReposC");
 
         // Now, start up the service ...
         service.getAdministrator().start();
@@ -211,7 +196,7 @@
     @Test
     public void shouldStartUpUsingConfigurationRepositoryThatContainsNoSources() throws Exception {
         // Set up the configuration repository to contain NO sources ...
-        configRepository.create(context, "/reposX/dna:sources");
+        configRepository.create(context, "/dna:sources");
 
         // Now, start up the service ...
         service.getAdministrator().start();
@@ -226,19 +211,24 @@
     @Test
     public void shouldStartUpAndCreateRepositoryUsingConfigurationRepositoryThatContainsNoSources() {
         // Set up the configuration repository ...
-        configRepository.create(context, "/reposX/dna:sources");
-        configRepository.setProperty(context, "/reposX/dna:sources/source A", CLASSNAME, SimpleRepositorySource.class.getName());
-        configRepository.setProperty(context, "/reposX/dna:sources/source A", CLASSPATH, "");
-        configRepository.setProperty(context, "/reposX/dna:sources/source A", "repositoryName", "sourceReposA");
-        configRepository.setProperty(context, "/reposX/dna:sources/source A", "retryLimit", 3);
+        configRepository.create(context, "/dna:sources");
+        configRepository.setProperty(context,
+                                     "/dna:sources/source A",
+                                     DnaLexicon.CLASSNAME,
+                                     SimpleRepositorySource.class.getName());
+        configRepository.setProperty(context, "/dna:sources/source A", DnaLexicon.CLASSPATH, "");
+        configRepository.setProperty(context, "/dna:sources/source A", "repositoryName", "sourceReposA");
+        configRepository.setProperty(context, "/dna:sources/source A", "retryLimit", 3);
 
-        String fedReposPath = "/reposX/dna:repositories/fed repos/";
-        configRepository.setProperty(context, fedReposPath, TIME_TO_CACHE, "10000");
-        configRepository.setProperty(context, fedReposPath, TIME_TO_EXPIRE, "20000");
-        configRepository.setProperty(context, fedReposPath + "dna:regions/source A", PROJECTION_RULES, "/a/b/c => /sx/sy");
-        configRepository.setProperty(context, fedReposPath + "dna:regions/source B", PROJECTION_RULES, "/ => /");
-        configRepository.setProperty(context, fedReposPath + "dna:regions/source C", PROJECTION_RULES, "/d/e/f => /");
-        configRepository.setProperty(context, fedReposPath + "dna:regions/source D", PROJECTION_RULES, "/ => /x/y/z");
+        String fedReposPath = "/dna:repositories/fed repos/";
+        configRepository.setProperty(context, fedReposPath, DnaLexicon.TIME_TO_EXPIRE, "20000");
+        configRepository.setProperty(context,
+                                     fedReposPath + "dna:regions/source A",
+                                     DnaLexicon.PROJECTION_RULES,
+                                     "/a/b/c => /sx/sy");
+        configRepository.setProperty(context, fedReposPath + "dna:regions/source B", DnaLexicon.PROJECTION_RULES, "/ => /");
+        configRepository.setProperty(context, fedReposPath + "dna:regions/source C", DnaLexicon.PROJECTION_RULES, "/d/e/f => /");
+        configRepository.setProperty(context, fedReposPath + "dna:regions/source D", DnaLexicon.PROJECTION_RULES, "/ => /x/y/z");
 
         // Now, start up the service ...
         service.getAdministrator().start();

Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java	2008-09-09 15:58:30 UTC (rev 510)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java	2008-09-09 16:06:09 UTC (rev 511)
@@ -36,4 +36,8 @@
 
     public static final Name UUID = new BasicName(Namespace.URI, "uuid");
     public static final Name MERGE_PLAN = new BasicName(Namespace.URI, "mergePlan");
+    public static final Name CLASSNAME = new BasicName(Namespace.URI, "classname");
+    public static final Name CLASSPATH = new BasicName(Namespace.URI, "classpath");
+    public static final Name PROJECTION_RULES = new BasicName(Namespace.URI, "projectionRules");
+    public static final Name TIME_TO_EXPIRE = new BasicName(Namespace.URI, "timeToExpire");
 }

Added: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/executor/SingleSourceCommandExecutor.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/executor/SingleSourceCommandExecutor.java	                        (rev 0)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/executor/SingleSourceCommandExecutor.java	2008-09-09 16:06:09 UTC (rev 511)
@@ -0,0 +1,193 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.commands.executor;
+
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.jboss.dna.spi.connector.RepositorySource;
+import org.jboss.dna.spi.connector.RepositorySourceException;
+import org.jboss.dna.spi.graph.DateTime;
+import org.jboss.dna.spi.graph.commands.CopyBranchCommand;
+import org.jboss.dna.spi.graph.commands.CopyNodeCommand;
+import org.jboss.dna.spi.graph.commands.CreateNodeCommand;
+import org.jboss.dna.spi.graph.commands.DeleteBranchCommand;
+import org.jboss.dna.spi.graph.commands.GetChildrenCommand;
+import org.jboss.dna.spi.graph.commands.GetPropertiesCommand;
+import org.jboss.dna.spi.graph.commands.MoveBranchCommand;
+import org.jboss.dna.spi.graph.commands.RecordBranchCommand;
+import org.jboss.dna.spi.graph.commands.SetPropertiesCommand;
+
+/**
+ * @author Randall Hauch
+ */
+public class SingleSourceCommandExecutor extends AbstractCommandExecutor {
+
+    private RepositoryConnection connection;
+    private final RepositoryConnectionFactory connectionFactory;
+
+    /**
+     * Create a command executor that does nothing.
+     * 
+     * @param context the execution context in which the executor will be run; may not be null
+     * @param sourceName the name of the {@link RepositorySource} that is making use of this executor; may not be null or empty
+     * @param connectionFactory the factory for {@link RepositoryConnection} instances
+     */
+    public SingleSourceCommandExecutor( ExecutionContext context,
+
+                                        String sourceName,
+                                        RepositoryConnectionFactory connectionFactory ) {
+        this(context, sourceName, null, connectionFactory);
+    }
+
+    /**
+     * Create a command executor that does nothing.
+     * 
+     * @param context the execution context in which the executor will be run; may not be null
+     * @param sourceName the name of the {@link RepositorySource} that is making use of this executor; may not be null or empty
+     * @param now the current time; may be null if the system time is to be used
+     * @param connectionFactory the factory for {@link RepositoryConnection} instances
+     */
+    public SingleSourceCommandExecutor( ExecutionContext context,
+                                        String sourceName,
+                                        DateTime now,
+                                        RepositoryConnectionFactory connectionFactory ) {
+        super(context, sourceName, now);
+        assert connectionFactory != null;
+        this.connectionFactory = connectionFactory;
+    }
+
+    protected RepositoryConnection getConnection() throws RepositorySourceException {
+        if (connection == null) {
+            // Create a connection ...
+            connection = this.connectionFactory.createConnection(getSourceName());
+        }
+        return connection;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#close()
+     */
+    @Override
+    public void close() {
+        if (this.connection != null) {
+            try {
+                this.connection.close();
+            } finally {
+                this.connection = null;
+            }
+        }
+        super.close();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.CopyBranchCommand)
+     */
+    @Override
+    public void execute( CopyBranchCommand command ) throws RepositorySourceException {
+        getConnection().execute(this.getExecutionContext(), command);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.CopyNodeCommand)
+     */
+    @Override
+    public void execute( CopyNodeCommand command ) throws RepositorySourceException {
+        getConnection().execute(this.getExecutionContext(), command);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.CreateNodeCommand)
+     */
+    @Override
+    public void execute( CreateNodeCommand command ) throws RepositorySourceException {
+        getConnection().execute(this.getExecutionContext(), command);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.DeleteBranchCommand)
+     */
+    @Override
+    public void execute( DeleteBranchCommand command ) throws RepositorySourceException {
+        getConnection().execute(this.getExecutionContext(), command);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.GetChildrenCommand)
+     */
+    @Override
+    public void execute( GetChildrenCommand command ) throws RepositorySourceException {
+        getConnection().execute(this.getExecutionContext(), command);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.GetPropertiesCommand)
+     */
+    @Override
+    public void execute( GetPropertiesCommand command ) throws RepositorySourceException {
+        getConnection().execute(this.getExecutionContext(), command);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.MoveBranchCommand)
+     */
+    @Override
+    public void execute( MoveBranchCommand command ) throws RepositorySourceException {
+        getConnection().execute(this.getExecutionContext(), command);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.RecordBranchCommand)
+     */
+    @Override
+    public void execute( RecordBranchCommand command ) throws RepositorySourceException {
+        getConnection().execute(this.getExecutionContext(), command);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.SetPropertiesCommand)
+     */
+    @Override
+    public void execute( SetPropertiesCommand command ) throws RepositorySourceException {
+        getConnection().execute(this.getExecutionContext(), command);
+    }
+}


Property changes on: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/executor/SingleSourceCommandExecutor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java	2008-09-09 15:58:30 UTC (rev 510)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java	2008-09-09 16:06:09 UTC (rev 511)
@@ -130,18 +130,35 @@
                                          String path,
                                          String propertyName,
                                          Object... values ) {
+        NameFactory nameFactory = context.getValueFactories().getNameFactory();
+        return setProperty(context, path, nameFactory.create(propertyName), values);
+    }
+
+    /**
+     * Utility method to help set the property on the node given by the supplied path. If the node does not exist, it will be
+     * created.
+     * 
+     * @param context the execution context; may not be null
+     * @param path the path to the node; may not be null
+     * @param propertyName the property name; may not be null
+     * @param values the values of the property
+     * @return this repository, for method chaining
+     */
+    public SimpleRepository setProperty( ExecutionContext context,
+                                         String path,
+                                         Name propertyName,
+                                         Object... values ) {
         Logger logger = context.getLogger(getClass());
         if (logger.isTraceEnabled()) {
             logger.trace("Setting property {0} on {1} to {2}", propertyName, path, StringUtil.readableString(values));
         }
         PathFactory pathFactory = context.getValueFactories().getPathFactory();
-        NameFactory nameFactory = context.getValueFactories().getNameFactory();
         PropertyFactory propertyFactory = context.getPropertyFactory();
         Path pathObj = pathFactory.create(path);
         if (!pathObj.isRoot()) {
             create(context, pathObj.getParent().getString(context.getNamespaceRegistry()));
         }
-        Property property = propertyFactory.create(nameFactory.create(propertyName), values);
+        Property property = propertyFactory.create(propertyName, values);
         Map<Name, Property> properties = new HashMap<Name, Property>();
         Map<Name, Property> existingProperties = data.putIfAbsent(pathObj, properties);
         if (existingProperties == null) existingProperties = properties;




More information about the dna-commits mailing list