jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1355036 - in /jackrabbit/oak/trunk/oak-jcr/src/main: java/org/apache/jackrabbit/oak/jcr/ java/org/apache/jackrabbit/oak/jcr/nodetype/ resources/org/apache/jackrabbit/oak/jcr/nodetype/
Date Thu, 28 Jun 2012 15:04:59 GMT
Author: reschke
Date: Thu Jun 28 15:04:57 2012
New Revision: 1355036

URL: http://svn.apache.org/viewvc?rev=1355036&view=rev
Log:
OAK-66: handle namespace declarations in CNDs (but do not register new namespaces yet (?))

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeManagerImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/resources/org/apache/jackrabbit/oak/jcr/nodetype/builtin_nodetypes.cnd

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java?rev=1355036&r1=1355035&r2=1355036&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
Thu Jun 28 15:04:57 2012
@@ -62,7 +62,7 @@ public class WorkspaceImpl implements Ja
     public WorkspaceImpl(SessionDelegate sessionDelegate)
             throws RepositoryException {
         this.sessionDelegate = sessionDelegate;
-        this.nodeTypeManager = new NodeTypeManagerImpl(sessionDelegate.getValueFactory(),
sessionDelegate.getNamePathMapper());
+        this.nodeTypeManager = new NodeTypeManagerImpl(sessionDelegate);
         this.queryManager = new QueryManagerImpl(sessionDelegate);
         this.lockManager = new LockManagerImpl(sessionDelegate.getSession());
     }

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=1355036&r1=1355035&r2=1355036&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 Jun 28 15:04:57 2012
@@ -16,18 +16,18 @@
  */
 package org.apache.jackrabbit.oak.jcr.nodetype;
 
-import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader;
-import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory;
-import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory.AbstractNodeDefinitionBuilder;
-import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory.AbstractNodeTypeDefinitionBuilder;
-import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory.AbstractPropertyDefinitionBuilder;
-import org.apache.jackrabbit.commons.cnd.ParseException;
-import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
-import org.apache.jackrabbit.oak.api.CoreValue;
-import org.apache.jackrabbit.oak.api.CoreValueFactory;
-import org.apache.jackrabbit.oak.jcr.value.ValueFactoryImpl;
-import org.apache.jackrabbit.oak.namepath.NameMapper;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
+import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
@@ -38,34 +38,40 @@ import javax.jcr.nodetype.NodeTypeIterat
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NodeTypeTemplate;
 import javax.jcr.nodetype.PropertyDefinitionTemplate;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+
