jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1170703 - in /jackrabbit/sandbox/jackrabbit-mk: jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbi...
Date Wed, 14 Sep 2011 16:17:01 GMT
Author: mduerig
Date: Wed Sep 14 16:17:01 2011
New Revision: 1170703

URL: http://svn.apache.org/viewvc?rev=1170703&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP) 
refactor: eliminate StateUtility

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntryImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/StateUtility.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Arrays.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Iterators.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java?rev=1170703&r1=1170702&r2=1170703&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
Wed Sep 14 16:17:01 2011
@@ -30,9 +30,9 @@ import org.apache.jackrabbit.jcr2spi.ope
 import org.apache.jackrabbit.jcr2spi.state.ItemState;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateValidator;
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
+import org.apache.jackrabbit.jcr2spi.state.PropertyState;
 import org.apache.jackrabbit.jcr2spi.state.Status;
 import org.apache.jackrabbit.jcr2spi.util.LogUtil;
-import org.apache.jackrabbit.jcr2spi.util.StateUtility;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.Path;
@@ -42,6 +42,8 @@ import org.apache.jackrabbit.spi.QProper
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.util.Arrays;
+import org.apache.jackrabbit.spi.commons.util.Function1;
 import org.apache.jackrabbit.spi.commons.value.ValueFormat;
 import org.apache.jackrabbit.util.ChildrenCollectorFilter;
 import org.apache.jackrabbit.value.ValueHelper;
@@ -77,7 +79,6 @@ import javax.jcr.version.VersionHistory;
 import java.io.InputStream;
 import java.math.BigDecimal;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Iterator;
 import java.util.List;
@@ -716,7 +717,7 @@ public class NodeImpl extends ItemImpl i
                 } else {
                     // prop entry exists (and ev. has been transiently mod.)
                     // -> retrieve mixin types from prop
-                    mixinValue = StateUtility.getMixinNames(pe.getPropertyState());
+                    mixinValue = getMixinNames(pe.getPropertyState());
                 }
             } catch (RepositoryException e) {
                 // should never occur
@@ -725,10 +726,24 @@ public class NodeImpl extends ItemImpl i
             }
         }
         List<Name> l = new ArrayList<Name>();
-        l.addAll(Arrays.asList(mixinValue));
+        l.addAll(java.util.Arrays.asList(mixinValue));
         return l;
     }
 
