]> source.dussan.org Git - vaadin-framework.git/commitdiff
Wrap variable change data in UidlValue wrapper with type info (#8878)
authorLeif Åstrand <leif@vaadin.com>
Wed, 30 May 2012 12:13:26 +0000 (15:13 +0300)
committerLeif Åstrand <leif@vaadin.com>
Wed, 6 Jun 2012 10:33:35 +0000 (13:33 +0300)
This is the first step towards dropping type info from the sent data for
everything except changeVariables data

src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
src/com/vaadin/terminal/gwt/client/communication/JsonEncoder.java
src/com/vaadin/terminal/gwt/client/communication/UidlValue.java [new file with mode: 0644]
src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
src/com/vaadin/terminal/gwt/server/JsonCodec.java

index c3bdc405aacf4efc484810e1583af43372798902..530fd546dba84685185d9b2c6da2abcf8366ff13 100644 (file)
@@ -45,6 +45,7 @@ import com.vaadin.terminal.gwt.client.communication.MethodInvocation;
 import com.vaadin.terminal.gwt.client.communication.RpcManager;
 import com.vaadin.terminal.gwt.client.communication.SerializerMap;
 import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
+import com.vaadin.terminal.gwt.client.communication.UidlValue;
 import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector;
 import com.vaadin.terminal.gwt.client.ui.VContextMenu;
 import com.vaadin.terminal.gwt.client.ui.dd.VDragAndDropManager;
@@ -1600,7 +1601,7 @@ public class ApplicationConnection {
         // TODO could eliminate invocations of same shared variable setter
         addMethodInvocationToQueue(new MethodInvocation(connectorId,
                 UPDATE_VARIABLE_INTERFACE, UPDATE_VARIABLE_METHOD,
-                new Object[] { variableName, value }), immediate);
+                new Object[] { variableName, new UidlValue(value) }), immediate);
     }
 
     /**
index f09536a9f7385ad7a246b542dfc1152c532a1ad3..edd900174a8866165d102b0cbc32f1f532fe2ebf 100644 (file)
@@ -46,6 +46,12 @@ public class JsonEncoder {
     public static final String VTYPE_SET = "q";
     public static final String VTYPE_NULL = "n";
 
+    /**
+     * Temporary hack to get variable changes decoded as internal types in
+     * JsonCodec.
+     */
+    public static final String VTYPE_UIDL_VALUE = "v";
+
     /**
      * Encode a value to a JSON representation for transport from the client to
      * the server.
@@ -98,6 +104,9 @@ public class JsonEncoder {
         } else if (value instanceof Collection) {
             return encodeCollection((Collection) value,
                     restrictToInternalTypes, connectorMap, connection);
+        } else if (value instanceof UidlValue) {
+            return encodeVariableChange((UidlValue) value, connectorMap,
+                    connection);
         } else {
             String transportType = getTransportType(value);
             if (transportType != null) {
@@ -117,6 +126,14 @@ public class JsonEncoder {
         }
     }
 
+    private static JSONValue encodeVariableChange(UidlValue value,
+            ConnectorMap connectorMap, ApplicationConnection connection) {
+        JSONArray encodedValue = encode(value.getValue(), true, connectorMap,
+                connection).isArray();
+
+        return combineTypeAndValue(VTYPE_UIDL_VALUE, encodedValue);
+    }
+
     private static JSONValue encodeMap(Map<Object, Object> map,
             boolean restrictToInternalTypes, ConnectorMap connectorMap,
             ApplicationConnection connection) {
diff --git a/src/com/vaadin/terminal/gwt/client/communication/UidlValue.java b/src/com/vaadin/terminal/gwt/client/communication/UidlValue.java
new file mode 100644 (file)
index 0000000..2a21074
--- /dev/null
@@ -0,0 +1,25 @@
+/* 
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.terminal.gwt.client.communication;
+
+import java.io.Serializable;
+
+public class UidlValue implements Serializable {
+    private Object value;
+
+    public UidlValue(Object value) {
+        this.value = value;
+    }
+
+    public Object getValue() {
+        return value;
+    }
+
+    @Override
+    public String toString() {
+        return "" + value;
+    }
+
+}
index 15b148ce7fb71ac4ea1a25aaadc760e9c74b8139..5ead96c42e9ba8526110db11c9d4c22852716849 100644 (file)
@@ -68,6 +68,7 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.Connector;
 import com.vaadin.terminal.gwt.client.communication.MethodInvocation;
 import com.vaadin.terminal.gwt.client.communication.SharedState;
+import com.vaadin.terminal.gwt.client.communication.UidlValue;
 import com.vaadin.terminal.gwt.server.BootstrapHandler.BootstrapContext;
 import com.vaadin.terminal.gwt.server.ComponentSizeValidator.InvalidLayout;
 import com.vaadin.ui.AbstractComponent;
@@ -1630,9 +1631,11 @@ public abstract class AbstractCommunicationManager implements Serializable {
         String variableName = (String) JsonCodec
                 .decodeInternalType(String.class, true,
                         parametersJson.getJSONArray(0), application);
-        Object value = JsonCodec.decodeInternalType(
+        UidlValue uidlValue = (UidlValue) JsonCodec.decodeInternalType(
                 parametersJson.getJSONArray(1), application);
 
+        Object value = uidlValue.getValue();
+
         if (previousInvocation != null
                 && previousInvocation.getConnectorId().equals(connectorId)) {
             previousInvocation.setVariableChange(variableName, value);
index e082eca47efc2da3fe29e3f7a3045ed51f159849..9c7abc53b466d5b17029a3283d39cebbdbd45f82 100644 (file)
@@ -13,6 +13,7 @@ import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -27,6 +28,7 @@ import com.vaadin.external.json.JSONException;
 import com.vaadin.external.json.JSONObject;
 import com.vaadin.terminal.gwt.client.Connector;
 import com.vaadin.terminal.gwt.client.communication.JsonEncoder;
+import com.vaadin.terminal.gwt.client.communication.UidlValue;
 import com.vaadin.ui.Component;
 
 /**
@@ -64,6 +66,7 @@ public class JsonCodec implements Serializable {
         registerType(HashMap.class, JsonEncoder.VTYPE_MAP);
         registerType(List.class, JsonEncoder.VTYPE_LIST);
         registerType(Set.class, JsonEncoder.VTYPE_SET);
+        registerType(UidlValue.class, JsonEncoder.VTYPE_UIDL_VALUE);
     }
 
     private static void registerType(Class<?> type, String transportType) {
@@ -195,6 +198,13 @@ public class JsonCodec implements Serializable {
         if (JsonEncoder.VTYPE_NULL.equals(encodedTransportType)) {
             return null;
         }
+
+        // VariableChange
+        if (JsonEncoder.VTYPE_UIDL_VALUE.contentEquals(transportType)) {
+            return decodeVariableChange((JSONArray) encodedJsonValue,
+                    application);
+        }
+
         // Collections
         if (JsonEncoder.VTYPE_LIST.equals(transportType)) {
             return decodeList(targetType, restrictToInternalTypes,
@@ -244,6 +254,17 @@ public class JsonCodec implements Serializable {
         throw new JSONException("Unknown type " + transportType);
     }
 
+    private static UidlValue decodeVariableChange(JSONArray encodedJsonValue,
+            Application application) throws JSONException {
+        String type = encodedJsonValue.getString(0);
+
+        // Fake format used by decode method
+        JSONArray valueAndType = new JSONArray(Arrays.asList(type,
+                encodedJsonValue.get(1)));
+        Object decodedValue = decodeInternalType(valueAndType, application);
+        return new UidlValue(decodedValue);
+    }
+
     private static boolean transportTypesCompatible(
             String encodedTransportType, String transportType) {
         if (encodedTransportType == null) {