jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1390584 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: plugins/type/TypeValidator.java plugins/type/TypeValidatorProvider.java value/ValueImpl.java
Date Wed, 26 Sep 2012 16:07:25 GMT
Author: mduerig
Date: Wed Sep 26 16:07:25 2012
New Revision: 1390584

URL: http://svn.apache.org/viewvc?rev=1390584&view=rev
Log:
OAK-66: JCR Node Type Management
replace extra Value wrapper with proper ValueImpl instances

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidatorProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java?rev=1390584&r1=1390583&r2=1390584&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
Wed Sep 26 16:07:25 2012
@@ -16,24 +16,19 @@
  */
 package org.apache.jackrabbit.oak.plugins.type;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.math.BigDecimal;
-import java.util.Calendar;
 import java.util.Collections;
 import java.util.List;
 
 import javax.annotation.Nonnull;
-import javax.jcr.Binary;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.PropertyDefinition;
 
+import com.google.common.base.Function;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
@@ -43,7 +38,6 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.core.ReadOnlyTree;
 import org.apache.jackrabbit.oak.spi.commit.Validator;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.util.ISO8601;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -56,6 +50,7 @@ class TypeValidator implements Validator
 
     private final NodeTypeManager ntm;
     private final ReadOnlyTree parent;
+    private final Function<CoreValue, Value> valueFactory;
 
     private EffectiveNodeType parentType;
 
@@ -67,9 +62,10 @@ class TypeValidator implements Validator
         return parentType;
     }
 
-    public TypeValidator(NodeTypeManager ntm, ReadOnlyTree parent) {
+    public TypeValidator(NodeTypeManager ntm, ReadOnlyTree parent, Function<CoreValue,
Value> valueFactory) {
         this.ntm = ntm;
         this.parent = parent;
+        this.valueFactory = valueFactory;
     }
 
     //-------------------------------------------------------< NodeValidator >
@@ -136,7 +132,7 @@ class TypeValidator implements Validator
             ReadOnlyTree addedTree = new ReadOnlyTree(parent, name, after);
             EffectiveNodeType addedType = getEffectiveNodeType(addedTree);
             addedType.checkMandatoryItems(addedTree);
-            return new TypeValidator(ntm, new ReadOnlyTree(parent, name, after));
+            return new TypeValidator(ntm, new ReadOnlyTree(parent, name, after), valueFactory);
         }
         catch (RepositoryException e) {
             throw new CommitFailedException(
@@ -150,7 +146,7 @@ class TypeValidator implements Validator
 
     @Override
     public Validator childNodeChanged(String name, NodeState before, NodeState after) throws
CommitFailedException {
-        return new TypeValidator(ntm, new ReadOnlyTree(parent, name, after));
+        return new TypeValidator(ntm, new ReadOnlyTree(parent, name, after), valueFactory);
     }
 
     @Override
@@ -229,7 +225,7 @@ class TypeValidator implements Validator
         return new EffectiveNodeType(getPrimaryType(tree), getMixinTypes(tree));
     }
 
-    private static class EffectiveNodeType {
+    private class EffectiveNodeType {
         private final Iterable<NodeType> allTypes;
 
         public EffectiveNodeType(NodeType primaryType, List<NodeType> mixinTypes) {
@@ -322,9 +318,8 @@ class TypeValidator implements Validator
                 }
             }
         }
-    }
 
