jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1212033 - in /jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit: json/JsonValue.java utils/ValueConverter.java
Date Thu, 08 Dec 2011 18:58:37 GMT
Author: mduerig
Date: Thu Dec  8 18:58:36 2011
New Revision: 1212033

URL: http://svn.apache.org/viewvc?rev=1212033&view=rev
Log:
Microkernel based prototype of JCR implementation (WIP)
- add factory methods
- add remove method

Modified:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/json/JsonValue.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/ValueConverter.java

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/json/JsonValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/json/JsonValue.java?rev=1212033&r1=1212032&r2=1212033&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/json/JsonValue.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/json/JsonValue.java
Thu Dec  8 18:58:36 2011
@@ -19,7 +19,10 @@
 
 package org.apache.jackrabbit.json;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -274,6 +277,25 @@ public abstract class JsonValue {
             this.type = type;
         }
 
+        public static JsonAtom string(String value) {
+            return new JsonAtom(value, Type.STRING);
+        }
+        
+        public static JsonAtom number(double value) {
+            if (Double.isNaN(value) || Double.isInfinite(value)) {
+                throw new IllegalArgumentException(Double.toString(value));
+            }
+            return new JsonAtom(Double.toString(value), Type.NUMBER);
+        }
+        
+        public static JsonAtom number(long value) {
+            return new JsonAtom(Long.toString(value), Type.NUMBER);
+        }
+        
+        public static JsonAtom number(BigDecimal value) {
+            return new JsonAtom(value.toString(), Type.NUMBER);
+        }
+
         /**
          * Create a new {@code JsonAtom} from {@code token}.
          * @param token
@@ -356,6 +378,10 @@ public abstract class JsonValue {
             this.values = values;
         }
 
+        public JsonArray() {
+            this(new ArrayList<JsonValue>());
+        }
+
         /**
          * Append {@code value} to the end of this array.
          * @param value
@@ -436,6 +462,10 @@ public abstract class JsonValue {
             this.values = values;
         }
 
+        public JsonObject() {
+            this(new HashMap<String, JsonValue>());
+        }
+
         /**
          * Put {@code value} into this object
          * @param key
@@ -454,6 +484,16 @@ public abstract class JsonValue {
             return values.get(key);
         }
 
+        /**
+         * Remove {@code key} from this object
+         * @param key
+         * @return  the {@code JsonValue} identified by {@code key} or {@code null}
+         * if no value exists for {@code key}.
+         */
+        public JsonValue remove(String key) {
+            return values.remove(key);
+        }
+
         public boolean isEmpty() {
             return values.isEmpty();
         }

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/ValueConverter.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/ValueConverter.java?rev=1212033&r1=1212032&r2=1212033&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/ValueConverter.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/ValueConverter.java
Thu Dec  8 18:58:36 2011
@@ -22,7 +22,6 @@ package org.apache.jackrabbit.utils;
 import org.apache.jackrabbit.json.JsonValue;
 import org.apache.jackrabbit.json.JsonValue.JsonArray;
 import org.apache.jackrabbit.json.JsonValue.JsonAtom;
-import org.apache.jackrabbit.json.JsonValue.Type;
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -39,15 +38,19 @@ public final class ValueConverter {
     public static JsonValue toJsonValue(Value value) throws RepositoryException {
         switch (value.getType()) {
             case PropertyType.STRING: {
-                return new JsonAtom(value.getString(), Type.STRING);
+                return JsonAtom.string(value.getString());
+            }
+            case PropertyType.DOUBLE: {
+                return JsonAtom.number(value.getDouble()); // todo mind NaN
+            }
+            case PropertyType.LONG: {
+                return JsonAtom.number(value.getLong());
             }
-            case PropertyType.LONG:
-            case PropertyType.DOUBLE:
             case PropertyType.DECIMAL: {
-                return new JsonAtom(value.getString(), Type.NUMBER);  // todo mind NaN
+                return JsonAtom.number(value.getDecimal());
             }
             case PropertyType.BOOLEAN: {
-                return new JsonAtom(value.getString(), Type.BOOLEAN);
+                return value.getBoolean() ? JsonAtom.TRUE : JsonAtom.FALSE;
             }
             case PropertyType.BINARY:
             case PropertyType.DATE:



Mime
View raw message