jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1399686 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/tck/
Date Thu, 18 Oct 2012 15:01:23 GMT
Author: jukka
Date: Thu Oct 18 15:01:22 2012
New Revision: 1399686

URL: http://svn.apache.org/viewvc?rev=1399686&view=rev
Log:
OAK-41: Initial repository setup

Teach registerNodeTypes() how to register also new namespaces included in a CND

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/Namespaces.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefBuilderFactory.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadWriteNodeTypeManager.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/tck/ApiIT.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/Namespaces.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/Namespaces.java?rev=1399686&r1=1399685&r2=1399686&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/Namespaces.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/Namespaces.java
Thu Oct 18 15:01:22 2012
@@ -30,7 +30,7 @@ import static org.apache.jackrabbit.oak.
 /**
  * Internal static utility class for managing the persisted namespace registry.
  */
-class Namespaces implements NamespaceConstants {
+public class Namespaces implements NamespaceConstants {
 
     private Namespaces() {
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefBuilderFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefBuilderFactory.java?rev=1399686&r1=1399685&r2=1399686&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefBuilderFactory.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefBuilderFactory.java
Thu Oct 18 15:01:22 2012
@@ -16,42 +16,62 @@
  */
 package org.apache.jackrabbit.oak.plugins.nodetype;
 
-import java.util.HashMap;
 import java.util.Map;
 
 import javax.jcr.nodetype.NodeTypeTemplate;
 
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory;
-import org.apache.jackrabbit.oak.namepath.NameMapper;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.namepath.NameMapperImpl;
+import org.apache.jackrabbit.oak.plugins.name.NamespaceConstants;
+import org.apache.jackrabbit.oak.plugins.name.Namespaces;
 
 class DefBuilderFactory extends
         DefinitionBuilderFactory<NodeTypeTemplate, Map<String, String>> {
 
-    private final NameMapper mapper;
-    private Map<String, String> namespaces = new HashMap<String, String>();
+    private final Tree root;
 
-    public DefBuilderFactory(NameMapper mapper) {
-        this.mapper = mapper;
+    public DefBuilderFactory(Tree root) {
+        this.root = root;
     }
 
     @Override
     public NodeTypeTemplateImpl newNodeTypeDefinitionBuilder() {
-        return new NodeTypeTemplateImpl(mapper);
+        return new NodeTypeTemplateImpl(new NameMapperImpl(root));
     }
 
     @Override
     public Map<String, String> getNamespaceMapping() {
-        return namespaces;
+        return Namespaces.getNamespaceMap(root);
     }
 
     @Override
     public void setNamespaceMapping(Map<String, String> namespaces) {
-        this.namespaces = namespaces;
+        throw new UnsupportedOperationException();
     }
 
     @Override
     public void setNamespace(String prefix, String uri) {
-        namespaces.put(prefix, uri);
+        if (Namespaces.getNamespaceMap(root).containsValue(uri)) {
+            return; // namespace already exists
+        }
+
+        Tree namespaces = getOrCreate(
+                JcrConstants.JCR_SYSTEM, NamespaceConstants.REP_NAMESPACES);
+        namespaces.setProperty(prefix, uri);
+    }
+
+    private Tree getOrCreate(String... path) {
+        Tree tree = root;
+        for (String name : path) {
+            Tree child = tree.getChild(name);
+            if (child == null) {
+                child = tree.addChild(name);
+            }
+            tree = child;
+        }
+        return tree;
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadWriteNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadWriteNodeTypeManager.java?rev=1399686&r1=1399685&r2=1399686&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadWriteNodeTypeManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadWriteNodeTypeManager.java
Thu Oct 18 15:01:22 2012
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.oak.plugins.nodetype;
 
 import java.io.Reader;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -139,16 +140,19 @@ public abstract class ReadWriteNodeTypeM
      * @throws RepositoryException  if registering the node types fails
      */
     public void registerNodeTypes(Reader cnd) throws ParseException, RepositoryException
{
+        Root root = getWriteRoot();
+
         CompactNodeTypeDefReader<NodeTypeTemplate, Map<String, String>> reader
=
                 new CompactNodeTypeDefReader<NodeTypeTemplate, Map<String, String>>(
-                        cnd, null, new DefBuilderFactory(getNameMapper()));
+                        cnd, null, new DefBuilderFactory(root.getTree("/")));
+
         Map<String, NodeTypeTemplate> templates = Maps.newHashMap();
         for (NodeTypeTemplate template : reader.getNodeTypeDefinitions()) {
             templates.put(template.getName(), template);
         }
+
         for (NodeTypeTemplate template : templates.values()) {
-            if (!template.isMixin()
-                    && !NT_BASE.equals(template.getName())) {
+            if (!template.isMixin() && !NT_BASE.equals(template.getName())) {
                 String[] supertypes =
                         template.getDeclaredSupertypeNames();
                 if (supertypes.length == 0) {
@@ -175,7 +179,14 @@ public abstract class ReadWriteNodeTypeM
                 }
             }
         }
-        registerNodeTypes(templates.values().toArray(new NodeTypeTemplate[templates.size()]),
true);
+
+        try {
+            internalRegister(root, templates.values(), true);
+            root.commit();
+            refresh();
+        } catch (CommitFailedException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     //----------------------------------------------------< NodeTypeManager >---
@@ -200,12 +211,9 @@ public abstract class ReadWriteNodeTypeM
             throws RepositoryException {
         // TODO handle inter-type dependencies (OAK-66)
         Root root = getWriteRoot();
-        Tree types = getOrCreateNodeTypes(root);
         try {
-            List<NodeType> list = Lists.newArrayList();
-            for (NodeTypeDefinition ntd : ntds) {
-                list.add(internalRegister(types, ntd, allowUpdate));
-            }
+            List<NodeType> list = internalRegister(
+                    root, Arrays.asList(ntds), allowUpdate);
             root.commit();
             refresh();
             return new NodeTypeIteratorAdapter(list);
@@ -214,6 +222,17 @@ public abstract class ReadWriteNodeTypeM
         }
     }
 
+    private List<NodeType> internalRegister(
+            Root root, Iterable<? extends NodeTypeDefinition> ntds,
+            boolean allowUpdate) throws RepositoryException {
+        Tree types = getOrCreateNodeTypes(root);
+        List<NodeType> list = Lists.newArrayList();
+        for (NodeTypeDefinition ntd : ntds) {
+            list.add(internalRegister(types, ntd, allowUpdate));
+        }
+        return list;
+    }
+
     private NodeType internalRegister(
             Tree types, NodeTypeDefinition ntd, boolean allowUpdate)
             throws RepositoryException {

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/tck/ApiIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/tck/ApiIT.java?rev=1399686&r1=1399685&r2=1399686&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/tck/ApiIT.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/tck/ApiIT.java
Thu Oct 18 15:01:22 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.jcr.tc
 
 import junit.framework.Test;
 import org.apache.jackrabbit.test.ConcurrentTestSuite;
+import org.apache.jackrabbit.test.api.NamespaceRegistryTest;
 
 public class ApiIT extends ConcurrentTestSuite {
 
@@ -27,6 +28,7 @@ public class ApiIT extends ConcurrentTes
 
     public ApiIT() {
         super("JCR API tests");
-        addTest(org.apache.jackrabbit.test.api.TestAll.suite());
+        addTestSuite(NamespaceRegistryTest.class);
+        // addTest(org.apache.jackrabbit.test.api.TestAll.suite());
     }
 }



Mime
View raw message