-    private static Value[] jcrValues(List<CoreValue> values) {
+        private Value[] jcrValues(List<CoreValue> values) {
             Value[] jcrValues = new  Value[values.size()];
 
             int k = 0;
@@ -335,115 +330,10 @@ class TypeValidator implements Validator
             return jcrValues;
         }
 
-        private static Value jcrValue(final CoreValue value) {
-            return new JcrValue(value);
-        }
-
-    private static class JcrValue implements Value {
-        private final CoreValue value;
-
-        public JcrValue(CoreValue value) {
-            this.value = value;
-        }
-
-        @Override
-        public String getString() {
-            return value.getString();
-        }
-
-        @Override
-        public InputStream getStream() {
-            return value.getNewStream();
-        }
-
-        @Override
-        public Binary getBinary() {
-            return new JcrBinary(value);
-        }
-
-        @Override
-        public long getLong() {
-            return value.getLong();
-        }
-
-        @Override
-        public double getDouble() {
-            return value.getDouble();
-        }
-
-        @Override
-        public BigDecimal getDecimal() {
-            return value.getDecimal();
-        }
-
-        @Override
-        public Calendar getDate() throws ValueFormatException {
-            Calendar cal = ISO8601.parse(getString());
-            if (cal == null) {
-                throw new ValueFormatException("Not a date string: " + getString());
-            }
-            return cal;
-        }
-
-        @Override
-        public boolean getBoolean() {
-            return value.getBoolean();
+        private Value jcrValue(CoreValue value) {
+            return valueFactory.apply(value);
         }
 
-        @Override
-        public int getType() {
-            return value.getType();
-        }
-
-        @Override
-        public int hashCode() {
-            return value.hashCode();
-        }
-
-        @Override
-        public boolean equals(Object other) {
-            return other instanceof JcrValue && value.equals(((JcrValue) other).value);
-        }
-
-        @Override
-        public String toString() {
-            return value.toString();
-        }
     }
 
-    private static class JcrBinary implements Binary {
-        private final CoreValue value;
-
-        public JcrBinary(CoreValue value) {
-            this.value = value;
-        }
-
-        @Override
-        public InputStream getStream() {
-            return value.getNewStream();
-        }
-
-        @Override
-        public int read(byte[] b, long position) throws IOException {
-            InputStream stream = value.getNewStream();
-            try {
-                if (position != stream.skip(position)) {
-                    throw new IOException("Can't skip to position " + position);
-                }
-                return stream.read(b);
-            }
-            finally {
-                stream.close();
-            }
-        }
-
-        @Override
-        public long getSize() {
-            return value.length();
-        }
-
-        @Override
-        public void dispose() {
-        }
-    }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidatorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidatorProvider.java?rev=1390584&r1=1390583&r2=1390584&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidatorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidatorProvider.java
Wed Sep 26 16:07:25 2012
@@ -16,14 +16,22 @@
  */
 package org.apache.jackrabbit.oak.plugins.type;
 
+import javax.jcr.Value;
+
+import com.google.common.base.Function;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.core.ReadOnlyTree;
+import org.apache.jackrabbit.oak.namepath.NameMapperImpl;
+import org.apache.jackrabbit.oak.namepath.NamePathMapper;
+import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
 import org.apache.jackrabbit.oak.spi.commit.Validator;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.value.ValueImpl;
 
 import static org.apache.jackrabbit.oak.plugins.type.NodeTypeConstants.NODE_TYPES_PATH;
 
@@ -55,7 +63,16 @@ public class TypeValidatorProvider imple
             }
         };
 
-        return new TypeValidator(ntm, new ReadOnlyTree(after));
+        Tree root = new ReadOnlyTree(after);
+        final NamePathMapper mapper = new NamePathMapperImpl(new NameMapperImpl(root));
+        Function<CoreValue, Value> valueFactory = new Function<CoreValue, Value>()
{
+            @Override
+            public Value apply(CoreValue coreValue) {
+                return new ValueImpl(coreValue, mapper);
+            }
+        };
+
+        return new TypeValidator(ntm, new ReadOnlyTree(after), valueFactory);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueImpl.java?rev=1390584&r1=1390583&r2=1390584&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueImpl.java
Wed Sep 26 16:07:25 2012
@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
 /**
  * ValueImpl...
  */
-class ValueImpl implements Value {
+public class ValueImpl implements Value {
 
     /**
      * logger instance



Mime
View raw message