jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1460695 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype: EffectiveNodeType.java ReadOnlyNodeTypeManager.java
Date Mon, 25 Mar 2013 14:57:53 GMT
Author: jukka
Date: Mon Mar 25 14:57:52 2013
New Revision: 1460695

URL: http://svn.apache.org/r1460695
Log:
OAK-702: Optimize access to node type information

Use NodeTypeImpls instead of NodeTypes as a first step in streamlining access. WIP...
Drop unused methods.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java?rev=1460695&r1=1460694&r2=1460695&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java
Mon Mar 25 14:57:52 2013
@@ -53,39 +53,39 @@ public class EffectiveNodeType {
 
     private static final Logger log = LoggerFactory.getLogger(EffectiveNodeType.class);
 
-    private static final NodeType[] NO_MIXINS = new NodeType[0];
+    private static final NodeTypeImpl[] NO_MIXINS = new NodeTypeImpl[0];
 
-    private final Map<String, NodeType> nodeTypes = Maps.newLinkedHashMap();
+    private final Map<String, NodeTypeImpl> nodeTypes = Maps.newLinkedHashMap();
 
     private final ReadOnlyNodeTypeManager ntMgr;
 
     EffectiveNodeType(
-            NodeType primary, NodeType[] mixins,
+            NodeTypeImpl primary, NodeTypeImpl[] mixins,
             ReadOnlyNodeTypeManager ntMgr) {
         this.ntMgr = ntMgr;
 
         addNodeType(checkNotNull(primary));
-        for (NodeType mixin : checkNotNull(mixins)) {
+        for (NodeTypeImpl mixin : checkNotNull(mixins)) {
             addNodeType(mixin);
         }
     }
 
-    EffectiveNodeType(NodeType primary, ReadOnlyNodeTypeManager ntMgr) {
+    EffectiveNodeType(NodeTypeImpl primary, ReadOnlyNodeTypeManager ntMgr) {
         this(primary, NO_MIXINS, ntMgr);
     }
 
-    private void addNodeType(NodeType type) {
+    private void addNodeType(NodeTypeImpl type) {
         String name = type.getName();
         if (!nodeTypes.containsKey(name)) {
             nodeTypes.put(name, type);
             NodeType[] supertypes = type.getDeclaredSupertypes();
             if (supertypes.length > 1) {
                 for (NodeType supertype : supertypes) {
-                    addNodeType(supertype);
+                    addNodeType((NodeTypeImpl) supertype); // FIXME
                 }
             } else if (!type.isMixin() && !nodeTypes.containsKey(NT_BASE)) {
                 try {
-                    addNodeType(ntMgr.getNodeType(NT_BASE));
+                    addNodeType((NodeTypeImpl) ntMgr.getNodeType(NT_BASE)); // FIXME
                 } catch (RepositoryException e) {
                     // TODO: ignore/warning/error?
                 }
@@ -286,36 +286,6 @@ public class EffectiveNodeType {
         }
     }
 
-    public void checkAddChildNode(String name, NodeType nodeType) throws RepositoryException
{
-        NodeDefinition definition = getDefinition(name, nodeType);
-
-        if (definition.isProtected()) {
-            return;
-        }
-
-        if (nodeType == null) {
-            if (!definition.getDeclaringNodeType().canAddChildNode(name)) {
-                throw new ConstraintViolationException("Cannot add node '" + name + '\'');
-            }
-        } else {
-            if (!definition.getDeclaringNodeType().canAddChildNode(name, nodeType.getName()))
{
-                throw new ConstraintViolationException("Cannot add node '" + name + "' of
type '" + nodeType.getName() + '\'');
-            }
-        }
-    }
-
-    public void checkRemoveNode(String name, NodeType nodeType) throws RepositoryException
{
-        NodeDefinition definition = getDefinition(name, nodeType);
-
-        if (definition.isProtected()) {
-            return;
-        }
-
-        if (!definition.getDeclaringNodeType().canRemoveNode(name)) {
-            throw new ConstraintViolationException("Cannot remove node '" + name + '\'');
-        }
-    }
-
     public void checkMandatoryItems(Tree tree) throws ConstraintViolationException {
         for (NodeType nodeType : nodeTypes.values()) {
             for (PropertyDefinition pd : nodeType.getPropertyDefinitions()) {
@@ -429,31 +399,6 @@ public class EffectiveNodeType {
         return getPropertyDefinition(propertyName, isMultiple, propertyType, true);
     }
 
-    /**
-     * Calculates the applicable definition for the child node with the
-     * specified name and node type.
-     *
-     * @param nodeName The internal oak name of the child node.
-     * @param nodeType The target node type of the child.
-     * @return the applicable definition for the child node with the specified
-     * name and primary type.
-     * @throws ConstraintViolationException If no matching definition can be found.
-     * @throws RepositoryException If another error occurs.
-     */
-    private NodeDefinition getDefinition(String nodeName, NodeType nodeType)
-            throws ConstraintViolationException {
-        // FIXME: ugly hack to workaround sns-hack that was used to map sns-item definitions
with node types.
-        String nameToCheck = nodeName;
-        if (nodeName.startsWith("jcr:childNodeDefinition")) {
-            nameToCheck = nodeName.substring(0, "jcr:childNodeDefinition".length());
-        }
-        if (nodeName.startsWith("jcr:propertyDefinition")) {
-            nameToCheck = nodeName.substring(0, "jcr:propertyDefinition".length());
-        }
-        return getNodeDefinition(
-                nameToCheck, new EffectiveNodeType(nodeType, ntMgr));
-    }
-
     private static class DefinitionNamePredicate implements Predicate<ItemDefinition>
{
 
         private final String oakName;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java?rev=1460695&r1=1460694&r2=1460695&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
Mon Mar 25 14:57:52 2013
@@ -343,14 +343,19 @@ public abstract class ReadOnlyNodeTypeMa
     @Override
     public EffectiveNodeType getEffectiveNodeType(Node node)
             throws RepositoryException {
-        return new EffectiveNodeType(
-                node.getPrimaryNodeType(), node.getMixinNodeTypes(), this);
+        NodeTypeImpl primary = (NodeTypeImpl) node.getPrimaryNodeType(); // FIXME
+        NodeType[] mixins = node.getMixinNodeTypes();
+        NodeTypeImpl[] mixinImpls = new NodeTypeImpl[mixins.length];
+        for (int i = 0; i < mixins.length; i++) {
+            mixinImpls[i] = (NodeTypeImpl) mixins[i]; // FIXME
+        }
+        return new EffectiveNodeType(primary, mixinImpls, this);
     }
 
     @Override
     public EffectiveNodeType getEffectiveNodeType(Tree tree) throws RepositoryException {
 
-        NodeType primaryType;
+        NodeTypeImpl primaryType;
         PropertyState jcrPrimaryType = tree.getProperty(JCR_PRIMARYTYPE);
         if (jcrPrimaryType != null) {
             String ntName = jcrPrimaryType.getValue(STRING);
@@ -363,9 +368,9 @@ public abstract class ReadOnlyNodeTypeMa
         if (jcrMixinType == null) {
             return new EffectiveNodeType(primaryType, this);
         } else {
-            NodeType[] mixinTypes = new NodeType[jcrMixinType.count()];
+            NodeTypeImpl[] mixinTypes = new NodeTypeImpl[jcrMixinType.count()];
             for (int i = 0; i < mixinTypes.length; i++) {
-                mixinTypes[i] = getNodeType(jcrMixinType.getValue(Type.NAME, i));
+                mixinTypes[i] = internalGetNodeType(jcrMixinType.getValue(Type.NAME, i));
             }
             return new EffectiveNodeType(primaryType, mixinTypes, this);
         }



Mime
View raw message