jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1384741 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ oak-jcr/ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/
Date Fri, 14 Sep 2012 12:29:37 GMT
Author: mduerig
Date: Fri Sep 14 12:29:37 2012
New Revision: 1384741

URL: http://svn.apache.org/viewvc?rev=1384741&view=rev
Log:
OAK-66: JCR Node Type Management
normalise expanded names to prefixed names in NodeTypeTemplate and friends

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/AbstractNodeTypeManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/DefBuilderFactory.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionTemplateImpl.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/NodeTypeTemplateImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionTemplateImpl.java
    jackrabbit/oak/trunk/oak-jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/AbstractNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/AbstractNodeTypeManager.java?rev=1384741&r1=1384740&r2=1384741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/AbstractNodeTypeManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/AbstractNodeTypeManager.java
Fri Sep 14 12:29:37 2012
@@ -161,22 +161,22 @@ public abstract class AbstractNodeTypeMa
 
     @Override
     public NodeTypeTemplate createNodeTypeTemplate() throws RepositoryException {
-        return new NodeTypeTemplateImpl(this, getValueFactory());
+        return new NodeTypeTemplateImpl(this, getNameMapper(), getValueFactory());
     }
 
     @Override
     public NodeTypeTemplate createNodeTypeTemplate(NodeTypeDefinition ntd) throws RepositoryException
{
-        return new NodeTypeTemplateImpl(this, getValueFactory(), ntd);
+        return new NodeTypeTemplateImpl(this, getNameMapper(), getValueFactory(), ntd);
     }
 
     @Override
     public NodeDefinitionTemplate createNodeDefinitionTemplate() {
-        return new NodeDefinitionTemplateImpl();
+        return new NodeDefinitionTemplateImpl(getNameMapper());
     }
 
     @Override
     public PropertyDefinitionTemplate createPropertyDefinitionTemplate() {
-        return new PropertyDefinitionTemplateImpl();
+        return new PropertyDefinitionTemplateImpl(getNameMapper());
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/DefBuilderFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/DefBuilderFactory.java?rev=1384741&r1=1384740&r2=1384741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/DefBuilderFactory.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/DefBuilderFactory.java
Fri Sep 14 12:29:37 2012
@@ -22,15 +22,21 @@ import java.util.Map;
 import javax.jcr.nodetype.NodeTypeTemplate;
 
 import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory;
+import org.apache.jackrabbit.oak.namepath.NameMapper;
 
 class DefBuilderFactory extends
         DefinitionBuilderFactory<NodeTypeTemplate, Map<String, String>> {
 
+    private final NameMapper mapper;
     private Map<String, String> namespaces = new HashMap<String, String>();
 
+    public DefBuilderFactory(NameMapper mapper) {
+        this.mapper = mapper;
+    }
+
     @Override
     public NodeTypeTemplateImpl newNodeTypeDefinitionBuilder() {
-        return new NodeTypeTemplateImpl();
+        return new NodeTypeTemplateImpl(mapper);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionTemplateImpl.java?rev=1384741&r1=1384740&r2=1384741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionTemplateImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeDefinitionTemplateImpl.java
Fri Sep 14 12:29:37 2012
@@ -29,6 +29,7 @@ import javax.jcr.version.OnParentVersion
 
 import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory.AbstractNodeDefinitionBuilder;
 import org.apache.jackrabbit.oak.namepath.JcrNameParser;
+import org.apache.jackrabbit.oak.namepath.NameMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,13 +42,15 @@ class NodeDefinitionTemplateImpl
 
     private String defaultPrimaryTypeName;
 
+    private final NameMapper mapper;
     private String[] requiredPrimaryTypeNames;
 
     protected NodeType getNodeType(String name) throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    public NodeDefinitionTemplateImpl() {
+    public NodeDefinitionTemplateImpl(NameMapper mapper) {
+        this.mapper = mapper;
         onParent = OnParentVersionAction.COPY;
     }
 
@@ -69,7 +72,7 @@ class NodeDefinitionTemplateImpl
     @Override
     public void setName(String name) throws ConstraintViolationException {
         JcrNameParser.checkName(name, true);
-        this.name = name;
+        this.name = mapper.getJcrName(mapper.getOakName(name));
     }
 
     @Override
@@ -152,7 +155,7 @@ class NodeDefinitionTemplateImpl
         }
         else {
             JcrNameParser.checkName(name, false);
-            this.defaultPrimaryTypeName = name;
+            this.defaultPrimaryTypeName = mapper.getJcrName(mapper.getOakName(name));
         }
     }
 
@@ -191,21 +194,24 @@ class NodeDefinitionTemplateImpl
         if (names == null) {
             throw new ConstraintViolationException("null is not a valid array of JCR names");
         }
+        int k = 0;
+        String[] n = new String[names.length];
         for (String name : names) {
             JcrNameParser.checkName(name, false);
+            n[k++] = mapper.getJcrName(mapper.getOakName(name));
         }
-        this.requiredPrimaryTypeNames = names;
+        this.requiredPrimaryTypeNames = n;
     }
 
     @Override
     public void addRequiredPrimaryType(String name) throws ConstraintViolationException {
         JcrNameParser.checkName(name, false);
         if (requiredPrimaryTypeNames == null) {
-            requiredPrimaryTypeNames = new String[] { name };
+            requiredPrimaryTypeNames = new String[] { mapper.getJcrName(mapper.getOakName(name))
};
         } else {
             String[] names = new String[requiredPrimaryTypeNames.length + 1];
             System.arraycopy(requiredPrimaryTypeNames, 0, names, 0, requiredPrimaryTypeNames.length);
-            names[requiredPrimaryTypeNames.length] = name;
+            names[requiredPrimaryTypeNames.length] = mapper.getJcrName(mapper.getOakName(name));
             requiredPrimaryTypeNames = names;
         }
 

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=1384741&r1=1384740&r2=1384741&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
Fri Sep 14 12:29:37 2012
@@ -33,7 +33,6 @@ import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeDefinition;
 import javax.jcr.nodetype.NodeTypeExistsException;
 import javax.jcr.nodetype.NodeTypeIterator;
-import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NodeTypeTemplate;
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.version.OnParentVersionAction;
@@ -122,7 +121,7 @@ public class NodeTypeManagerImpl extends
                     try {
                         InputStream stream = NodeTypeManagerImpl.class.getResourceAsStream("builtin_nodetypes.cnd");
                         try {
-                            registerNodeTypes(NodeTypeManagerImpl.this, new InputStreamReader(stream,
"UTF-8"));
+                            registerNodeTypes(new InputStreamReader(stream, "UTF-8"));
                         } finally {
                             stream.close();
                         }
@@ -138,16 +137,14 @@ public class NodeTypeManagerImpl extends
 
     /**
      * Utility method for registering node types from a CND format.
-     * @param nodeTypeManager  mode type manager where the node types are registered.
      * @param cnd  reader for the CND
      * @throws ParseException  if parsing the CND fails
      * @throws RepositoryException  if registering the node types fails
      */
-    public static void registerNodeTypes(NodeTypeManager nodeTypeManager, InputStreamReader
cnd)
-            throws ParseException, RepositoryException {
+    public void registerNodeTypes(InputStreamReader cnd) throws ParseException, RepositoryException
{
         CompactNodeTypeDefReader<NodeTypeTemplate, Map<String, String>> reader
=
                 new CompactNodeTypeDefReader<NodeTypeTemplate, Map<String, String>>(
-                        cnd, null, new DefBuilderFactory());
+                        cnd, null, new DefBuilderFactory(mapper));
         Map<String, NodeTypeTemplate> templates = Maps.newHashMap();
         for (NodeTypeTemplate template : reader.getNodeTypeDefinitions()) {
             templates.put(template.getName(), template);
@@ -166,7 +163,7 @@ public class NodeTypeManagerImpl extends
                     for (String name : supertypes) {
                         NodeTypeDefinition st = templates.get(name);
                         if (st == null) {
-                            st = nodeTypeManager.getNodeType(name);
+                            st = getNodeType(name);
                         }
                         if (st != null && !st.isMixin()) {
                             needsNtBase = false;
@@ -181,8 +178,7 @@ public class NodeTypeManagerImpl extends
                 }
             }
         }
-        nodeTypeManager.registerNodeTypes(templates.values().toArray(
-                new NodeTypeTemplate[templates.size()]), true);
+        registerNodeTypes(templates.values().toArray(new NodeTypeTemplate[templates.size()]),
true);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeTemplateImpl.java?rev=1384741&r1=1384740&r2=1384741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeTemplateImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeTemplateImpl.java
Fri Sep 14 12:29:37 2012
@@ -34,6 +34,7 @@ import javax.jcr.nodetype.PropertyDefini
 
 import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory.AbstractNodeTypeDefinitionBuilder;
 import org.apache.jackrabbit.oak.namepath.JcrNameParser;
+import org.apache.jackrabbit.oak.namepath.NameMapper;
 import org.apache.jackrabbit.value.ValueFactoryImpl;
 
 final class NodeTypeTemplateImpl
@@ -42,6 +43,8 @@ final class NodeTypeTemplateImpl
 
     private final NodeTypeManager manager;
 
+    private final NameMapper mapper;
+
     private final ValueFactory factory;
 
     private String primaryItemName;
@@ -52,19 +55,20 @@ final class NodeTypeTemplateImpl
 
     private List<NodeDefinitionTemplate> nodeDefinitionTemplates;
 
-    public NodeTypeTemplateImpl(NodeTypeManager manager, ValueFactory factory) {
+    public NodeTypeTemplateImpl(NodeTypeManager manager, NameMapper mapper, ValueFactory
factory) {
         this.manager = manager;
+        this.mapper = mapper;
         this.factory = factory;
     }
 
-    public NodeTypeTemplateImpl() {
-        this(null, ValueFactoryImpl.getInstance());
+    public NodeTypeTemplateImpl(NameMapper mapper) {
+        this(null, mapper, ValueFactoryImpl.getInstance());
     }
 
     public NodeTypeTemplateImpl(
-            NodeTypeManager manager, ValueFactory factory,
+            NodeTypeManager manager, NameMapper mapper, ValueFactory factory,
             NodeTypeDefinition ntd) throws ConstraintViolationException {
-        this(manager, factory);
+        this(manager, mapper, factory);
 
         setName(ntd.getName());
         setAbstract(ntd.isAbstract());
@@ -119,7 +123,7 @@ final class NodeTypeTemplateImpl
 
     @Override
     public PropertyDefinitionTemplateImpl newPropertyDefinitionBuilder() {
-        return new PropertyDefinitionTemplateImpl() {
+        return new PropertyDefinitionTemplateImpl(mapper) {
             @Override
             protected Value createValue(String value) {
                 return factory.createValue(value);
@@ -133,7 +137,7 @@ final class NodeTypeTemplateImpl
 
     @Override
     public NodeDefinitionTemplateImpl newNodeDefinitionBuilder() {
-        return new NodeDefinitionTemplateImpl() {
+        return new NodeDefinitionTemplateImpl(mapper) {
             @Override
             protected NodeType getNodeType(String name)
                     throws RepositoryException  {
@@ -158,7 +162,7 @@ final class NodeTypeTemplateImpl
     @Override
     public void setName(String name) throws ConstraintViolationException {
         JcrNameParser.checkName(name, false);
-        this.name = name;
+        this.name = mapper.getJcrName(mapper.getOakName(name));
     }
 
     @Override
@@ -213,7 +217,7 @@ final class NodeTypeTemplateImpl
         }
         else {
             JcrNameParser.checkName(name, false);
-            this.primaryItemName = name;
+            this.primaryItemName = mapper.getJcrName(mapper.getOakName(name));
         }
     }
 
@@ -227,10 +231,13 @@ final class NodeTypeTemplateImpl
         if (names == null) {
             throw new ConstraintViolationException("null is not a valid array of JCR names");
         }
+        int k = 0;
+        String[] n = new String[names.length];
         for (String name : names) {
             JcrNameParser.checkName(name, false);
+            n[k++] = mapper.getJcrName(mapper.getOakName(name));
         }
-        this.superTypeNames = names;
+        this.superTypeNames = n;
     }
 
     @Override
@@ -238,7 +245,7 @@ final class NodeTypeTemplateImpl
         JcrNameParser.checkName(name, false);
         String[] names = new String[superTypeNames.length + 1];
         System.arraycopy(superTypeNames, 0, names, 0, superTypeNames.length);
-        names[superTypeNames.length] = name;
+        names[superTypeNames.length] = mapper.getJcrName(mapper.getOakName(name));
         superTypeNames = names;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionTemplateImpl.java?rev=1384741&r1=1384740&r2=1384741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionTemplateImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/PropertyDefinitionTemplateImpl.java
Fri Sep 14 12:29:37 2012
@@ -28,6 +28,7 @@ import javax.jcr.version.OnParentVersion
 
 import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory.AbstractPropertyDefinitionBuilder;
 import org.apache.jackrabbit.oak.namepath.JcrNameParser;
+import org.apache.jackrabbit.oak.namepath.NameMapper;
 
 class PropertyDefinitionTemplateImpl
         extends AbstractPropertyDefinitionBuilder<NodeTypeTemplate>
@@ -35,9 +36,11 @@ class PropertyDefinitionTemplateImpl
 
     private String[] valueConstraints;
 
+    private final NameMapper mapper;
     private Value[] defaultValues;
 
-    public PropertyDefinitionTemplateImpl() {
+    public PropertyDefinitionTemplateImpl(NameMapper mapper) {
+        this.mapper = mapper;
         onParent = OnParentVersionAction.COPY;
         requiredType = PropertyType.STRING;
     }
@@ -64,7 +67,7 @@ class PropertyDefinitionTemplateImpl
     @Override
     public void setName(String name) throws ConstraintViolationException {
         JcrNameParser.checkName(name, true);
-        this.name = name;
+        this.name = mapper.getJcrName(mapper.getOakName(name));
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1384741&r1=1384740&r2=1384741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Fri Sep 14 12:29:37 2012
@@ -67,9 +67,6 @@ org.apache.jackrabbit.test.api.nodetype.
 org.apache.jackrabbit.test.api.nodetype.CanSetPropertyDoubleTest#testConversionsMultiple
 <!-- OAK-302 -->
 org.apache.jackrabbit.test.api.nodetype.CanSetPropertyLongTest#testConversions          
 <!-- OAK-302 -->
 org.apache.jackrabbit.test.api.nodetype.CanSetPropertyLongTest#testConversionsMultiple  
 <!-- OAK-302 -->
-org.apache.jackrabbit.test.api.nodetype.NodeTypeCreationTest#testNewNodeTypeTemplate    
 <!-- OAK-66 -->
-org.apache.jackrabbit.test.api.nodetype.NodeTypeCreationTest#testPropertyDefinitionTemplate
      <!-- OAK-66 -->
-org.apache.jackrabbit.test.api.nodetype.NodeTypeCreationTest#testNodeDefinitionTemplate 
 <!-- OAK-66 -->
 org.apache.jackrabbit.test.api.SetPropertyAssumeTypeTest#testValueConstraintViolationExceptionBecauseOfInvalidTypeParameter
 org.apache.jackrabbit.test.api.SetPropertyAssumeTypeTest#testValuesConstraintViolationExceptionBecauseOfInvalidTypeParameter
 org.apache.jackrabbit.test.api.SetPropertyAssumeTypeTest#testStringConstraintViolationExceptionBecauseOfInvalidTypeParameter

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java?rev=1384741&r1=1384740&r2=1384741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java
Fri Sep 14 12:29:37 2012
@@ -67,7 +67,10 @@ public class TestContentLoader {
     private static void registerTestNodeTypes(NodeTypeManager ntm) throws RepositoryException,
ParseException, IOException {
         InputStream stream = TestContentLoader.class.getResourceAsStream("test_nodetypes.cnd");
         try {
-            NodeTypeManagerImpl.registerNodeTypes(ntm, new InputStreamReader(stream, "UTF-8"));
+            if (!(ntm instanceof NodeTypeManagerImpl)) {
+                throw new IllegalArgumentException("Need NodeTypeManagerImpl");
+            }
+            ((NodeTypeManagerImpl)ntm).registerNodeTypes(new InputStreamReader(stream, "UTF-8"));
         } finally {
             stream.close();
         }



Mime
View raw message