jackrabbit-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1158851&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/DefaultValueProvider.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/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=1158851&r1=1158850&r2=1158851&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 18:02:58 2011
@@ -48,6 +48,7 @@ import org.apache.jackrabbit.spi.commons
 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;
@@ -85,34 +86,34 @@ import static javax.jcr.Repository.IDENT
 import static javax.jcr.Repository.IDENTIFIER_STABILITY_METHOD_DURATION;
 import static javax.jcr.Repository.LEVEL_1_SUPPORTED;
 import static javax.jcr.Repository.LEVEL_2_SUPPORTED;
-import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED;
-import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_PROPERTY_TYPES;
-import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_PRIMARY_ITEM_NAME_SUPPORTED;
-import static javax.jcr.Repository.OPTION_NODE_TYPE_MANAGEMENT_SUPPORTED;
-import static javax.jcr.Repository.OPTION_OBSERVATION_SUPPORTED;
-import static javax.jcr.Repository.OPTION_UPDATE_MIXIN_NODE_TYPES_SUPPORTED;
-import static javax.jcr.Repository.OPTION_WORKSPACE_MANAGEMENT_SUPPORTED;
-import static javax.jcr.Repository.QUERY_XPATH_DOC_ORDER;
-import static javax.jcr.Repository.SPEC_NAME_DESC;
-import static javax.jcr.Repository.WRITE_SUPPORTED;
-import static javax.jcr.Repository.SPEC_VERSION_DESC;
 import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_AUTOCREATED_DEFINITIONS_SUPPORTED;
+import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_INHERITANCE;
+import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_MULTIPLE_BINARY_PROPERTIES_SUPPORTED;
 import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_MULTIVALUED_PROPERTIES_SUPPORTED;
 import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_ORDERABLE_CHILD_NODES_SUPPORTED;
-import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_RESIDUAL_DEFINITIONS_SUPPORTED;
 import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_OVERRIDES_SUPPORTED;
-import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_INHERITANCE;
-import static javax.jcr.Repository.REP_NAME_DESC;
-import static javax.jcr.Repository.OPTION_BASELINES_SUPPORTED;
-import static javax.jcr.Repository.OPTION_ACTIVITIES_SUPPORTED;
-import static javax.jcr.Repository.OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED;
-import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_MULTIPLE_BINARY_PROPERTIES_SUPPORTED;
+import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_PRIMARY_ITEM_NAME_SUPPORTED;
+import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_PROPERTY_TYPES;
+import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_RESIDUAL_DEFINITIONS_SUPPORTED;
+import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED;
 import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_UPDATE_IN_USE_SUPORTED;
 import static javax.jcr.Repository.NODE_TYPE_MANAGEMENT_VALUE_CONSTRAINTS_SUPPORTED;
-import static javax.jcr.Repository.QUERY_XPATH_POS_INDEX;
+import static javax.jcr.Repository.OPTION_ACTIVITIES_SUPPORTED;
+import static javax.jcr.Repository.OPTION_BASELINES_SUPPORTED;
+import static javax.jcr.Repository.OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED;
+import static javax.jcr.Repository.OPTION_NODE_TYPE_MANAGEMENT_SUPPORTED;
+import static javax.jcr.Repository.OPTION_OBSERVATION_SUPPORTED;
 import static javax.jcr.Repository.OPTION_QUERY_SQL_SUPPORTED;
-import static javax.jcr.Repository.REP_VENDOR_URL_DESC;
+import static javax.jcr.Repository.OPTION_UPDATE_MIXIN_NODE_TYPES_SUPPORTED;
+import static javax.jcr.Repository.OPTION_WORKSPACE_MANAGEMENT_SUPPORTED;
+import static javax.jcr.Repository.QUERY_XPATH_DOC_ORDER;
+import static javax.jcr.Repository.QUERY_XPATH_POS_INDEX;
+import static javax.jcr.Repository.REP_NAME_DESC;
 import static javax.jcr.Repository.REP_VENDOR_DESC;
+import static javax.jcr.Repository.REP_VENDOR_URL_DESC;
+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;
@@ -629,10 +630,10 @@ public class RepositoryServiceImpl exten
 
                 jsop.append('+').append(target(parentId, nodeName)).append(" : ").append(sb.toString()).append('\n');
 
-                // todo: factor out setting of default values
-                if (isSubType(nodetypeName, MIX_CREATED)) {
-                    setProperty(target(parentId, nodeName, JCR_CREATED), Values.dateToString(GregorianCalendar.getInstance()));
-                    setProperty(target(parentId, nodeName, JCR_CREATEDBY), '"' + sessionInfo.getUserID()
+ '"');
+                DefaultValueProvider defaultValueProvider = Values.getDefaultValueProvider(nodetypeName,
nodeTypeDefs);
+                for (Name propertyName : defaultValueProvider.getDefaultProperties()) {
+                    QValue value = defaultValueProvider.getValue(propertyName);
+                    setProperty(target(parentId, nodeName, propertyName), Values.valueToString(value,
saveToDataStore));
                 }
             }
             catch (IOException e) {
@@ -687,14 +688,12 @@ public class RepositoryServiceImpl exten
                 setProperty(nodeId, JCR_MIXINTYPES, Values.namesToString(mixinNodeTypeNames));
             }
 
