jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1371188 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: plugins/type/ util/
Date Thu, 09 Aug 2012 13:03:06 GMT
Author: angela
Date: Thu Aug  9 13:03:05 2012
New Revision: 1371188

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

- move NodeUtil to common utility package
- add helper methods for creating child including setting primary type and simplify node type
registration accordingly
- resolve TODO in NodeTypeManagerImpl#getOakName + use it in favor of mapper.getOakName

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
  (contents, props changed)
      - copied, changed from r1370710, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeUtil.java
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeUtil.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ItemDefinitionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ItemDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ItemDefinitionImpl.java?rev=1371188&r1=1371187&r2=1371188&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ItemDefinitionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ItemDefinitionImpl.java
Thu Aug  9 13:03:05 2012
@@ -20,6 +20,7 @@ import javax.jcr.nodetype.ItemDefinition
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.version.OnParentVersionAction;
 
+import org.apache.jackrabbit.oak.util.NodeUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionImpl.java?rev=1371188&r1=1371187&r2=1371188&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionImpl.java
Thu Aug  9 13:03:05 2012
@@ -24,6 +24,7 @@ import javax.jcr.nodetype.NodeDefinition
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeManager;
 
+import org.apache.jackrabbit.oak.util.NodeUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java?rev=1371188&r1=1371187&r2=1371188&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
Thu Aug  9 13:03:05 2012
@@ -36,6 +36,7 @@ import javax.jcr.nodetype.NodeTypeManage
 import javax.jcr.nodetype.PropertyDefinition;
 
 import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
+import org.apache.jackrabbit.oak.util.NodeUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java?rev=1371188&r1=1371187&r2=1371188&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java
Thu Aug  9 13:03:05 2012
@@ -51,6 +51,7 @@ import org.apache.jackrabbit.oak.namepat
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+import org.apache.jackrabbit.oak.util.NodeUtil;
 
 public class NodeTypeManagerImpl implements NodeTypeManager, NodeTypeConstants {
 
@@ -115,8 +116,8 @@ public class NodeTypeManagerImpl impleme
         }
     }
 
