Author: rhauch
Date: 2009-04-02 16:15:09 -0400 (Thu, 02 Apr 2009)
New Revision: 805
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/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.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
Log:
DNA-340 Projection of Node Types onto System View
Applied the 2nd patch, which adds support to JcrRepository for configurable options, with
a single option as to whether or not the node types should be projected under
"/jcr:system/dna:nodeTypes". Minor change from the patch was to reorder the
constructor parameters of JcrRepository to match the other existing constructor.
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 19:02:05
UTC (rev 804)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-04-02 20:15:09
UTC (rev 805)
@@ -26,6 +26,7 @@
import java.lang.reflect.Method;
import java.security.AccessControlContext;
import java.util.Collections;
+import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -71,11 +72,31 @@
@ThreadSafe
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>
+ */
+ public enum Settings {
+ /**
+ * 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.
+ */
+ PROJECT_NODE_TYPES,
+
+ }
+
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;
/**
* Creates a JCR repository that uses the supplied {@link RepositoryConnectionFactory
repository connection factory} to
@@ -90,24 +111,26 @@
public JcrRepository( ExecutionContext executionContext,
RepositoryConnectionFactory connectionFactory,
String repositorySourceName ) {
- this(null, executionContext, connectionFactory, repositorySourceName);
+ this(executionContext, connectionFactory, repositorySourceName, null, null);
}
/**
* Creates a JCR repository that uses the supplied {@link RepositoryConnectionFactory
repository connection factory} to
* establish {@link Session sessions} to the underlying repository source upon {@link
#login() login}.
*
- * @param descriptors The {@link #getDescriptorKeys() descriptors} for this
repository; may be <code>null</code>.
* @param executionContext the execution context in which this repository is to
operate
* @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
* @throws IllegalArgumentException If
<code>executionContextFactory</code> or
<code>connectionFactory</code> is
* <code>null</code>.
*/
- public JcrRepository( Map<String, String> descriptors,
- ExecutionContext executionContext,
+ public JcrRepository( ExecutionContext executionContext,
RepositoryConnectionFactory connectionFactory,
- String repositorySourceName ) {
+ String repositorySourceName,
+ Map<String, String> descriptors,
+ Map<Settings, String> settings ) {
CheckArg.isNotNull(executionContext, "executionContext");
CheckArg.isNotNull(connectionFactory, "connectionFactory");
CheckArg.isNotNull(repositorySourceName, "repositorySourceName");
@@ -146,21 +169,28 @@
modifiableDescriptors.put(Repository.SPEC_NAME_DESC,
JcrI18n.SPEC_NAME_DESC.text());
modifiableDescriptors.put(Repository.SPEC_VERSION_DESC, "1.0");
this.descriptors = Collections.unmodifiableMap(modifiableDescriptors);
-
+
JcrNodeTypeSource source = null;
source = new JcrBuiltinNodeTypeSource(this.executionContext);
source = new DnaBuiltinNodeTypeSource(this.executionContext, source);
this.repositoryTypeManager = new RepositoryNodeTypeManager(this.executionContext,
source);
+
+ if (settings == null) {
+ this.settings = Collections.<Settings, String>emptyMap();
+ } else {
+ this.settings = Collections.unmodifiableMap(new EnumMap<Settings,
String>(settings));
+ }
}
/**
* Returns the repository-level node type manager
+ *
* @return the repository-level node type manager
*/
RepositoryNodeTypeManager getRepositoryTypeManager() {
return repositoryTypeManager;
}
-
+
/**
* Get the name of the repository source that this repository is using.
*
@@ -322,8 +352,10 @@
}
// 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);
+ JcrWorkspace workspace = new JcrWorkspace(this, workspaceName, execContext,
sessionAttributes, shouldProjectNodeTypes);
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 19:02:05
UTC (rev 804)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-04-02 20:15:09
UTC (rev 805)
@@ -120,6 +120,15 @@
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;
@@ -157,10 +166,12 @@
this.nodeTypeManager = new JcrNodeTypeManager(session.getExecutionContext(),
repoTypeManager);
this.queryManager = new JcrQueryManager(this.session);
- Path parentOfTypeNodes =
context.getValueFactories().getPathFactory().create(root,
-
JcrLexicon.SYSTEM,
-
JcrLexicon.NODE_TYPES);
- repoTypeManager.projectOnto(this.graph, parentOfTypeNodes);
+ if (projectTypesOntoSystemView) {
+ Path parentOfTypeNodes =
context.getValueFactories().getPathFactory().create(root,
+
JcrLexicon.SYSTEM,
+
JcrLexicon.NODE_TYPES);
+ repoTypeManager.projectOnto(this.graph, parentOfTypeNodes);
+ }
}
final String getSourceName() {
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java
===================================================================
---
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java 2009-04-02
19:02:05 UTC (rev 804)
+++
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java 2009-04-02
20:15:09 UTC (rev 805)
@@ -37,6 +37,7 @@
import javax.jcr.nodetype.PropertyDefinition;
import javax.jcr.version.OnParentVersionAction;
import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.text.XmlNameEncoder;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
@@ -60,6 +61,8 @@
@Immutable
class RepositoryNodeTypeManager {
+ private static final TextEncoder NAME_ENCODER = new XmlNameEncoder();
+
private final ExecutionContext context;
private final Map<Name, JcrNodeType> nodeTypes;
private final Map<PropertyDefinitionId, JcrPropertyDefinition>
propertyDefinitions;
@@ -652,8 +655,7 @@
projectNodeTypeOnto(nodeType, parentOfTypeNodes, batch);
}
- // TODO: Add back in; see DNA-340 ...
- // batch.execute();
+ batch.execute();
}
/**
@@ -730,7 +732,7 @@
assert batch != null;
JcrPropertyDefinition jcrPropDef = (JcrPropertyDefinition)propertyDef;
- String propName =
jcrPropDef.getInternalName().getString(context.getNamespaceRegistry(), new
XmlNameEncoder());
+ String propName =
jcrPropDef.getInternalName().getString(context.getNamespaceRegistry(), NAME_ENCODER);
Path propDefPath = pathFactory.create(nodeTypePath,
JcrLexicon.PROPERTY_DEFINITION);
List<Property> propsList = new ArrayList<Property>();
@@ -793,7 +795,7 @@
assert batch != null;
JcrNodeDefinition jcrNodeDef = (JcrNodeDefinition)childNodeDef;
- String nodeName =
jcrNodeDef.getInternalName().getString(context.getNamespaceRegistry(), new
XmlNameEncoder());
+ String nodeName =
jcrNodeDef.getInternalName().getString(context.getNamespaceRegistry(), NAME_ENCODER);
Path nodeDefPath = pathFactory.create(nodeTypePath,
JcrLexicon.CHILD_NODE_DEFINITION);
List<Property> propsList = new ArrayList<Property>();
@@ -817,5 +819,4 @@
batch.create(nodeDefPath).with(propsList).and();
}
-
}
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
19:02:05 UTC (rev 804)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java 2009-04-02
20:15:09 UTC (rev 805)
@@ -103,27 +103,27 @@
// Set up the repository ...
descriptors = new HashMap<String, String>();
- repository = new JcrRepository(descriptors, context, connectionFactory,
sourceName);
+ repository = new JcrRepository(context, connectionFactory, sourceName,
descriptors, null);
}
@Test
public void shouldAllowNullDescriptors() {
- new JcrRepository(null, context, connectionFactory, sourceName);
+ new JcrRepository(context, connectionFactory, sourceName, null, null);
}
@Test( expected = IllegalArgumentException.class )
public void shouldNotAllowNullExecutionContext() throws Exception {
- new JcrRepository(descriptors, null, connectionFactory, sourceName);
+ new JcrRepository(null, connectionFactory, sourceName, descriptors, null);
}
@Test( expected = IllegalArgumentException.class )
public void shouldNotAllowNullConnectionFactories() throws Exception {
- new JcrRepository(descriptors, context, null, sourceName);
+ new JcrRepository(context, null, sourceName, descriptors, null);
}
@Test( expected = IllegalArgumentException.class )
public void shouldNotAllowNullSourceName() throws Exception {
- new JcrRepository(descriptors, context, connectionFactory, null);
+ new JcrRepository(context, connectionFactory, null, descriptors, null);
}
@Test( expected = IllegalArgumentException.class )
@@ -148,7 +148,7 @@
@Test
public void shouldProvideBuiltInDescriptorsWhenNotSuppliedDescriptors() {
- Repository repository = new JcrRepository(descriptors, context,
connectionFactory, sourceName);
+ Repository repository = new JcrRepository(context, connectionFactory, sourceName,
descriptors, null);
testDescriptorKeys(repository);
testDescriptorValues(repository);
}
@@ -157,7 +157,7 @@
public void shouldProvideUserSuppliedDescriptors() {
Map<String, String> descriptors = new HashMap<String, String>();
descriptors.put("property", "value");
- Repository repository = new JcrRepository(descriptors, context,
connectionFactory, sourceName);
+ Repository repository = new JcrRepository(context, connectionFactory, sourceName,
descriptors, null);
testDescriptorKeys(repository);
testDescriptorValues(repository);
assertThat(repository.getDescriptor("property"),
is("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 19:02:05 UTC
(rev 804)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-04-02 20:15:09 UTC
(rev 805)
@@ -28,6 +28,7 @@
import java.security.AccessControlContext;
import java.security.AccessController;
import java.util.Collections;
+import java.util.Map;
import java.util.Properties;
import javax.jcr.Credentials;
import javax.jcr.Repository;
@@ -54,6 +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;
/**
* Test suite to wrap Apache Jackrabbit JCR technology compatibility kit (TCK) unit
tests. Note that technically these are not the
@@ -276,9 +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");
connection = source.getConnection();
- repository = new JcrRepository(Collections.<String, String>emptyMap(),
executionContext.create(accessControlContext),
- connectionFactory, source.getName());
+ repository = new JcrRepository(executionContext.create(accessControlContext),
connectionFactory, source.getName(),
+ null, settings);
// Make sure the path to the namespaces exists ...
Graph graph = Graph.create(source.getName(), connectionFactory,
executionContext);
@@ -291,7 +294,7 @@
executionContext.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX,
DnaLexicon.Namespace.URI);
executionContext.getNamespaceRegistry().register(JcrLexicon.Namespace.PREFIX,
JcrLexicon.Namespace.URI);
executionContext.getNamespaceRegistry().register(JcrNtLexicon.Namespace.PREFIX,
JcrNtLexicon.Namespace.URI);
- executionContext.getNamespaceRegistry().register("sv",
"http://www.jcp.org/jcr/sv/1.0");
+
executionContext.getNamespaceRegistry().register(JcrSvLexicon.Namespace.PREFIX,
JcrSvLexicon.Namespace.URI);
Path destinationPath =
executionContext.getValueFactories().getPathFactory().create("/");
GraphImporter importer = new GraphImporter(graph);
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
19:02:05 UTC (rev 804)
+++
trunk/dna-jcr-tck/src/test/java/org/jboss/dna/jcr/InMemoryRepositoryStub.java 2009-04-02
20:15:09 UTC (rev 805)
@@ -28,6 +28,7 @@
import java.security.AccessControlContext;
import java.security.AccessController;
import java.util.Collections;
+import java.util.Map;
import java.util.Properties;
import javax.jcr.Credentials;
import javax.jcr.Repository;
@@ -42,6 +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;
/**
* Class with TCK repository stub. This class does not contain any tests.
@@ -84,9 +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");
connection = source.getConnection();
- repository = new JcrRepository(Collections.<String, String>emptyMap(),
executionContext.create(accessControlContext),
- connectionFactory, source.getName());
+ repository = new JcrRepository(executionContext.create(accessControlContext),
connectionFactory, source.getName(), null,
+ settings);
// Make sure the path to the namespaces exists ...
Graph graph = Graph.create(source.getName(), connectionFactory,
executionContext);
@@ -99,7 +102,7 @@
executionContext.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX,
DnaLexicon.Namespace.URI);
executionContext.getNamespaceRegistry().register(JcrLexicon.Namespace.PREFIX,
JcrLexicon.Namespace.URI);
executionContext.getNamespaceRegistry().register(JcrNtLexicon.Namespace.PREFIX,
JcrNtLexicon.Namespace.URI);
- executionContext.getNamespaceRegistry().register("sv",
"http://www.jcp.org/jcr/sv/1.0");
+
executionContext.getNamespaceRegistry().register(JcrSvLexicon.Namespace.PREFIX,
JcrSvLexicon.Namespace.URI);
Path destinationPath =
executionContext.getValueFactories().getPathFactory().create("/");
GraphImporter importer = new GraphImporter(graph);