You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2012/09/19 17:35:25 UTC

svn commit: r1387644 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: core/ContentSessionImpl.java plugins/type/BuiltInNodeTypes.java plugins/type/ReadWriteNodeTypeManager.java

Author: mreutegg
Date: Wed Sep 19 15:35:24 2012
New Revision: 1387644

URL: http://svn.apache.org/viewvc?rev=1387644&view=rev
Log:
OAK-315: Separate built-in node types from ReadWriteNodeTypeManager

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/BuiltInNodeTypes.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentSessionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ReadWriteNodeTypeManager.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentSessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentSessionImpl.java?rev=1387644&r1=1387643&r2=1387644&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentSessionImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentSessionImpl.java Wed Sep 19 15:35:24 2012
@@ -28,7 +28,7 @@ import org.apache.jackrabbit.oak.api.Con
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.SessionQueryEngine;
-import org.apache.jackrabbit.oak.plugins.type.ReadWriteNodeTypeManager;
+import org.apache.jackrabbit.oak.plugins.type.BuiltInNodeTypes;
 import org.apache.jackrabbit.oak.query.QueryEngineImpl;
 import org.apache.jackrabbit.oak.query.SessionQueryEngineImpl;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
@@ -78,7 +78,7 @@ class ContentSessionImpl implements Cont
         synchronized (this) {
             if (!initialised) {
                 initialised = true;
-                ReadWriteNodeTypeManager.registerBuiltInNodeTypes(getLatestRoot());
+                BuiltInNodeTypes.register(getLatestRoot());
             }
         }
 

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/BuiltInNodeTypes.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/BuiltInNodeTypes.java?rev=1387644&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/BuiltInNodeTypes.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/BuiltInNodeTypes.java Wed Sep 19 15:35:24 2012
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.type;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.security.PrivilegedAction;
+
+import javax.annotation.Nonnull;
+import javax.security.auth.Subject;
+
+import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal;
+
+import static org.apache.jackrabbit.oak.plugins.type.NodeTypeConstants.NODE_TYPES_PATH;
+
+/**
+ * <code>BuiltInNodeTypes</code> is a utility class that registers the built-in
+ * node types required for a JCR repository running on Oak.
+ */
+public class BuiltInNodeTypes {
+
+    private final ReadWriteNodeTypeManager ntMgr;
+
+    private BuiltInNodeTypes(final Root root) {
+        this.ntMgr =  new ReadWriteNodeTypeManager() {
+            @Override
+            protected Tree getTypes() {
+                return root.getTree(NODE_TYPES_PATH);
+            }
+
+            @Nonnull
+            @Override
+            protected Root getWriteRoot() {
+                return root;
+            }
+        };
+    }
+
+    /**
+     * Registers built in node types using the given {@link Root}.
+     *
+     * @param root the {@link Root} instance.
+     */
+    public static void register(final Root root) {
+        new BuiltInNodeTypes(root).registerBuiltinNodeTypes();
+    }
+
+    private void registerBuiltinNodeTypes() {
+        // FIXME: migrate custom node types as well.
+        // FIXME: registration of built-in node types should be moved to repo-setup
+        //        as the jcr:nodetypes tree is protected and the editing session may
+        //        not have sufficient permission to register node types or may
+        //        even have limited read-permission on the jcr:nodetypes path.
+        if (!nodeTypesInContent()) {
+            Subject admin = new Subject();
+            admin.getPrincipals().add(AdminPrincipal.INSTANCE);
+            Subject.doAs(admin, new PrivilegedAction<Void>() {
+                @Override
+                public Void run() {
+                    try {
+                        InputStream stream = BuiltInNodeTypes.class.getResourceAsStream("builtin_nodetypes.cnd");
+                        try {
+                            ntMgr.registerNodeTypes(new InputStreamReader(stream, "UTF-8"));
+                        } finally {
+                            stream.close();
+                        }
+                    } catch (Exception e) {
+                        throw new IllegalStateException(
+                                "Unable to load built-in node types", e);
+                    }
+                    return null;
+                }
+            });
+        }
+    }
+
+    private boolean nodeTypesInContent() {
+        Tree types = ntMgr.getTypes();
+        return types != null && types.getChildrenCount() > 0;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/BuiltInNodeTypes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/BuiltInNodeTypes.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ReadWriteNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ReadWriteNodeTypeManager.java?rev=1387644&r1=1387643&r2=1387644&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ReadWriteNodeTypeManager.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ReadWriteNodeTypeManager.java Wed Sep 19 15:35:24 2012
@@ -16,9 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.type;
 
-import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.security.PrivilegedAction;
 import java.util.List;
 import java.util.Map;
 
@@ -36,7 +34,6 @@ import javax.jcr.nodetype.NodeTypeIterat
 import javax.jcr.nodetype.NodeTypeTemplate;
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.version.OnParentVersionAction;
-import javax.security.auth.Subject;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
@@ -47,7 +44,6 @@ import org.apache.jackrabbit.oak.api.Com
 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.spi.security.principal.AdminPrincipal;
 import org.apache.jackrabbit.oak.util.NodeUtil;
 
 import static org.apache.jackrabbit.JcrConstants.JCR_AUTOCREATED;
@@ -138,56 +134,6 @@ public abstract class ReadWriteNodeTypeM
     }
 
     /**
-     * Registers built in node types using the given {@link Root}.
-     *
-     * @param root the {@link Root} instance.
-     */
-    public static void registerBuiltInNodeTypes(final Root root) {
-        ReadWriteNodeTypeManager ntMgr = new ReadWriteNodeTypeManager() {
-            @Override
-            protected Tree getTypes() {
-                return root.getTree(NODE_TYPES_PATH);
-            }
-
-            @Nonnull
-            @Override
-            protected Root getWriteRoot() {
-                return root;
-            }
-        };
-        ntMgr.registerBuiltinNodeTypes();
-    }
-
-    private void registerBuiltinNodeTypes() {
-        // FIXME: migrate custom node types as well.
-        // FIXME: registration of built-in node types should be moved to repo-setup
-        //        as the jcr:nodetypes tree is protected and the editing session may
-        //        not have sufficient permission to register node types or may
-        //        even have limited read-permission on the jcr:nodetypes path.
-        if (!nodeTypesInContent()) {
-            Subject admin = new Subject();
-            admin.getPrincipals().add(AdminPrincipal.INSTANCE);
-            Subject.doAs(admin, new PrivilegedAction<Void>() {
-                @Override
-                public Void run() {
-                    try {
-                        InputStream stream = ReadWriteNodeTypeManager.class.getResourceAsStream("builtin_nodetypes.cnd");
-                        try {
-                            registerNodeTypes(new InputStreamReader(stream, "UTF-8"));
-                        } finally {
-                            stream.close();
-                        }
-                    } catch (Exception e) {
-                        throw new IllegalStateException(
-                                "Unable to load built-in node types", e);
-                    }
-                    return null;
-                }
-            });
-        }
-    }
-
-    /**
      * Utility method for registering node types from a CND format.
      * @param cnd  reader for the CND
      * @throws ParseException  if parsing the CND fails
@@ -389,11 +335,6 @@ public abstract class ReadWriteNodeTypeM
         return types;
     }
 
-    private boolean nodeTypesInContent() {
-        Tree types = getTypes();
-        return types != null && types.getChildrenCount() > 0;
-    }
-
     @Override
     public void unregisterNodeType(String name) throws RepositoryException {
         Tree type = null;