+    private static Name[] getMixinNames(PropertyState propertyState) {
+        if (propertyState.getStatus() == Status.REMOVED) {
+            return Name.EMPTY_ARRAY;
+        } else {
+            QValue[] qValues = propertyState.getValues();
+            return Arrays.map(qValues, new Name[qValues.length], new Function1<QValue,
Name>() {
+                @Override
+                public Name apply(QValue qValue) throws Exception {
+                    return qValue.getName();
+                }
+            });
+        }
+    }
+
     /**
      * Build the effective node type of remaining mixins & primary type
      *

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntryImpl.java?rev=1170703&r1=1170702&r2=1170703&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntryImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntryImpl.java
Wed Sep 14 16:17:01 2011
@@ -29,7 +29,6 @@ import org.apache.jackrabbit.jcr2spi.sta
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.state.PropertyState;
 import org.apache.jackrabbit.jcr2spi.state.Status;
-import org.apache.jackrabbit.jcr2spi.util.StateUtility;
 import org.apache.jackrabbit.spi.ChildInfo;
 import org.apache.jackrabbit.spi.Event;
 import org.apache.jackrabbit.spi.IdFactory;
@@ -44,6 +43,8 @@ import org.apache.jackrabbit.spi.QProper
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.name.PathBuilder;
+import org.apache.jackrabbit.spi.commons.util.Arrays;
+import org.apache.jackrabbit.spi.commons.util.Function1;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -1188,7 +1189,7 @@ public class NodeEntryImpl extends Hiera
                 NodeState state = (NodeState) internalGetItemState();
                 if (state != null) {
                     PropertyState ps = child.getPropertyState();
-                    state.setMixinTypeNames(StateUtility.getMixinNames(ps));
+                    state.setMixinTypeNames(getMixinNames(ps));
                 } // node state not yet loaded -> ignore change
             }
         } catch (ItemNotFoundException e) {
@@ -1453,7 +1454,7 @@ public class NodeEntryImpl extends Hiera
             PropertyState pState = pe.getPropertyState();
             switch (operation.getStatus()) {
                 case PERSISTED:
-                    Name[] mixins = StateUtility.getMixinNames(pState);
+                    Name[] mixins = getMixinNames(pState);
                     getNodeState().setMixinTypeNames(mixins);
                     if (pState.getStatus() == Status.NEW || pState.getStatus() == Status.EXISTING_MODIFIED)
{
                         pState.setStatus(Status.EXISTING);
@@ -1569,6 +1570,20 @@ public class NodeEntryImpl extends Hiera
         parent.childNodeEntries.add(this, revertInfo.oldIndex, revertInfo.oldSuccessor);
     }
 
+    private static Name[] getMixinNames(PropertyState propertyState) {
+        if (propertyState.getStatus() == Status.REMOVED) {
+            return Name.EMPTY_ARRAY;
+        } else {
+            QValue[] qValues = propertyState.getValues();
+            return Arrays.map(qValues, new Name[qValues.length], new Function1<QValue,
Name>() {
+                @Override
+                public Name apply(QValue qValue) throws Exception {
+                    return qValue.getName();
+                }
+            });
+        }
+    }
+
     //--------------------------------------------------------< inner class >---
     
     /**

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Arrays.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Arrays.java?rev=1170703&r1=1170702&r2=1170703&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Arrays.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Arrays.java
Wed Sep 14 16:17:01 2011
@@ -19,9 +19,12 @@
 
 package org.apache.jackrabbit.spi.commons.util;
 
+import java.lang.reflect.Array;
 import java.util.HashSet;
 import java.util.Set;
 
+import static org.apache.jackrabbit.spi.commons.util.Unchecked.cast;
+
 public final class Arrays {
     private Arrays() {}
 
@@ -39,4 +42,33 @@ public final class Arrays {
         set.addAll(java.util.Arrays.asList(elements));
         return set;
     }
+
+    /**
+     * Map function {@code f} over array {@code from}. If {@code to.length < from.length}
+     * a new array is allocated. 
+     * 
+     * @param from  array to map from
+     * @param to  array to map to
+     * @param f  function to map
+     * @param <T>  from type
+     * @param <R>  to type
+     * @return  array {@code to}
+     */
+    public static <T, R> R[] map(T[] from, R[] to, Function1<T, R> f) {
+        if (to.length < from.length) {
+            to = cast(Array.newInstance(to.getClass().getComponentType(), from.length));
+        }
+
+        for (int k = 0; k < from.length; k++) {
+            try {
+                to[k] = f.apply(from[k]);
+            }
+            catch (Exception e) {
+                throw new IllegalArgumentException("Function1 must not throw unchecked exceptions",
e);
+            }
+        }
+
+        return to;
+    }
+
 }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Iterators.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Iterators.java?rev=1170703&r1=1170702&r2=1170703&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Iterators.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Iterators.java
Wed Sep 14 16:17:01 2011
@@ -130,7 +130,7 @@ public final class Iterators {
                     return predicate.apply(Unchecked.<T>cast(object));
                 }
                 catch (Exception e) {
-                    throw new IllegalArgumentException("Predicate may not throw exceptions",
e);
+                    throw new IllegalArgumentException("Predicate must not throw unchecked
exceptions", e);
                 }
             }
         }));
@@ -157,7 +157,7 @@ public final class Iterators {
                     return transformer.apply(Unchecked.<S>cast(input));
                 }
                 catch (Exception e) {
-                    throw new IllegalArgumentException("Transformer may not throw exceptions",
e);
+                    throw new IllegalArgumentException("Transformer must not throw unchecked
exceptions", e);
                 }
             }
         }));



Mime
View raw message