-            // todo: factor out setting of default values
-            if (contains(mixinNodeTypeNames, MIX_REFERENCEABLE)) {
-                // todo uuid is not stable across move operations
-                setProperty(nodeId, JCR_UUID, Values.pathToString(getPath(nodeId)));
-            }
-            else if (contains(mixinNodeTypeNames, MIX_CREATED)) {
-                setProperty(nodeId, JCR_CREATED, Values.dateToString(GregorianCalendar.getInstance()));
-                setProperty(nodeId, JCR_CREATEDBY, '"' + sessionInfo.getUserID() + '"');
+            for (Name mixin: mixinNodeTypeNames) {
+                DefaultValueProvider defaultValueProvider = Values.getDefaultValueProvider(mixin,
nodeTypeDefs);
+                for (Name propertyName : defaultValueProvider.getDefaultProperties()) {
+                    QValue value = defaultValueProvider.getValue(propertyName);
+                    setProperty(nodeId, propertyName, Values.valueToString(value, saveToDataStore));
+                }
             }
         }
 
@@ -714,38 +713,7 @@ public class RepositoryServiceImpl exten
                 }
             });
         }
-
-        private boolean isSubType(Name name1, final Name name2) throws RepositoryException
{
-            try {
-                return isDirectSubType(name1, name2) || exists(new Predicate1<Name>()
{
-                    public Boolean apply(Name name) throws Exception {
-                        return isSubType(name, name2);
-                    }
-                }, superTypes(name1));
-            }
-            catch (RepositoryException e) {
-                throw e;
-            }
-            catch (Exception e) {
-                throw new RepositoryException(e); 
-            }
-        }
-
-        private boolean isDirectSubType(Name name1, Name name2) throws Exception {
-            return containsElement(name2, superTypes(name1));
-        }
-
-        private Iterator<Name> superTypes(Name name) throws RepositoryException {
-            Iterator<QNodeTypeDefinition> ntDefinitions = nodeTypeDefs.getDefinitions(new
Name[]{name});
-            if (ntDefinitions.hasNext()) {
-                Name[] superTypes = ntDefinitions.next().getSupertypes();
-                return Iterators.arrayIterator(superTypes, 0, superTypes.length);
-            }
-            else {
-                return Iterators.empty();
-            }
-        }
-
+        
         private String target(NodeId nodeId) throws RepositoryException {
             return '\"' + JsonBuilder.escape(
                 PathUtils.relativize("/", Paths.pathToString(sessionInfo.getWorkspaceName(),
getPath(nodeId)))) + '\"';

Added: 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=1158851&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/DefaultValueProvider.java
(added)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/DefaultValueProvider.java
Wed Aug 17 18:02:58 2011
@@ -0,0 +1,13 @@
+package org.apache.jackrabbit.spi2microkernel.util;
+
+import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.SessionInfo;
+
+import javax.jcr.RepositoryException;
+
+public interface DefaultValueProvider {
+    Name[] getDefaultProperties();
+    QValue getValue(Name propertyName) throws RepositoryException;
+}

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=1158851&r1=1158850&r2=1158851&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 18:02:58 2011
@@ -22,23 +22,55 @@ 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.commons.nodetype.NodeTypeStorage;
 import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
 import org.apache.jackrabbit.util.Base64;
 import org.apache.jackrabbit.util.ISO8601;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.StringWriter;
 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;
 
-import static javax.jcr.PropertyType.*;
+import static javax.jcr.PropertyType.BINARY;
+import static javax.jcr.PropertyType.BOOLEAN;
+import static javax.jcr.PropertyType.DATE;
+import static javax.jcr.PropertyType.DECIMAL;
+import static javax.jcr.PropertyType.DOUBLE;
+import static javax.jcr.PropertyType.LONG;
+import static javax.jcr.PropertyType.NAME;
+import static javax.jcr.PropertyType.PATH;
+import static javax.jcr.PropertyType.REFERENCE;
+import static javax.jcr.PropertyType.STRING;
+import static javax.jcr.PropertyType.UNDEFINED;
+import static javax.jcr.PropertyType.URI;
+import static javax.jcr.PropertyType.WEAKREFERENCE;
+import static javax.jcr.PropertyType.nameFromValue;
+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_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;
 
 public final class Values {
+    static final Logger log = LoggerFactory.getLogger(Values.class);
+
     private static final QValueFactory FACTORY = QValueFactoryImpl.getInstance();
 
     private static final char BLOB_REF_TYPE = 13;
@@ -358,6 +390,78 @@ public final class Values {
         return sb.toString();
     }
 
+    // fixme improve, factor out?
+    public static DefaultValueProvider getDefaultValueProvider(Name nodetypeName, NodeTypeStorage
nodeTypes)
+            throws RepositoryException {
+        
+        final Set<Name> propertyNames = new HashSet<Name>();
+
+        if (isSubType(nodetypeName, MIX_CREATED, nodeTypes)) {
+            propertyNames.add(JCR_CREATED);
+            propertyNames.add(JCR_CREATEDBY);
+        }
+        if (isSubType(nodetypeName, MIX_REFERENCEABLE, nodeTypes)) {
+            propertyNames.add(JCR_UUID);
+        }
+
+        return new DefaultValueProvider() {
+            public Name[] getDefaultProperties() {
+                return propertyNames.toArray(new Name[propertyNames.size()]);
+            }
+
+            @Override
+            public QValue getValue(Name propertyName) throws RepositoryException {
+                if (JCR_UUID.equals(propertyName)) {
+                    return FACTORY.create("todo uuid", PropertyType.STRING);  // fixme set
uuid
+                }
+                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
+                }
+                else {
+                    IllegalStateException e = new IllegalStateException("No default valur
for property " + propertyName);
+                    log.debug(e.getMessage(), e);
+                    throw e;
+                }
+            }
+        };
+    }
+
+    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