jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1305797 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ oak-mk/src/main/java/org/apache/jackrabbit/mk/json/ oak-mk/src/main/java/org/apache/jackrabbit/mk/model/
Date Tue, 27 Mar 2012 09:54:50 GMT
Author: mduerig
Date: Tue Mar 27 09:54:50 2012
New Revision: 1305797

URL: http://svn.apache.org/viewvc?rev=1305797&view=rev
Log:
OAK-33: Values in oak-core
- implemented default json encoding in AbstractPropertyState

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/json/JsonBuilder.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/AbstractPropertyState.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/PropertyState.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java?rev=1305797&r1=1305796&r2=1305797&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
Tue Mar 27 09:54:50 2012
@@ -18,10 +18,8 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
-import org.apache.jackrabbit.mk.json.JsonBuilder;
 import org.apache.jackrabbit.mk.model.AbstractPropertyState;
 import org.apache.jackrabbit.mk.model.Scalar;
-import org.apache.jackrabbit.mk.model.Scalar.Type;
 
 import java.util.Collections;
 import java.util.List;
@@ -50,24 +48,6 @@ public class KernelPropertyState extends
     }
 
     @Override
-    public String getEncodedValue() {
-        if (value == null) {
-            String sep = "";
-            StringBuilder sb = new StringBuilder("[");
-            for (Scalar s : values) {
-                sb.append(sep);
-                sep = ",";
-                sb.append(encodeValue(s));
-            }
-            sb.append(']');
-            return sb.toString();
-        }
-        else {
-            return encodeValue(value);
-        }
-    }
-
-    @Override
     public boolean isArray() {
         return value == null;
     }
@@ -82,14 +62,4 @@ public class KernelPropertyState extends
         return values;
     }
 
-    //------------------------------------------------------------< private >
-
-    private static String encodeValue(Scalar value) {
-        if (value.getType() == Type.STRING) {
-            return '"' + JsonBuilder.escape(value.getString()) + '"';
-        }
-        else {
-            return value.getString();
-        }
-    }
 }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/json/JsonBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/json/JsonBuilder.java?rev=1305797&r1=1305796&r2=1305797&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/json/JsonBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/json/JsonBuilder.java
Tue Mar 27 09:54:50 2012
@@ -19,6 +19,8 @@
 
 package org.apache.jackrabbit.mk.json;
 
+import org.apache.jackrabbit.mk.model.Scalar;
+
 import java.io.IOException;
 
 /**
@@ -441,5 +443,28 @@ public final class JsonBuilder {
         sb.append(']');
         return sb.toString();
     }
+    
+    public static String encode(Scalar scalar) {
+        switch (scalar.getType()) {
+            case BOOLEAN: return encode(scalar.getBoolean());
+            case LONG:    return encode(scalar.getLong());
+            case DOUBLE:  return encode(scalar.getDouble());
+            case BINARY:  return null; // TODO implement encoding of binaries
+            case STRING:  return encode(scalar.getString());
+            case NULL:    return "null";
+        }
+        throw new IllegalStateException("unreachable");  // Make javac happy
+    }
 
+    public static String encode(Iterable<Scalar> scalars) {
+        StringBuilder sb = new StringBuilder();
+        sb.append('[');
+        for (Scalar scalar : scalars) {
+            sb.append(encode(scalar));
+            sb.append(',');
+        }
+        sb.deleteCharAt(sb.length() - 1);
+        sb.append(']');
+        return sb.toString();
+    }
 }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/AbstractPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/AbstractPropertyState.java?rev=1305797&r1=1305796&r2=1305797&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/AbstractPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/AbstractPropertyState.java
Tue Mar 27 09:54:50 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.mk.model;
 
+import org.apache.jackrabbit.mk.json.JsonBuilder;
+
 /**
  * Abstract base class for {@link PropertyState} implementations.
  * This base class contains default implementations of the
@@ -25,14 +27,24 @@ package org.apache.jackrabbit.mk.model;
 public abstract class AbstractPropertyState implements PropertyState {
 
     /**
+     * Default implementation delegating to {@link JsonBuilder#encode(Scalar)}.
+     * Derived classes may override this with more efficient implementations.
+     */
+    @Override
+    public String getEncodedValue() {
+        return isArray()
+            ? JsonBuilder.encode(getArray())
+            : JsonBuilder.encode(getScalar());
+    }
+
+    /**
      * Checks whether the given object is equal to this one. Two property
      * states are considered equal if both their names and encoded values
      * match. Subclasses may override this method with a more efficient
      * equality check if one is available.
      *
      * @param that target of the comparison
-     * @return <code>true</code> if the objects are equal,
-     *         <code>false</code> otherwise
+     * @return {@code true} if the objects are equal, {@code false} otherwise
      */
     @Override
     public boolean equals(Object that) {

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/PropertyState.java?rev=1305797&r1=1305796&r2=1305797&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/PropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/PropertyState.java
Tue Mar 27 09:54:50 2012
@@ -37,7 +37,7 @@ public interface PropertyState {
     String getName();
 
     /**
-     * FIXME: replace with type-specific accessors
+     * @return the JSON encoded value of this property state.
      */
     String getEncodedValue();
 



Mime
View raw message