jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1197212 - in /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel: ItemInfos.java RepositoryServiceImpl.java Values.java
Date Thu, 03 Nov 2011 16:43:46 GMT
Author: mduerig
Date: Thu Nov  3 16:43:45 2011
New Revision: 1197212

URL: http://svn.apache.org/viewvc?rev=1197212&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP): refactor Values.java to better match new JSON
parser

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/ItemInfos.java
    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/Values.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/ItemInfos.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/ItemInfos.java?rev=1197212&r1=1197211&r2=1197212&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/ItemInfos.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/ItemInfos.java
Thu Nov  3 16:43:45 2011
@@ -139,13 +139,12 @@ public final class ItemInfos {
         @Override
         public void atom(Token key, Token value) {
             isEmpty = false;
-            Object val = val(value);
             try {
                 if (Paths.nameToString(JCR_PRIMARYTYPE).equals(key.text())) {
-                    nodeInfoBuilder.setPrimaryType(Values.objectToValue(val).getName());
+                    nodeInfoBuilder.setPrimaryType(Values.tokenToValue(value).getName());
                 }
                 else if (Paths.nameToString(JCR_UUID).equals(key.text())) {
-                    nodeInfoBuilder.setUUID(Values.objectToValue(val).getString());
+                    nodeInfoBuilder.setUUID(Values.tokenToValue(value).getString());
                 }
                 else if (key.text().startsWith(":")) {  // ignore other internal values
                     return;
@@ -154,7 +153,7 @@ public final class ItemInfos {
                 // Single valued property
                 nodeInfoBuilder.createPropertyInfo()
                     .setName(Paths.stringToName(key.text()))
-                    .addValue(Values.objectToValue(val, binaryHandler))
+                    .addValue(Values.tokenToValue(value, binaryHandler))
                     .build();
             }
             catch (RepositoryException e) {
@@ -217,11 +216,10 @@ public final class ItemInfos {
             public void atom(Token key, Token value) {
                 try {
                     hasElements = true;
-                    Object val = val(value);
                     if (Paths.nameToString(JCR_MIXINTYPES).equals(arrayKey)) {
-                        nodeInfoBuilder.addMixin(Values.objectToValue(val).getName());
+                        nodeInfoBuilder.addMixin(Values.tokenToValue(value).getName());
                     }
-                    propertyInfoBuilder.addValue(Values.objectToValue(val, binaryHandler));
+                    propertyInfoBuilder.addValue(Values.tokenToValue(value, binaryHandler));
                 }
                 catch (RepositoryException e) {
                     throw new WrappedRepositoryException(e);
@@ -233,33 +231,5 @@ public final class ItemInfos {
             }
         }
 
-        private static Object val(Token value) {  // fixme cleanup: refactor Values.objectToValue
to match
-            Object val;
-            switch (value.type()) {
-                case TRUE:
-                    val = Boolean.TRUE;
-                    break;
-                case FALSE:
-                    val = Boolean.FALSE;
-                    break;
-                case NULL:
-                    val = null;
-                    break;
-                case STRING:
-                    val = value.text();
-                    break;
-                case NUMBER:
-                    try {
-                        val = Long.parseLong(value.text());
-                    }
-                    catch (NumberFormatException e) {
-                        val = Double.parseDouble(value.text());
-                    }
-                    break;
-                default:
-                    val = null;
-            }
-            return val;
-        }
     }
 }

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=1197212&r1=1197211&r2=1197212&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
Thu Nov  3 16:43:45 2011
@@ -144,16 +144,16 @@ public class RepositoryServiceImpl exten
         QValue[] TRUE = new QValue[]{Values.TRUE};
 
         try {
-            put(SPEC_NAME_DESC, new QValue[]{Values.objectToValue("Content Repository for
Java Technology API")});
-            put(SPEC_VERSION_DESC, new QValue[]{Values.objectToValue("2.0")});
-            put(REP_NAME_DESC, new QValue[]{Values.objectToValue("Jackrabbit 3 Microkernel
prototype")});
-            put(REP_VENDOR_URL_DESC, new QValue[]{Values.objectToValue("http://www.apache.org/")});
-            put(REP_VENDOR_DESC, new QValue[]{Values.objectToValue("Apache Software Foundation")});
+            put(SPEC_NAME_DESC, new QValue[]{Values.stringToValue("Content Repository for
Java Technology API")});
+            put(SPEC_VERSION_DESC, new QValue[]{Values.stringToValue("2.0")});
+            put(REP_NAME_DESC, new QValue[]{Values.stringToValue("Jackrabbit 3 Microkernel
prototype")});
+            put(REP_VENDOR_URL_DESC, new QValue[]{Values.stringToValue("http://www.apache.org/")});
+            put(REP_VENDOR_DESC, new QValue[]{Values.stringToValue("Apache Software Foundation")});
             put(NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED, FALSE);
             put(OPTION_WORKSPACE_MANAGEMENT_SUPPORTED, TRUE);
             put(OPTION_OBSERVATION_SUPPORTED, TRUE);
             put(WRITE_SUPPORTED, TRUE);
-            put(IDENTIFIER_STABILITY, new QValue[] {Values.objectToValue(IDENTIFIER_STABILITY_METHOD_DURATION)});
+            put(IDENTIFIER_STABILITY, new QValue[] {Values.stringToValue(IDENTIFIER_STABILITY_METHOD_DURATION)});
             put(OPTION_UPDATE_MIXIN_NODE_TYPES_SUPPORTED, TRUE);
             put(OPTION_NODE_TYPE_MANAGEMENT_SUPPORTED, TRUE);
             put(NODE_TYPE_MANAGEMENT_AUTOCREATED_DEFINITIONS_SUPPORTED, TRUE);
@@ -188,7 +188,7 @@ public class RepositoryServiceImpl exten
         return Arrays.map(strings, new QValue[strings.length], new Function1<String, QValue>(){
             @Override
             public QValue apply(String s) throws Exception {
-                return Values.objectToValue(s);
+                return Values.stringToValue(s);
             }
         });
     }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/Values.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/Values.java?rev=1197212&r1=1197211&r2=1197212&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/Values.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/Values.java
Thu Nov  3 16:43:45 2011
@@ -26,8 +26,10 @@ import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
 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.spi.commons.util.Function1;
+import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
+import org.apache.jackrabbit.spi2microkernel.json.Token;
+import org.apache.jackrabbit.spi2microkernel.json.Token.Type;
 import org.apache.jackrabbit.util.Base64;
 import org.apache.jackrabbit.util.ISO8601;
 import org.slf4j.Logger;
@@ -38,6 +40,7 @@ import javax.jcr.RepositoryException;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.StringWriter;
+import java.math.BigDecimal;
 import java.util.Calendar;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -84,67 +87,38 @@ public final class Values {
     private static final Map<Object, ValueFactory> VALUE_FACTORIES = new HashMap<Object,
ValueFactory>() {{
         ValueFactory valueFactory = new ValueFactory() {
             @Override
-            public QValue create(Object value) throws RepositoryException {
-                return create((String) value);
-            }
-
-            @Override
             public QValue create(String value) throws RepositoryException {
                 return FACTORY.create(value, STRING);
             }
         };
-        put(String.class, valueFactory);
         put(TYPES[STRING], valueFactory);
 
         valueFactory = new ValueFactory() {
             @Override
-            public QValue create(Object value) throws RepositoryException {
-                return FACTORY.create((Long) value);
-            }
-
-            @Override
             public QValue create(String value) throws RepositoryException {
                 return FACTORY.create(value, LONG);
             }
         };
-        put(Long.class, valueFactory);
         put(TYPES[LONG], valueFactory);
 
         valueFactory = new ValueFactory() {
             @Override
-            public QValue create(Object value) throws RepositoryException {
-                return FACTORY.create((Double) value);
-            }
-
-            @Override
             public QValue create(String value) throws RepositoryException {
                 return FACTORY.create(value, DOUBLE);
             }
         };
-        put(Double.class, valueFactory);
         put(TYPES[DOUBLE], valueFactory);
 
         valueFactory = new ValueFactory() {
             @Override
-            public QValue create(Object value) throws RepositoryException {
-                return FACTORY.create((Boolean) value);
-            }
-
-            @Override
             public QValue create(String value) throws RepositoryException {
                 return FACTORY.create(value, BOOLEAN);
             }
         };
-        put(Boolean.class, valueFactory);
         put(TYPES[BOOLEAN], valueFactory);
 
         valueFactory = new ValueFactory() {
             @Override
-            public QValue create(Object value) throws RepositoryException {
-                throw new RepositoryException("Invalid value " + value);
-            }
-
-            @Override
             public QValue create(String value) throws RepositoryException {
                 return FACTORY.create(value, DECIMAL);
             }
@@ -153,11 +127,6 @@ public final class Values {
 
         valueFactory = new ValueFactory() {
             @Override
-            public QValue create(Object value) throws RepositoryException {
-                throw new RepositoryException("Invalid value " + value);
-            }
-
-            @Override
             public QValue create(String value) throws RepositoryException {
                 return FACTORY.create(value, DATE);
             }
@@ -166,11 +135,6 @@ public final class Values {
 
         valueFactory = new ValueFactory() {
             @Override
-            public QValue create(Object value) throws RepositoryException {
-                throw new RepositoryException("Invalid value " + value);
-            }
-
-            @Override
             public QValue create(String value) throws RepositoryException {
                 return FACTORY.create(value, URI);
             }
@@ -179,11 +143,6 @@ public final class Values {
 
         valueFactory = new ValueFactory() {
             @Override
-            public QValue create(Object value) throws RepositoryException {
-                throw new RepositoryException("Invalid value " + value);
-            }
-
-            @Override
             public QValue create(String value) throws RepositoryException {
                 return FACTORY.create(Paths.stringToName(value));
             }
@@ -192,11 +151,6 @@ public final class Values {
 
         valueFactory = new ValueFactory() {
             @Override
-            public QValue create(Object value) throws RepositoryException {
-                throw new RepositoryException("Invalid value " + value);
-            }
-
-            @Override
             public QValue create(String value) throws RepositoryException {
                 return FACTORY.create(Paths.stringToPath(value));
             }
@@ -205,11 +159,6 @@ public final class Values {
 
         valueFactory = new ValueFactory() {
             @Override
-            public QValue create(Object value) throws RepositoryException {
-                throw new RepositoryException("Invalid value " + value);
-            }
-
-            @Override
             public QValue create(String value) throws RepositoryException {
                 try {
                     ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -225,11 +174,6 @@ public final class Values {
 
         valueFactory = new ValueFactory() {
             @Override
-            public QValue create(Object value) throws RepositoryException {
-                throw new RepositoryException("Invalid value " + value);
-            }
-
-            @Override
             public QValue create(String value) throws RepositoryException {
                 return FACTORY.create(value, REFERENCE);
             }
@@ -238,11 +182,6 @@ public final class Values {
 
         valueFactory = new ValueFactory() {
             @Override
-            public QValue create(Object value) throws RepositoryException {
-                throw new RepositoryException("Invalid value " + value);
-            }
-
-            @Override
             public QValue create(String value) throws RepositoryException {
                 return FACTORY.create(value, WEAKREFERENCE);
             }
@@ -252,22 +191,23 @@ public final class Values {
 
     private Values() {}
 
-    public static QValue objectToValue(Object value) throws RepositoryException {
-        return objectToValue(value, null);
+    public static QValue tokenToValue(Token token) throws RepositoryException {
+        return tokenToValue(token, null);
     }
 
-    public static QValue objectToValue(Object value, Function1<String, QValue> binaryHandler)
throws RepositoryException {
+    public static QValue tokenToValue(Token token, Function1<String, QValue> binaryHandler)
+            throws RepositoryException {
+        
         // Type encoded value
-        if (value instanceof String) {
-            String val = (String) value;
+        if (token.type() == Type.STRING) {
+            String val = token.text();
             if (val.length() >= 2 && val.charAt(1) == ':') {
-                ValueFactory valueFactory;
                 char type = val.charAt(0);
                 if (type == toHex(BLOB_REF_TYPE)) {
                     try {
                         if (binaryHandler == null) {
-                            IllegalArgumentException e = new IllegalArgumentException("Binary
value found but " +
-                                    "binaryHandler is null");
+                            IllegalArgumentException e = new IllegalArgumentException(
+                                    "Binary value found but binaryHandler is null");
                             log.error(e.getMessage(), e);
                             throw e;
                         }
@@ -283,32 +223,53 @@ public final class Values {
                     }
                 }
                 else {
-                    valueFactory = VALUE_FACTORIES.get(type);
-                }
+                    ValueFactory valueFactory = VALUE_FACTORIES.get(type);
+                    if (valueFactory == null) {
+                        RepositoryException e = new RepositoryException("Cannot convert to
value: " + token);
+                            log.error(e.getMessage(), e);
+                            throw e;
+                    }
 
-                if (valueFactory == null) {
-                    RepositoryException e = new RepositoryException("Not supported value
" + value);
-                    log.error(e.getMessage(), e);
-                    throw e;
-                }
-                else {
                     return valueFactory.create(val.substring(2));
                 }
             }
         }
 
         // Non type encoded value
-        ValueFactory valueFactory = VALUE_FACTORIES.get(value.getClass());
-        if (valueFactory == null) {
-            RepositoryException e = new RepositoryException("Not supported value " + value);
-            log.error(e.getMessage(), e);
-            throw e;
-        }
-        else {
-            return valueFactory.create(value);
+        switch (token.type()) {
+            case TRUE:   return FACTORY.create(true);
+            case FALSE:  return FACTORY.create(false);
+            case STRING: return FACTORY.create(token.text(), STRING);
+            case NUMBER:
+                try {
+                    return FACTORY.create(Long.parseLong(token.text()));
+                }
+                catch (NumberFormatException e0) {
+                    try {
+                        return FACTORY.create(Double.parseDouble(token.text()));
+                    }
+                    catch (NumberFormatException e1) {
+                        try {
+                            return FACTORY.create(new BigDecimal(token.text()));
+                        }
+                        catch (RepositoryException e2) {
+                            RepositoryException e = new RepositoryException("Cannot convert
to value: " + token, e2);
+                            log.error(e.getMessage(), e);
+                            throw e;
+                        }
+                    }
+                }
+            default:
+                RepositoryException e = new RepositoryException("Cannot convert to value:
" + token);
+                log.error(e.getMessage(), e);
+                throw e;
         }
     }
 
+    public static QValue stringToValue(String string) throws RepositoryException {
+        return FACTORY.create(string, STRING);
+    }
+    
     public static QValue pathToValue(Path path) throws RepositoryException {
         return FACTORY.create(path);
     }
@@ -498,7 +459,6 @@ public final class Values {
     }
 
     private interface ValueFactory {
-        QValue create(Object value) throws RepositoryException;
         QValue create(String value) throws RepositoryException;
     }
 }



Mime
View raw message