+import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader;
+import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory;
+import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory.AbstractNodeDefinitionBuilder;
+import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory.AbstractNodeTypeDefinitionBuilder;
+import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory.AbstractPropertyDefinitionBuilder;
+import org.apache.jackrabbit.commons.cnd.ParseException;
+import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
+import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.api.CoreValueFactory;
+import org.apache.jackrabbit.oak.jcr.SessionDelegate;
+import org.apache.jackrabbit.oak.jcr.value.ValueFactoryImpl;
+import org.apache.jackrabbit.oak.namepath.NameMapper;
+import org.apache.jackrabbit.oak.plugins.name.NamespaceRegistryImpl;
 
 public class NodeTypeManagerImpl implements NodeTypeManager {
 
     private final ValueFactoryImpl vf;
     private final NameMapper mapper;
+    private final NamespaceRegistry nsregistry;
     private final List<NodeTypeDelegate> typeDelegates;
 
     private final Map<String, NodeType> typemap = new HashMap<String, NodeType>();
 
-    public NodeTypeManagerImpl(ValueFactoryImpl vf, NameMapper mapper) throws RepositoryException
{
-        this.vf = vf;
-        this.mapper = mapper;
+    public NodeTypeManagerImpl(SessionDelegate sd) throws RepositoryException {
+        this.vf = sd.getValueFactory();
+        this.mapper = sd.getNamePathMapper();
+        this.nsregistry = new NamespaceRegistryImpl(sd.getContentSession());
 
         try {
             InputStream stream = NodeTypeManagerImpl.class.getResourceAsStream("builtin_nodetypes.cnd");
             Reader reader = new InputStreamReader(stream, "UTF-8");
             try {
-                DefinitionBuilderFactory<NodeTypeDelegate, Map<String, String>>
dbf = new DefinitionDelegateBuilderFactory(vf);
+                DefinitionBuilderFactory<NodeTypeDelegate, Map<String, String>>
dbf = new DefinitionDelegateBuilderFactory();
                 CompactNodeTypeDefReader<NodeTypeDelegate, Map<String, String>>
cndr = new CompactNodeTypeDefReader<NodeTypeDelegate, Map<String, String>>(
                         reader, null, dbf);
 
@@ -192,13 +198,7 @@ public class NodeTypeManagerImpl impleme
     private class DefinitionDelegateBuilderFactory extends DefinitionBuilderFactory<NodeTypeDelegate,
Map<String, String>> {
 
         private Map<String, String> nsmap = new HashMap<String, String>();
-
-        private final ValueFactoryImpl vf;
-
-        public DefinitionDelegateBuilderFactory(ValueFactoryImpl vf) {
-            this.vf = vf;
-        }
-
+        
         @Override
         public Map<String, String> getNamespaceMapping() {
             return nsmap;
@@ -206,7 +206,7 @@ public class NodeTypeManagerImpl impleme
 
         @Override
         public AbstractNodeTypeDefinitionBuilder<NodeTypeDelegate> newNodeTypeDefinitionBuilder()
throws RepositoryException {
-            return new NodeTypeDefinitionDelegateBuilder(vf);
+            return new NodeTypeDefinitionDelegateBuilder(this);
         }
 
         @Override
@@ -218,6 +218,37 @@ public class NodeTypeManagerImpl impleme
         public void setNamespaceMapping(Map<String, String> nsmap) {
             this.nsmap = nsmap;
         }
+
+        public String convertNameToOak(String cndName) throws RepositoryException {
+            if (cndName == null) {
+                return null;
+            } else {
+                int pos = cndName.indexOf(":");
+                if (pos < 0) {
+                    // no colon
+                    return cndName;
+                } else {
+                    String pref = cndName.substring(0, pos);
+                    String name = cndName.substring(pos + 1);
+                    String ns = nsmap.get(pref);
+
+                    if (ns == null) {
+                        throw new RepositoryException("no namespace defined for prefix "
+ pref);
+                    } else {
+                        String oakprefix = nsregistry.getPrefix(ns);
+                        return oakprefix + ":" + name;
+                    }
+                }
+            }
+        }
+
+        public List<String> convertNamesToOak(List<String> cndNames) throws RepositoryException
{
+            List<String> result = new ArrayList<String>();
+            for (String cndName : cndNames) {
+                result.add(convertNameToOak(cndName));
+            }
+            return result;
+        }
     }
 
     private class NodeTypeDefinitionDelegateBuilder extends AbstractNodeTypeDefinitionBuilder<NodeTypeDelegate>
{
@@ -225,13 +256,13 @@ public class NodeTypeManagerImpl impleme
         private final List<PropertyDefinitionDelegateBuilder> propertyDefinitions =
new ArrayList<PropertyDefinitionDelegateBuilder>();
         private final List<NodeDefinitionDelegateBuilder> childNodeDefinitions = new
ArrayList<NodeDefinitionDelegateBuilder>();
 
-        private final ValueFactoryImpl vf;
+        private final DefinitionDelegateBuilderFactory ddbf;
 
         private String primaryItemName;
-        private final List<String> declaredSuperTypes = new ArrayList<String>();
+        private List<String> declaredSuperTypes = new ArrayList<String>();
 
-        public NodeTypeDefinitionDelegateBuilder(ValueFactoryImpl vf) {
-            this.vf = vf;
+        public NodeTypeDefinitionDelegateBuilder(DefinitionDelegateBuilderFactory ddbf) {
+            this.ddbf = ddbf;
         }
 
         @Override
@@ -257,6 +288,10 @@ public class NodeTypeManagerImpl impleme
         @Override
         public NodeTypeDelegate build() throws RepositoryException {
 
+            name = ddbf.convertNameToOak(name);
+            declaredSuperTypes = ddbf.convertNamesToOak(declaredSuperTypes);
+            primaryItemName = ddbf.convertNameToOak(primaryItemName);
+
             NodeTypeDelegate result = new NodeTypeDelegate(name, declaredSuperTypes.toArray(new
String[declaredSuperTypes.size()]),
                     primaryItemName, isMixin, isAbstract, isOrderable);
 
@@ -278,6 +313,10 @@ public class NodeTypeManagerImpl impleme
         public void addNodeDefinition(NodeDefinitionDelegateBuilder nd) {
             this.childNodeDefinitions.add(nd);
         }
+
+        public String convertNameToOak(String name) throws RepositoryException {
+            return ddbf.convertNameToOak(name);
+        }
     }
 
     private class NodeDefinitionDelegateBuilder extends AbstractNodeDefinitionBuilder<NodeTypeDelegate>
{
@@ -330,14 +369,17 @@ public class NodeTypeManagerImpl impleme
             this.ndtb = ntdb;
         }
 
-        public PropertyDefinitionDelegate getPropertyDefinitionDelegate(CoreValueFactory
cvf) {
+        public PropertyDefinitionDelegate getPropertyDefinitionDelegate(CoreValueFactory
cvf) throws RepositoryException {
 
             CoreValue[] defaultCoreValues = new CoreValue[defaultValues.size()];
 
             for (int i = 0; i < defaultCoreValues.length; i++) {
+                // TODO: need name mapping?
                 defaultCoreValues[i] = cvf.createValue(defaultValues.get(i), requiredType);
             }
 
+            name = ndtb.convertNameToOak(name);
+
             return new PropertyDefinitionDelegate(name, autocreate, isMandatory, onParent,
isProtected, requiredType, isMultiple,
                     defaultCoreValues);
         }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/resources/org/apache/jackrabbit/oak/jcr/nodetype/builtin_nodetypes.cnd
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/resources/org/apache/jackrabbit/oak/jcr/nodetype/builtin_nodetypes.cnd?rev=1355036&r1=1355035&r2=1355036&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/resources/org/apache/jackrabbit/oak/jcr/nodetype/builtin_nodetypes.cnd
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/resources/org/apache/jackrabbit/oak/jcr/nodetype/builtin_nodetypes.cnd
Thu Jun 28 15:04:57 2012
@@ -18,7 +18,7 @@
 <rep='internal'>
 <jcr='http://www.jcp.org/jcr/1.0'>
 <nt='http://www.jcp.org/jcr/nt/1.0'>
-<mix='http://www.jcp.org/jcr/mix/1.0'>
+<mixin='http://www.jcp.org/jcr/mix/1.0'>
 
 //------------------------------------------------------------------------------
 // B A S E  T Y P E
@@ -43,7 +43,7 @@
  * This abstract node type serves as the supertype of nt:file and nt:folder.
  * @since 1.0
  */
-[nt:hierarchyNode] > mix:created
+[nt:hierarchyNode] > mixin:created
   abstract
 
 /**
@@ -92,7 +92,7 @@
  *
  * @since 1.0
  */
-[nt:resource] > mix:mimeType, mix:lastModified, mix:referenceable
+[nt:resource] > mixin:mimeType, mixin:lastModified, mixin:referenceable
   primaryitem jcr:data
   - jcr:data (BINARY) mandatory
 
@@ -103,7 +103,7 @@
  * Note that the protected attributes suggested by JSR283 are omitted in this variant.
  * @since 2.0
  */
-[mix:title]
+[mixin:title]
   mixin
   - jcr:title (STRING)
   - jcr:description (STRING)
@@ -120,7 +120,7 @@
  *
  * @since 2.0
  */
-[mix:created]
+[mixin:created]
   mixin
   - jcr:created (DATE) autocreated protected
   - jcr:createdBy (STRING) autocreated protected
@@ -142,7 +142,7 @@
  * Note that the protected attributes suggested by JSR283 are omitted in this variant.
  * @since 2.0
  */
-[mix:lastModified]
+[mixin:lastModified]
   mixin
   - jcr:lastModified (DATE) autocreated
   - jcr:lastModifiedBy (STRING) autocreated
@@ -157,7 +157,7 @@
  * Note that the protected attributes suggested by JSR283 are omitted in this variant.
  * @since 2.0
  */
-[mix:language]
+[mixin:language]
   mixin
   - jcr:language (STRING)
 
@@ -174,7 +174,7 @@
  * Note that the protected attributes suggested by JSR283 are omitted in this variant.
  * @since 2.0
  */
-[mix:mimeType]
+[mixin:mimeType]
   mixin
   - jcr:mimeType (STRING)
   - jcr:encoding (STRING)
@@ -221,14 +221,14 @@
   - jcr:id (WEAKREFERENCE)
 
 /**
- * The mix:etag mixin type defines a standardized identity validator for BINARY 
+ * The mixin:etag mixin type defines a standardized identity validator for BINARY 
  * properties similar to the entity tags used in HTTP/1.1
  *
  * A jcr:etag property is an opaque string whose syntax is identical to that
  * defined for entity tags in HTTP/1.1. Semantically, the jcr:etag is comparable
  * to the HTTP/1.1 strong entity tag.
  *
- * On creation of a mix:etag node N, or assignment of mix:etag to N, the
+ * On creation of a mixin:etag node N, or assignment of mixin:etag to N, the
  * repository must create a jcr:etag property with an implementation determined
  * value.
  *
@@ -240,7 +240,7 @@
  *
  * @since 2.0
  */
-[mix:etag]
+[mixin:etag]
   mixin
   - jcr:etag (STRING) protected autocreated
 
@@ -281,7 +281,7 @@
  *
  * @since 1.0
  */
-[mix:referenceable]
+[mixin:referenceable]
   mixin
   - jcr:uuid (STRING) mandatory autocreated protected INITIALIZE 
 
@@ -292,7 +292,7 @@
 /**
  * @since 1.0
  */
-[mix:lockable]
+[mixin:lockable]
   mixin
   - jcr:lockOwner (STRING) protected IGNORE
   - jcr:lockIsDeep (BOOLEAN) protected IGNORE
@@ -304,7 +304,7 @@
 /**
  * @since 2.0
  */
-[mix:shareable] > mix:referenceable
+[mixin:shareable] > mixin:referenceable
   mixin
 
 //------------------------------------------------------------------------------
@@ -314,14 +314,14 @@
 /**
  * @since 2.0
  */
-[mix:simpleVersionable]
+[mixin:simpleVersionable]
   mixin
   - jcr:isCheckedOut (BOOLEAN) = 'true' mandatory autocreated protected IGNORE
 
 /**
  * @since 1.0
  */
-[mix:versionable] > mix:simpleVersionable, mix:referenceable
+[mixin:versionable] > mixin:simpleVersionable, mixin:referenceable
   mixin
   - jcr:versionHistory (REFERENCE) mandatory protected IGNORE < 'nt:versionHistory'
   - jcr:baseVersion (REFERENCE) mandatory protected IGNORE < 'nt:version'
@@ -335,7 +335,7 @@
 /**
  * @since 1.0
  */
-[nt:versionHistory] > mix:referenceable
+[nt:versionHistory] > mixin:referenceable
   - jcr:versionableUuid (STRING) mandatory autocreated protected ABORT
     /** @since 2.0 */
   - jcr:copiedFrom (WEAKREFERENCE) protected ABORT < 'nt:version'
@@ -352,7 +352,7 @@
 /**
  * @since 1.0
  */
-[nt:version] > mix:referenceable
+[nt:version] > mixin:referenceable
   - jcr:created (DATE) mandatory autocreated protected ABORT
   - jcr:predecessors (REFERENCE) protected multiple ABORT < 'nt:version'
   - jcr:successors (REFERENCE) protected multiple ABORT < 'nt:version'
@@ -363,7 +363,7 @@
 /**
  * @since 1.0
  */
-[nt:frozenNode] > mix:referenceable
+[nt:frozenNode] > mixin:referenceable
   orderable
   - jcr:frozenPrimaryType (NAME) mandatory autocreated protected ABORT
   - jcr:frozenMixinTypes (NAME) protected multiple ABORT
@@ -381,13 +381,13 @@
 /**
  * @since 2.0
  */
-[nt:activity] > mix:referenceable
+[nt:activity] > mixin:referenceable
   - jcr:activityTitle (STRING) mandatory autocreated protected
 
 /**
  * @since 2.0
  */
-[nt:configuration] > mix:versionable
+[nt:configuration] > mixin:versionable
   - jcr:root (REFERENCE) mandatory autocreated protected
 
 //------------------------------------------------------------------------------
@@ -469,7 +469,7 @@
 //------------------------------------------------------------------------------
 
 /**
- * Only nodes with mixin node type mix:lifecycle may participate in a lifecycle.
+ * Only nodes with mixin node type mixin:lifecycle may participate in a lifecycle.
  *
  * @peop jcr:lifecyclePolicy
  *              This property is a reference to another node that contains
@@ -481,7 +481,7 @@
  *
  * @since 2.0
  */
-[mix:lifecycle]
+[mixin:lifecycle]
   mixin
   - jcr:lifecyclePolicy (REFERENCE) protected INITIALIZE
   - jcr:currentLifecycleState (STRING) protected INITIALIZE
@@ -591,7 +591,7 @@
 // User Management 
 // -----------------------------------------------------------------------------
 
-[rep:Authorizable] > mix:referenceable, nt:hierarchyNode
+[rep:Authorizable] > mixin:referenceable, nt:hierarchyNode
   abstract
   + * (nt:base) = nt:unstructured VERSION
   - rep:principalName (STRING) protected mandatory



Mime
View raw message