[dna-commits] DNA SVN: r806 - in trunk: dna-jcr/src/test/java/org/jboss/dna/jcr and 1 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Thu Apr 2 16:39:44 EDT 2009


Author: rhauch
Date: 2009-04-02 16:39:44 -0400 (Thu, 02 Apr 2009)
New Revision: 806

Modified:
   trunk/dna-jcr-tck/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/RepositoryNodeTypeManagerTest.java
Log:
DNA-340 Projection of Node Types onto System View

Changed the name of JcrRepository.Settings to JcrRepository.Options, added a mechanism for setting up defaults, and added a public method to get the unmodifiable options map.  Also changed JcrWorkspace to use the repository's options map (rather than a custom boolean constructor parameter) to determine whether it should project the node types as content.

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java	2009-04-02 20:15:09 UTC (rev 805)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java	2009-04-02 20:39:44 UTC (rev 806)
@@ -73,30 +73,47 @@
 public class JcrRepository implements Repository {
 
     /**
-     * List of settings for the {@code JcrRepository}.
-     * <p>
-     * The attributes that may be set are:
-     * <ul>
-     * <li>{@code PROJECT_NODE_TYPES} (boolean) - if {@code true}, project the registered node types onto the system view at the
-     * path {@code /jcr:system/jcr:nodeTypes}.</li>
-     * </ul>
-     * </p>
+     * The available options for the {@code JcrRepository}.
      */
-    public enum Settings {
+    public enum Options {
+
         /**
-         * Flag that defines whether or not the node types should be exposed as content under the "
-         * <code>/jcr:system/dna:nodeTypes</code>" node. By default, the flag is false.
+         * Flag that defines whether or not the node types should be exposed as content under the "{@code
+         * /jcr:system/jcr:nodeTypes}" node. Value is either "<code>true</code>" or "<code>false</code>" (default).
+         * 
+         * @see DefaultOptions#PROJECT_NODE_TYPES
          */
         PROJECT_NODE_TYPES,
+    }
 
+    /**
+     * The default values for each of the {@link Options}.
+     */
+    public static class DefaultOptions {
+        /**
+         * The default value for the {@link Options#PROJECT_NODE_TYPES} option is {@value} .
+         */
+        public static final String PROJECT_NODE_TYPES = Boolean.FALSE.toString();
     }
 
+    /**
+     * The static unmodifiable map of default options, which are initialized in the static initializer.
+     */
+    protected static final Map<Options, String> DEFAULT_OPTIONS;
+
+    static {
+        // Initialize the unmodifiable map of default options ...
+        EnumMap<Options, String> defaults = new EnumMap<Options, String>(Options.class);
+        defaults.put(Options.PROJECT_NODE_TYPES, DefaultOptions.PROJECT_NODE_TYPES);
+        DEFAULT_OPTIONS = Collections.<Options, String>unmodifiableMap(defaults);
+    }
+
     private final String sourceName;
     private final Map<String, String> descriptors;
     private final ExecutionContext executionContext;
     private final RepositoryConnectionFactory connectionFactory;
     private final RepositoryNodeTypeManager repositoryTypeManager;
-    private final Map<Settings, String> settings;
+    private final Map<Options, String> options;
 
     /**
      * Creates a JCR repository that uses the supplied {@link RepositoryConnectionFactory repository connection factory} to
@@ -122,7 +139,7 @@
      * @param connectionFactory the factory for repository connections
      * @param repositorySourceName the name of the repository source (in the connection factory) that should be used
      * @param descriptors the {@link #getDescriptorKeys() descriptors} for this repository; may be <code>null</code>.
-     * @param settings the optional {@link Settings settings} for this repository; may be null
+     * @param options the optional {@link Options settings} for this repository; may be null
      * @throws IllegalArgumentException If <code>executionContextFactory</code> or <code>connectionFactory</code> is
      *         <code>null</code>.
      */
@@ -130,7 +147,7 @@
                           RepositoryConnectionFactory connectionFactory,
                           String repositorySourceName,
                           Map<String, String> descriptors,
-                          Map<Settings, String> settings ) {
+                          Map<Options, String> options ) {
         CheckArg.isNotNull(executionContext, "executionContext");
         CheckArg.isNotNull(connectionFactory, "connectionFactory");
         CheckArg.isNotNull(repositorySourceName, "repositorySourceName");
@@ -175,10 +192,13 @@
         source = new DnaBuiltinNodeTypeSource(this.executionContext, source);
         this.repositoryTypeManager = new RepositoryNodeTypeManager(this.executionContext, source);
 
-        if (settings == null) {
-            this.settings = Collections.<Settings, String>emptyMap();
+        if (options == null) {
+            this.options = DEFAULT_OPTIONS;
         } else {
-            this.settings = Collections.unmodifiableMap(new EnumMap<Settings, String>(settings));
+            // Initialize with defaults, then add supplied options ...
+            EnumMap<Options, String> localOptions = new EnumMap<Options, String>(DEFAULT_OPTIONS);
+            localOptions.putAll(options);
+            this.options = Collections.unmodifiableMap(localOptions);
         }
     }
 
@@ -192,6 +212,15 @@
     }
 
     /**
+     * Get the options as configured for this repository.
+     * 
+     * @return the unmodifiable options; never null
+     */
+    public Map<Options, String> getOptions() {
+        return options;
+    }
+
+    /**
      * Get the name of the repository source that this repository is using.
      * 
      * @return the name of the RepositorySource
@@ -352,10 +381,8 @@
         }
 
         // Create the workspace, which will create its own session ...
-        boolean shouldProjectNodeTypes = Boolean.valueOf(settings.get(Settings.PROJECT_NODE_TYPES));
-
         sessionAttributes = Collections.unmodifiableMap(sessionAttributes);
-        JcrWorkspace workspace = new JcrWorkspace(this, workspaceName, execContext, sessionAttributes, shouldProjectNodeTypes);
+        JcrWorkspace workspace = new JcrWorkspace(this, workspaceName, execContext, sessionAttributes);
         return workspace.getSession();
     }
 }

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java	2009-04-02 20:15:09 UTC (rev 805)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java	2009-04-02 20:39:44 UTC (rev 806)
@@ -58,6 +58,7 @@
 import org.jboss.dna.graph.property.PropertyFactory;
 import org.jboss.dna.graph.property.ValueFormatException;
 import org.jboss.dna.graph.property.basic.GraphNamespaceRegistry;
+import org.jboss.dna.jcr.JcrRepository.Options;
 import org.xml.sax.ContentHandler;
 
 /**
@@ -120,15 +121,7 @@
                   String workspaceName,
                   ExecutionContext context,
                   Map<String, Object> sessionAttributes ) {
-        this(repository, workspaceName, context, sessionAttributes, true);
-    }
 
-    JcrWorkspace( JcrRepository repository,
-                  String workspaceName,
-                  ExecutionContext context,
-                  Map<String, Object> sessionAttributes,
-                  boolean projectTypesOntoSystemView ) {
-
         assert workspaceName != null;
         assert context != null;
         assert repository != null;
@@ -166,7 +159,7 @@
         this.nodeTypeManager = new JcrNodeTypeManager(session.getExecutionContext(), repoTypeManager);
         this.queryManager = new JcrQueryManager(this.session);
 
-        if (projectTypesOntoSystemView) {
+        if (Boolean.valueOf(repository.getOptions().get(Options.PROJECT_NODE_TYPES))) {
             Path parentOfTypeNodes = context.getValueFactories().getPathFactory().create(root,
                                                                                          JcrLexicon.SYSTEM,
                                                                                          JcrLexicon.NODE_TYPES);

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java	2009-04-02 20:15:09 UTC (rev 805)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java	2009-04-02 20:39:44 UTC (rev 806)
@@ -154,6 +154,13 @@
     }
 
     @Test
+    public void shouldHaveDefaultOptionsWhenNotOverridden() {
+        JcrRepository repository = new JcrRepository(context, connectionFactory, sourceName, descriptors, null);
+        assertThat(repository.getOptions().get(JcrRepository.Options.PROJECT_NODE_TYPES),
+                   is(JcrRepository.DefaultOptions.PROJECT_NODE_TYPES));
+    }
+
+    @Test
     public void shouldProvideUserSuppliedDescriptors() {
         Map<String, String> descriptors = new HashMap<String, String>();
         descriptors.put("property", "value");

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java	2009-04-02 20:15:09 UTC (rev 805)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java	2009-04-02 20:39:44 UTC (rev 806)
@@ -55,7 +55,7 @@
 import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
 import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
 import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.jcr.JcrRepository.Settings;
+import org.jboss.dna.jcr.JcrRepository.Options;
 
 /**
  * Test suite to wrap Apache Jackrabbit JCR technology compatibility kit (TCK) unit tests. Note that technically these are not the
@@ -278,10 +278,10 @@
             source.setName("TestRepositorySource");
 
             // Wrap a connection to the in-memory (DNA) repository in a (JCR) repository
-            Map<Settings, String> settings = Collections.singletonMap(Settings.PROJECT_NODE_TYPES, "false");
+            Map<Options, String> options = Collections.singletonMap(Options.PROJECT_NODE_TYPES, "false");
             connection = source.getConnection();
             repository = new JcrRepository(executionContext.create(accessControlContext), connectionFactory, source.getName(),
-                                           null, settings);
+                                           null, options);
 
             // Make sure the path to the namespaces exists ...
             Graph graph = Graph.create(source.getName(), connectionFactory, executionContext);

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/RepositoryNodeTypeManagerTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/RepositoryNodeTypeManagerTest.java	2009-04-02 20:15:09 UTC (rev 805)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/RepositoryNodeTypeManagerTest.java	2009-04-02 20:39:44 UTC (rev 806)
@@ -32,6 +32,7 @@
 import static org.mockito.Mockito.stub;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.EnumMap;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
@@ -70,6 +71,7 @@
     private RepositoryConnectionFactory connectionFactory;
     private RepositoryNodeTypeManager repoTypeManager;
     private Map<String, Object> sessionAttributes;
+    private Map<JcrRepository.Options, String> options;
     @Mock
     private JcrRepository repository;
 
@@ -122,6 +124,11 @@
         stub(repository.getRepositorySourceName()).toReturn(repositorySourceName);
         stub(repository.getConnectionFactory()).toReturn(connectionFactory);
 
+        // Stub out the repository options ...
+        options = new EnumMap<JcrRepository.Options, String>(JcrRepository.Options.class);
+        options.put(JcrRepository.Options.PROJECT_NODE_TYPES, Boolean.TRUE.toString());
+        stub(repository.getOptions()).toReturn(options);
+
         // Set up the session attributes ...
         sessionAttributes = new HashMap<String, Object>();
         sessionAttributes.put("attribute1", "value1");

Modified: trunk/dna-jcr-tck/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java
===================================================================
--- trunk/dna-jcr-tck/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java	2009-04-02 20:15:09 UTC (rev 805)
+++ trunk/dna-jcr-tck/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java	2009-04-02 20:39:44 UTC (rev 806)
@@ -43,7 +43,7 @@
 import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
 import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
 import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.jcr.JcrRepository.Settings;
+import org.jboss.dna.jcr.JcrRepository.Options;
 
 /**
  * Class with TCK repository stub. This class does not contain any tests.
@@ -86,10 +86,10 @@
         source.setName("TestRepositorySource");
 
         // Wrap a connection to the in-memory (DNA) repository in a (JCR) repository
-        Map<Settings, String> settings = Collections.singletonMap(Settings.PROJECT_NODE_TYPES, "true");
+        Map<Options, String> options = Collections.singletonMap(Options.PROJECT_NODE_TYPES, "true");
         connection = source.getConnection();
         repository = new JcrRepository(executionContext.create(accessControlContext), connectionFactory, source.getName(), null,
-                                       settings);
+                                       options);
 
         // Make sure the path to the namespaces exists ...
         Graph graph = Graph.create(source.getName(), connectionFactory, executionContext);




More information about the dna-commits mailing list