jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1360963 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeManagerImpl.java
Date Thu, 12 Jul 2012 21:34:14 GMT
Author: jukka
Date: Thu Jul 12 21:34:14 2012
New Revision: 1360963

URL: http://svn.apache.org/viewvc?rev=1360963&view=rev
Log:
OAK-66: JCR Node Type Management

Add-hoc solution to allow the TypeValidator see tyeps that have been registered through the
NodeTypeManager

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeManagerImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java?rev=1360963&r1=1360962&r2=1360963&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
Thu Jul 12 21:34:14 2012
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.plugins.type;
 
-import java.util.Collections;
 import java.util.Set;
 
 import javax.jcr.nodetype.NoSuchNodeTypeException;

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeManagerImpl.java?rev=1360963&r1=1360962&r2=1360963&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeManagerImpl.java
Thu Jul 12 21:34:14 2012
@@ -35,18 +35,25 @@ import javax.jcr.nodetype.NodeTypeTempla
 import javax.jcr.nodetype.PropertyDefinitionTemplate;
 
 import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.core.DefaultConflictHandler;
 import org.apache.jackrabbit.oak.jcr.SessionDelegate;
 import org.apache.jackrabbit.oak.jcr.value.ValueFactoryImpl;
 import org.apache.jackrabbit.oak.namepath.NameMapper;
 
 public class NodeTypeManagerImpl implements NodeTypeManager {
 
+    private final ContentSession cs;
     private final ValueFactoryImpl vf;
     private final NameMapper mapper;
     private final NodeTypeManagerDelegate ntmd;
     private final Map<String, NodeType> typemap = new HashMap<String, NodeType>();
 
     public NodeTypeManagerImpl(SessionDelegate sd, NodeTypeManagerDelegate ntmd) throws RepositoryException
{
+        this.cs = sd.getContentSession();
         this.vf = sd.getValueFactory();
         this.mapper = sd.getNamePathMapper();
         this.ntmd = ntmd;
@@ -134,23 +141,51 @@ public class NodeTypeManagerImpl impleme
     @Override
     public NodeType registerNodeType(NodeTypeDefinition ntd, boolean allowUpdate) throws
RepositoryException {
         // TODO proper node type registration... (OAK-66)
+        try {
+            Root root = cs.getCurrentRoot();
+            NodeType type = internalRegister(ntd, root.getTree("/"));
+            root.commit(DefaultConflictHandler.OURS);
+            return type;
+        } catch (CommitFailedException e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+    @Override
+    public NodeTypeIterator registerNodeTypes(NodeTypeDefinition[] ntds, boolean allowUpdate)
throws RepositoryException {
+        // TODO handle inter-type dependencies (OAK-66)
+        try {
+            Root root = cs.getCurrentRoot();
+            NodeType[] types = new NodeType[ntds.length];
+            for (int i = 0; i < ntds.length; i++) {
+                types[i] = internalRegister(ntds[i], root.getTree("/"));
+            }
+            root.commit(DefaultConflictHandler.OURS);
+            return new NodeTypeIteratorAdapter(Arrays.asList(types));
+        } catch (CommitFailedException e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+    private NodeType internalRegister(NodeTypeDefinition ntd, Tree root) {
         NodeTypeDelegate delegate = new NodeTypeDelegate(
                 ntd.getName(),
                 ntd.getDeclaredSupertypeNames(), ntd.getPrimaryItemName(),
                 ntd.isMixin(), ntd.isAbstract(), ntd.hasOrderableChildNodes());
         NodeType type = new NodeTypeImpl(this, vf, mapper, delegate);
         typemap.put(ntd.getName(), type);
-        return type;
-    }
 
-    @Override
-    public NodeTypeIterator registerNodeTypes(NodeTypeDefinition[] ntds, boolean allowUpdate)
throws RepositoryException {
-        // TODO handle inter-type dependencies (OAK-66)
-        NodeType[] types = new NodeType[ntds.length];
-        for (int i = 0; i < ntds.length; i++) {
-            types[i] = registerNodeType(ntds[i], allowUpdate);
+        Tree system = root.getChild("jcr:system");
+        if (system == null) {
+            system = root.addChild("jcr:system");
+        }
+        Tree nodetypes = system.getChild("jcr:nodeTypes");
+        if (nodetypes == null) {
+            nodetypes = system.addChild("jcr:nodeTypes");
         }
-        return new NodeTypeIteratorAdapter(Arrays.asList(types));
+        nodetypes.addChild(ntd.getName());
+
+        return type;
     }
 
     @Override



Mime
View raw message