jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1330808 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: SessionImpl.java WorkspaceImpl.java nodetype/NodeTypeImpl.java nodetype/NodeTypeManagerImpl.java
Date Thu, 26 Apr 2012 12:23:40 GMT
Author: jukka
Date: Thu Apr 26 12:23:40 2012
New Revision: 1330808

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

Use simple regexps to parse the default CND file

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
    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/NodeTypeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeManagerImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1330808&r1=1330807&r2=1330808&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Thu Apr 26 12:23:40 2012
@@ -72,7 +72,8 @@ public class SessionImpl extends Abstrac
     private boolean isAlive = true;
     private Root root;
 
-    SessionImpl(GlobalContext globalContext, ContentSession contentSession) {
+    SessionImpl(GlobalContext globalContext, ContentSession contentSession)
+            throws RepositoryException {
         this.globalContext = globalContext;
         this.contentSession = contentSession;
         this.valueFactory = new ValueFactoryImpl(contentSession.getCoreValueFactory(), nameMapper);

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=1330808&r1=1330807&r2=1330808&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 Apr 26 12:23:40 2012
@@ -64,7 +64,7 @@ public class WorkspaceImpl implements Ja
 
     public WorkspaceImpl(
             SessionContext<SessionImpl> sessionContext,
-            NamespaceRegistry nsRegistry) {
+            NamespaceRegistry nsRegistry) throws RepositoryException {
         this.sessionContext = sessionContext;
         this.nsRegistry = nsRegistry;
         this.nodeTypeManager =

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeImpl.java?rev=1330808&r1=1330807&r2=1330808&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeImpl.java
Thu Apr 26 12:23:40 2012
@@ -20,7 +20,10 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.nodetype.NodeDefinition;
@@ -28,12 +31,22 @@ import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.PropertyDefinition;
+import javax.jcr.version.OnParentVersionAction;
 
 import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
 import org.apache.jackrabbit.oak.namepath.NameMapper;
 
 class NodeTypeImpl implements NodeType {
 
+    private static final Pattern CND_PATTERN = Pattern.compile(
+            "( > (\\S+(, \\S+)*))?(\n  mixin)?(\n  abstract)?"
+            + "(\n  orderable)?(\n  primaryitem (\\S+))?(\n.*)*");
+
+    private static final Pattern DEF_PATTERN = Pattern.compile(
+            "  ([\\+\\-]) (\\S+) \\((.+?)\\)( = (\\S+))"
+            + "(( (mandatory|autocreated|protected|multiple))*)"
+            + "( ([A-Z])+)?.*");
+
     private final NodeTypeManager manager;
 
     private final NameMapper mapper;
@@ -50,27 +63,58 @@ class NodeTypeImpl implements NodeType {
 
     private final String primaryItemName;
 
-    private final List<PropertyDefinition> declaredPropertyDefinitions;
+    private final List<PropertyDefinition> declaredPropertyDefinitions =
+            new ArrayList<PropertyDefinition>();
 
-    private final List<NodeDefinition> declaredChildNodeDefinitions;
+    private final List<NodeDefinition> declaredChildNodeDefinitions =
+            new ArrayList<NodeDefinition>();
 
     public NodeTypeImpl(
             NodeTypeManager manager, NameMapper mapper, String name,
-            String[] declaredSuperTypeNames, boolean isAbstract,
-            boolean isMixin, boolean hasOrderableChildNodes,
-            String primaryItemName,
-            List<PropertyDefinition> declaredPropertyDefinitions,
-            List<NodeDefinition> declaredChildNodeDefinitions) {
+            String cnd) {
         this.manager = manager;
         this.mapper = mapper;
         this.name = name;
-        this.declaredSuperTypeNames = declaredSuperTypeNames;
-        this.isAbstract = isAbstract;
-        this.isMixin = isMixin;
-        this.hasOrderableChildNodes = hasOrderableChildNodes;
-        this.primaryItemName = primaryItemName;
-        this.declaredPropertyDefinitions = declaredPropertyDefinitions;
-        this.declaredChildNodeDefinitions = declaredChildNodeDefinitions;
+
+        Matcher matcher = CND_PATTERN.matcher(cnd.replace("\r\n", "\n"));
+        matcher.matches();
+
+        this.declaredSuperTypeNames = matcher.group(2).split(", ");
+        this.isAbstract = matcher.group(5) != null;
+        this.isMixin = matcher.group(4) != null;
+        this.hasOrderableChildNodes = matcher.group(7) != null;
+        this.primaryItemName = matcher.group(8);
+
+        for (String line : matcher.group(9).split("\n")) {
+            matcher = DEF_PATTERN.matcher(line);
+            matcher.matches();
+
+            String defName = matcher.group(2);
+            String defType = matcher.group(3);
+
+            boolean mandatory = matcher.group(6).contains(" mandatory");
+            boolean autoCreated = matcher.group(6).contains(" autocreated");
+            boolean isProtected = matcher.group(6).contains(" protected");
+            boolean multiple = matcher.group(6).contains(" multiple");
+
+            int onParentVersionAction = OnParentVersionAction.COPY;
+            if (matcher.group(9) != null) {
+                onParentVersionAction =
+                        OnParentVersionAction.valueFromName(matcher.group(9));
+            }
+
+            if ("+".equals(matcher.group(1))) {
+                declaredChildNodeDefinitions.add(new NodeDefinitionImpl(
+                        this, mapper, defName, autoCreated, mandatory,
+                        onParentVersionAction, isProtected, manager,
+                        defType.split(", "), matcher.group(5), false));
+            } else {
+                declaredPropertyDefinitions.add(new PropertyDefinitionImpl(
+                        this, mapper, defName, autoCreated, mandatory,
+                        onParentVersionAction, isProtected,
+                        PropertyType.valueFromName(defType), multiple));
+            }
+        }
     }
 
     @Override
@@ -109,7 +153,11 @@ class NodeTypeImpl implements NodeType {
 
     @Override
     public String getPrimaryItemName() {
-        return mapper.getJcrName(primaryItemName);
+        if (primaryItemName != null) {
+            return mapper.getJcrName(primaryItemName);
+        } else {
+            return null;
+        }
     }
 
     @Override

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=1330808&r1=1330807&r2=1330808&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 Apr 26 12:23:40 2012
@@ -16,10 +16,14 @@
  */
 package org.apache.jackrabbit.oak.jcr.nodetype;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
@@ -34,17 +38,39 @@ import javax.jcr.nodetype.NodeTypeManage
 import javax.jcr.nodetype.NodeTypeTemplate;
 import javax.jcr.nodetype.PropertyDefinitionTemplate;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
 import org.apache.jackrabbit.oak.namepath.NameMapper;
 
 public class NodeTypeManagerImpl implements NodeTypeManager {
 
+    private static final Pattern CND_PATTERN =
+            Pattern.compile("\\[(.*)?\\](.*?\n)\n");
+
     private final NameMapper mapper;
 
     private final Map<String, NodeType> types = new HashMap<String, NodeType>();
 
-    public NodeTypeManagerImpl(NameMapper mapper) {
+    public NodeTypeManagerImpl(NameMapper mapper) throws RepositoryException {
         this.mapper = mapper;
+
+        try {
+            InputStream stream = NodeTypeManagerImpl.class.getResourceAsStream(
+                    "builtin_nodetypes.cnd");
+            try {
+                String cnd = IOUtils.toString(stream, "UTF-8");
+                Matcher matcher = CND_PATTERN.matcher(cnd);
+                while (matcher.find()) {
+                    String name = matcher.group(1);
+                    types.put(name, new NodeTypeImpl(this, mapper, name, matcher.group(2)));
+                }
+            } finally {
+                stream.close();
+            }
+        } catch (IOException e) {
+            throw new RepositoryException(
+                    "Failed to load built-in node types", e);
+        }
     }
 
     @Override



Mime
View raw message