jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1158938 - in /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel: RepositoryServiceImpl.java util/DefaultValueProvider.java util/NodeTypes.java util/Values.java
Date Wed, 17 Aug 2011 22:16:58 GMT
Author: mduerig
Date: Wed Aug 17 22:16:57 2011
New Revision: 1158938

URL: http://svn.apache.org/viewvc?rev=1158938&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
- factor out default value handling (WIP)

Added:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/NodeTypes.java
Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/DefaultValueProvider.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1158938&r1=1158937&r2=1158938&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Wed Aug 17 22:16:57 2011
@@ -46,13 +46,11 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.QNodeDefinitionImpl;
 import org.apache.jackrabbit.spi.commons.SessionInfoImpl;
 import org.apache.jackrabbit.spi.commons.batch.ConsolidatingChangeLog;
-import org.apache.jackrabbit.spi.commons.iterator.Iterators;
 import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.apache.jackrabbit.spi2microkernel.util.DefaultValueProvider;
 import org.apache.jackrabbit.spi2microkernel.util.Function1;
 import org.apache.jackrabbit.spi2microkernel.util.JsonHandlerBase;
 import org.apache.jackrabbit.spi2microkernel.util.Paths;
-import org.apache.jackrabbit.spi2microkernel.util.Predicate1;
 import org.apache.jackrabbit.spi2microkernel.util.Values;
 import org.json.simple.parser.JSONParser;
 import org.json.simple.parser.ParseException;
@@ -71,7 +69,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -114,20 +111,12 @@ import static javax.jcr.Repository.REP_V
 import static javax.jcr.Repository.SPEC_NAME_DESC;
 import static javax.jcr.Repository.SPEC_VERSION_DESC;
 import static javax.jcr.Repository.WRITE_SUPPORTED;
-import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_CREATED;
-import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_CREATEDBY;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_MIXINTYPES;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_PRIMARYTYPE;
-import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_UUID;
-import static org.apache.jackrabbit.spi.commons.name.NameConstants.MIX_CREATED;
-import static org.apache.jackrabbit.spi.commons.name.NameConstants.MIX_REFERENCEABLE;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.REP_ROOT;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.ROOT;
-import static org.apache.jackrabbit.spi2microkernel.util.Arrays.contains;
 import static org.apache.jackrabbit.spi2microkernel.util.ItemInfos.buildItemInfos;
 import static org.apache.jackrabbit.spi2microkernel.util.Maps.getOrElse;