-    protected String getOakName(String name) throws RepositoryException {
-        return name; // TODO
+    protected String getOakName(String jcrName) throws RepositoryException {
+        return mapper.getOakName(jcrName);
     }
 
     /**
@@ -135,14 +136,14 @@ public class NodeTypeManagerImpl impleme
     @Override
     public boolean hasNodeType(String name) throws RepositoryException {
         Tree types = session.getCurrentRoot().getTree(NODE_TYPES_PATH);
-        return types != null && types.hasChild(mapper.getOakName(name));
+        return types != null && types.hasChild(getOakName(name));
     }
 
     @Override
     public NodeType getNodeType(String name) throws RepositoryException {
         Tree types = session.getCurrentRoot().getTree(NODE_TYPES_PATH);
         if (types != null) {
-            Tree type = types.getChild(mapper.getOakName(name));
+            Tree type = types.getChild(getOakName(name));
             if (type != null) {
                 return new NodeTypeImpl(this, factory, new NodeUtil(
                         session.getCoreValueFactory(), mapper, type));
@@ -246,7 +247,7 @@ public class NodeTypeManagerImpl impleme
             Tree types, NodeTypeDefinition ntd, boolean allowUpdate)
             throws RepositoryException {
         String jcrName = ntd.getName();
-        String oakName = mapper.getOakName(jcrName);
+        String oakName = getOakName(jcrName);
 
         Tree type = types.getChild(oakName);
         if (type != null) {
@@ -275,16 +276,14 @@ public class NodeTypeManagerImpl impleme
 
         int pdn = 1;
         for (PropertyDefinition pd : ntd.getDeclaredPropertyDefinitions()) {
-            Tree def = type.addChild(JCR_PROPERTYDEFINITION + pdn++);
-            internalRegisterPropertyDefinition(
-                    new NodeUtil(factory, mapper, def), pd);
+            NodeUtil def = node.addChild(JCR_PROPERTYDEFINITION + pdn++, NT_PROPERTYDEFINITION);
+            internalRegisterPropertyDefinition(def, pd);
         }
 
         int ndn = 1;
         for (NodeDefinition nd : ntd.getDeclaredChildNodeDefinitions()) {
-            Tree def = type.addChild(JCR_CHILDNODEDEFINITION + ndn++);
-            internalRegisterNodeDefinition(
-                    new NodeUtil(factory, mapper, def), nd);
+            NodeUtil def = node.addChild(JCR_CHILDNODEDEFINITION + ndn++, NT_CHILDNODEDEFINITION);
+            internalRegisterNodeDefinition(def, nd);
         }
 
         return new NodeTypeImpl(this, this.factory, node);
@@ -306,7 +305,6 @@ public class NodeTypeManagerImpl impleme
 
     private void internalRegisterPropertyDefinition(
             NodeUtil node, PropertyDefinition def) {
-        node.setName(JCR_PRIMARYTYPE, NT_PROPERTYDEFINITION);
         internalRegisterItemDefinition(node, def);
 
         node.setString(
@@ -329,7 +327,6 @@ public class NodeTypeManagerImpl impleme
     }
 
     private void internalRegisterNodeDefinition(NodeUtil node, NodeDefinition def) {
-        node.setName(JCR_PRIMARYTYPE, NT_CHILDNODEDEFINITION);
         internalRegisterItemDefinition(node, def);
 
         node.setBoolean(JCR_SAMENAMESIBLINGS, def.allowsSameNameSiblings());
@@ -360,7 +357,7 @@ public class NodeTypeManagerImpl impleme
         Root root = session.getCurrentRoot();
         Tree types = root.getTree(NODE_TYPES_PATH);
         if (types != null) {
-            type = types.getChild(mapper.getOakName(name));
+            type = types.getChild(getOakName(name));
         }
         if (type == null) {
             throw new NoSuchNodeTypeException("Node type " + name + " can not be unregistered.");
@@ -385,7 +382,7 @@ public class NodeTypeManagerImpl impleme
 
         try {
             for (String name : names) {
-                Tree type = types.getChild(mapper.getOakName(name));
+                Tree type = types.getChild(getOakName(name));
                 if (type == null) {
                     throw new NoSuchNodeTypeException("Node type " + name + " can not be
unregistered.");
                 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionImpl.java?rev=1371188&r1=1371187&r2=1371188&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionImpl.java
Thu Aug  9 13:03:05 2012
@@ -23,6 +23,7 @@ import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.query.qom.QueryObjectModelConstants;
 
+import org.apache.jackrabbit.oak.util.NodeUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
(from r1370710, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeUtil.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeUtil.java&r1=1370710&r2=1371188&rev=1371188&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
Thu Aug  9 13:03:05 2012
@@ -14,17 +14,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.oak.plugins.type;
+package org.apache.jackrabbit.oak.util;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 
 import com.google.common.collect.Lists;
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.PropertyState;
@@ -34,9 +37,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Utility class for accessing typed content of a node.
+ * Utility class for accessing and writing typed content of a tree.
  */
-class NodeUtil {
+public class NodeUtil {
 
     private static final Logger log = LoggerFactory.getLogger(NodeUtil.class);
 
@@ -52,14 +55,47 @@ class NodeUtil {
         this.tree = tree;
     }
 
-    public void remove(String name) {
-        tree.removeProperty(name);
+    @Nonnull
+    public Tree getTree() {
+        return tree;
     }
 
+    @Nonnull
     public String getName() {
         return mapper.getJcrName(tree.getName());
     }
 
+    public boolean hasChild(String name) {
+        return tree.getChild(name) != null;
+    }
+
+    @CheckForNull
+    public NodeUtil getChild(String name) {
+        Tree child = tree.getChild(name);
+        return (child == null) ? null : new NodeUtil(factory, mapper, child);
+    }
+
+    @Nonnull
+    public NodeUtil addChild(String name, String primaryNodeTypeName) {
+        Tree child = tree.addChild(name);
+        NodeUtil childUtil = new NodeUtil(factory, mapper, child);
+        childUtil.setName(JcrConstants.JCR_PRIMARYTYPE, primaryNodeTypeName);
+        return childUtil;
+    }
+
+    public NodeUtil getOrAddChild(String name, String primaryTypeName) {
+        NodeUtil child = getChild(name);
+        return (child != null) ? child : addChild(name, primaryTypeName);
+    }
+
+    public boolean hasPrimaryNodeTypeName(String ntName) {
+        return ntName.equals(getString(JcrConstants.JCR_PRIMARYTYPE, null));
+    }
+
+    public void removeProperty(String name) {
+        tree.removeProperty(name);
+    }
+
     public boolean getBoolean(String name) {
         PropertyState property = tree.getProperty(name);
         return property != null && !property.isArray()

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message