-import static org.apache.jackrabbit.spi2microkernel.util.Predicates.containsElement;
-import static org.apache.jackrabbit.spi2microkernel.util.Predicates.exists;
 
 public class RepositoryServiceImpl extends AbstractRepositoryService {
     private static final long BINARY_VALUE_INLINE_THRESHOLD = 0x1000;
@@ -630,9 +619,9 @@ public class RepositoryServiceImpl exten
 
                 jsop.append('+').append(target(parentId, nodeName)).append(" : ").append(sb.toString()).append('\n');
 
-                DefaultValueProvider defaultValueProvider = Values.getDefaultValueProvider(nodetypeName,
nodeTypeDefs);
-                for (Name propertyName : defaultValueProvider.getDefaultProperties()) {
-                    QValue value = defaultValueProvider.getValue(propertyName);
+                DefaultValueProvider defaultProvider = Values.getDefaultProvider(nodetypeName,
nodeTypeDefs);
+                for (Name propertyName : defaultProvider.getDefaultProperties()) {
+                    QValue value = defaultProvider.getValue(propertyName, sessionInfo, uuid);
                     setProperty(target(parentId, nodeName, propertyName), Values.valueToString(value,
saveToDataStore));
                 }
             }
@@ -689,9 +678,9 @@ public class RepositoryServiceImpl exten
             }
 
             for (Name mixin: mixinNodeTypeNames) {
-                DefaultValueProvider defaultValueProvider = Values.getDefaultValueProvider(mixin,
nodeTypeDefs);
-                for (Name propertyName : defaultValueProvider.getDefaultProperties()) {
-                    QValue value = defaultValueProvider.getValue(propertyName);
+                DefaultValueProvider defaultProvider = Values.getDefaultProvider(mixin, nodeTypeDefs);
+                for (Name propertyName : defaultProvider.getDefaultProperties()) {
+                    QValue value = defaultProvider.getValue(propertyName, sessionInfo, getPath(nodeId).toString());
                     setProperty(nodeId, propertyName, Values.valueToString(value, saveToDataStore));
                 }
             }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/DefaultValueProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/DefaultValueProvider.java?rev=1158938&r1=1158937&r2=1158938&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/DefaultValueProvider.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/DefaultValueProvider.java
Wed Aug 17 22:16:57 2011
@@ -2,6 +2,7 @@ package org.apache.jackrabbit.spi2microk
 
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.SessionInfo;
 
@@ -9,5 +10,5 @@ import javax.jcr.RepositoryException;
 
 public interface DefaultValueProvider {
     Name[] getDefaultProperties();
-    QValue getValue(Name propertyName) throws RepositoryException;
+    QValue getValue(Name propertyName, SessionInfo sessionInfo, String uuid) throws RepositoryException;
 }

Added: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/NodeTypes.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/NodeTypes.java?rev=1158938&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/NodeTypes.java
(added)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/NodeTypes.java
Wed Aug 17 22:16:57 2011
@@ -0,0 +1,50 @@
+package org.apache.jackrabbit.spi2microkernel.util;
+
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.commons.iterator.Iterators;
+import org.apache.jackrabbit.spi.commons.nodetype.NodeTypeStorage;
+
+import javax.jcr.RepositoryException;
+import java.util.Iterator;
+
+import static org.apache.jackrabbit.spi2microkernel.util.Predicates.containsElement;
+import static org.apache.jackrabbit.spi2microkernel.util.Predicates.exists;
+
+public class NodeTypes {
+    private NodeTypes() {}
+
+    public static boolean isSubType(Name ntName1, final Name ntName2, final NodeTypeStorage
nodeTypes)
+            throws RepositoryException {
+
+        try {
+            return isDirectSubType(ntName1, ntName2, nodeTypes) || exists(new Predicate1<Name>()
{
+                public Boolean apply(Name ntName) throws Exception {
+                    return isSubType(ntName, ntName2, nodeTypes);
+                }
+            }, superTypes(ntName1, nodeTypes));
+        }
+        catch (RepositoryException e) {
+            throw e;
+        }
+        catch (Exception e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+    public static boolean isDirectSubType(Name ntName1, Name ntName2, NodeTypeStorage nodeTypes)
throws Exception {
+        return ntName1.equals(ntName2) || containsElement(ntName2, superTypes(ntName1, nodeTypes));
+    }
+
+    public static Iterator<Name> superTypes(Name ntName, NodeTypeStorage nodeTypes)
throws RepositoryException {
+        Iterator<QNodeTypeDefinition> ntDefinitions = nodeTypes.getDefinitions(new
Name[]{ntName});
+        if (ntDefinitions.hasNext()) {
+            Name[] superTypes = ntDefinitions.next().getSupertypes();
+            return Iterators.arrayIterator(superTypes, 0, superTypes.length);
+        }
+        else {
+            return Iterators.empty();
+        }
+    }
+
+}

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java?rev=1158938&r1=1158937&r2=1158938&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
Wed Aug 17 22:16:57 2011
@@ -22,10 +22,9 @@ package org.apache.jackrabbit.spi2microk
 import org.apache.jackrabbit.mk.json.JsonBuilder;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
-import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
-import org.apache.jackrabbit.spi.commons.iterator.Iterators;
+import org.apache.jackrabbit.spi.SessionInfo;
 import org.apache.jackrabbit.spi.commons.nodetype.NodeTypeStorage;
 import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
 import org.apache.jackrabbit.util.Base64;
@@ -42,7 +41,6 @@ import java.util.Calendar;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
@@ -65,8 +63,7 @@ import static org.apache.jackrabbit.spi.
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_UUID;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.MIX_CREATED;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.MIX_REFERENCEABLE;
-import static org.apache.jackrabbit.spi2microkernel.util.Predicates.containsElement;
-import static org.apache.jackrabbit.spi2microkernel.util.Predicates.exists;
+import static org.apache.jackrabbit.spi2microkernel.util.NodeTypes.*;
 
 public final class Values {
     static final Logger log = LoggerFactory.getLogger(Values.class);
@@ -390,8 +387,7 @@ public final class Values {
         return sb.toString();
     }
 
-    // fixme improve, factor out?
-    public static DefaultValueProvider getDefaultValueProvider(Name nodetypeName, NodeTypeStorage
nodeTypes)
+    public static DefaultValueProvider getDefaultProvider(Name nodetypeName, NodeTypeStorage
nodeTypes)
             throws RepositoryException {
         
         final Set<Name> propertyNames = new HashSet<Name>();
@@ -410,15 +406,17 @@ public final class Values {
             }
 
             @Override
-            public QValue getValue(Name propertyName) throws RepositoryException {
+            public QValue getValue(Name propertyName, SessionInfo sessionInfo, String uuid)
+                    throws RepositoryException {
+                
                 if (JCR_UUID.equals(propertyName)) {
-                    return FACTORY.create("todo uuid", PropertyType.STRING);  // fixme set
uuid
+                    return FACTORY.create(uuid, PropertyType.STRING);
                 }
                 else if (JCR_CREATED.equals(propertyName)) {
                     return FACTORY.create(GregorianCalendar.getInstance());
                 }
                 else if (JCR_CREATEDBY.equals(propertyName)) {
-                    return FACTORY.create("todo userId", PropertyType.STRING);  // fixme
set user id
+                    return FACTORY.create(sessionInfo.getUserID(), PropertyType.STRING);
 
                 }
                 else {
                     IllegalStateException e = new IllegalStateException("No default valur
for property " + propertyName);
@@ -429,39 +427,6 @@ public final class Values {
         };
     }
 
-    private static boolean isSubType(Name name1, final Name name2, final NodeTypeStorage
nodeTypes)
-            throws RepositoryException {
-        
-        try {
-            return isDirectSubType(name1, name2, nodeTypes) || exists(new Predicate1<Name>()
{
-                public Boolean apply(Name name) throws Exception {
-                    return isSubType(name, name2, nodeTypes);
-                }
-            }, superTypes(name1, nodeTypes));
-        }
-        catch (RepositoryException e) {
-            throw e;
-        }
-        catch (Exception e) {
-            throw new RepositoryException(e);
-        }
-    }
-
-    private static boolean isDirectSubType(Name name1, Name name2, NodeTypeStorage nodeTypes)
throws Exception {
-        return name1.equals(name2) || containsElement(name2, superTypes(name1, nodeTypes));
-    }
-
-    private static Iterator<Name> superTypes(Name name, NodeTypeStorage nodeTypes)
throws RepositoryException {
-        Iterator<QNodeTypeDefinition> ntDefinitions = nodeTypes.getDefinitions(new
Name[]{name});
-        if (ntDefinitions.hasNext()) {
-            Name[] superTypes = ntDefinitions.next().getSupertypes();
-            return Iterators.arrayIterator(superTypes, 0, superTypes.length);
-        }
-        else {
-            return Iterators.empty();
-        }
-    }
-
     //------------------------------------------< private >---
 
     private static Character toHex(int i) {



Mime
View raw message