]> source.dussan.org Git - vaadin-framework.git/commitdiff
Remove redundant ConnectorMap from JsonEncoder.encode
authorLeif Åstrand <leif@vaadin.com>
Tue, 5 Jun 2012 12:18:03 +0000 (15:18 +0300)
committerLeif Åstrand <leif@vaadin.com>
Wed, 6 Jun 2012 10:33:52 +0000 (13:33 +0300)
src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
src/com/vaadin/terminal/gwt/client/communication/JSONSerializer.java
src/com/vaadin/terminal/gwt/client/communication/JsonEncoder.java
src/com/vaadin/terminal/gwt/client/communication/URLReference_Serializer.java
src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java

index 1b902e8e4025ad8ba36725c44cf878d80f28cca9..0a954f530b23b3e33953e9a38669b34e05c79383 100644 (file)
@@ -1711,7 +1711,7 @@ public class ApplicationConnection {
                     // TODO non-static encoder? type registration?
                     paramJson.set(i, JsonEncoder.encode(
                             invocation.getParameters()[i],
-                            restrictToInternalTypes, getConnectorMap(), this));
+                            restrictToInternalTypes, this));
                 }
                 invocationJson.set(3, paramJson);
                 reqJson.set(reqJson.size(), invocationJson);
index fe879b2fa77f23648fafc2fba7e794ec687bdcf3..9820b6a895e12a10698d8ceb4e7296bc5b9b80d6 100644 (file)
@@ -47,12 +47,8 @@ public interface JSONSerializer<T> {
      * 
      * @param value
      *            The object to serialize
-     * @param idMapper
-     *            mapper from paintable id to paintable, used to decode
-     *            references to paintables
      * @return A JSON serialized version of the object
      */
-    JSONValue serialize(T value, ConnectorMap idMapper,
-            ApplicationConnection connection);
+    JSONValue serialize(T value, ApplicationConnection connection);
 
 }
index df095833dc8feb5520f022f5a2ae68c1161a725a..9b0b690ed43f2abde4431e1a6fe285cc07638635 100644 (file)
@@ -18,7 +18,6 @@ import com.google.gwt.json.client.JSONString;
 import com.google.gwt.json.client.JSONValue;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.Connector;
-import com.vaadin.terminal.gwt.client.ConnectorMap;
 
 /**
  * Encoder for converting RPC parameters and other values to JSON for transfer
@@ -53,14 +52,11 @@ public class JsonEncoder {
      * 
      * @param value
      *            value to convert
-     * @param connectorMap
-     *            mapper from connectors to connector IDs
      * @param connection
      * @return JSON representation of the value
      */
     public static JSONValue encode(Object value,
-            boolean restrictToInternalTypes, ConnectorMap connectorMap,
-            ApplicationConnection connection) {
+            boolean restrictToInternalTypes, ApplicationConnection connection) {
         if (null == value) {
             return JSONNull.getInstance();
         } else if (value instanceof String[]) {
@@ -76,29 +72,27 @@ public class JsonEncoder {
             return JSONBoolean.getInstance((Boolean) value);
         } else if (value instanceof Object[]) {
             return encodeObjectArray((Object[]) value, restrictToInternalTypes,
-                    connectorMap, connection);
+                    connection);
         } else if (value instanceof Enum) {
             if (restrictToInternalTypes) {
                 // Enums are encoded as strings in Vaadin 6 so we still do that
                 // for backwards copmatibility.
                 return encode(new UidlValue(value.toString()),
-                        restrictToInternalTypes, connectorMap, connection);
+                        restrictToInternalTypes, connection);
             } else {
                 Enum e = (Enum) value;
-                return encodeEnum(e, connectorMap, connection);
+                return encodeEnum(e, connection);
             }
         } else if (value instanceof Map) {
-            return encodeMap((Map) value, restrictToInternalTypes,
-                    connectorMap, connection);
+            return encodeMap((Map) value, restrictToInternalTypes, connection);
         } else if (value instanceof Connector) {
             Connector connector = (Connector) value;
             return new JSONString(connector.getConnectorId());
         } else if (value instanceof Collection) {
             return encodeCollection((Collection) value,
-                    restrictToInternalTypes, connectorMap, connection);
+                    restrictToInternalTypes, connection);
         } else if (value instanceof UidlValue) {
-            return encodeVariableChange((UidlValue) value, connectorMap,
-                    connection);
+            return encodeVariableChange((UidlValue) value, connection);
         } else {
             String transportType = getTransportType(value);
             if (transportType != null) {
@@ -111,25 +105,24 @@ public class JsonEncoder {
                         .getSerializer(transportType);
 
                 // TODO handle case with no serializer found
-                return serializer.serialize(value, connectorMap, connection);
+                return serializer.serialize(value, connection);
             }
         }
     }
 
     private static JSONValue encodeVariableChange(UidlValue uidlValue,
-            ConnectorMap connectorMap, ApplicationConnection connection) {
+            ApplicationConnection connection) {
         Object value = uidlValue.getValue();
 
         JSONArray jsonArray = new JSONArray();
         jsonArray.set(0, new JSONString(getTransportType(value)));
-        jsonArray.set(1, encode(value, true, connectorMap, connection));
+        jsonArray.set(1, encode(value, true, connection));
 
         return jsonArray;
     }
 
     private static JSONValue encodeMap(Map<Object, Object> map,
-            boolean restrictToInternalTypes, ConnectorMap connectorMap,
-            ApplicationConnection connection) {
+            boolean restrictToInternalTypes, ApplicationConnection connection) {
         /*
          * As we have no info about declared types, we instead select encoding
          * scheme based on actual type of first key. We can't do this if there's
@@ -142,28 +135,26 @@ public class JsonEncoder {
 
         Object firstKey = map.keySet().iterator().next();
         if (firstKey instanceof String) {
-            return encodeStringMap(map, restrictToInternalTypes, connectorMap,
-                    connection);
+            return encodeStringMap(map, restrictToInternalTypes, connection);
         } else if (restrictToInternalTypes) {
             throw new IllegalStateException(
                     "Only string keys supported for legacy maps");
         } else if (firstKey instanceof Connector) {
-            return encodeConenctorMap(map, connectorMap, connection);
+            return encodeConenctorMap(map, connection);
         } else {
-            return encodeObjectMap(map, connectorMap, connection);
+            return encodeObjectMap(map, connection);
         }
     }
 
     private static JSONValue encodeObjectMap(Map<Object, Object> map,
-            ConnectorMap connectorMap, ApplicationConnection connection) {
+            ApplicationConnection connection) {
         JSONArray keys = new JSONArray();
         JSONArray values = new JSONArray();
         for (Entry<?, ?> entry : map.entrySet()) {
             // restrictToInternalTypes always false if we end up here
-            keys.set(keys.size(),
-                    encode(entry.getKey(), false, connectorMap, connection));
+            keys.set(keys.size(), encode(entry.getKey(), false, connection));
             values.set(values.size(),
-                    encode(entry.getValue(), false, connectorMap, connection));
+                    encode(entry.getValue(), false, connection));
         }
 
         JSONArray keysAndValues = new JSONArray();
@@ -174,15 +165,14 @@ public class JsonEncoder {
     }
 
     private static JSONValue encodeConenctorMap(Map<Object, Object> map,
-            ConnectorMap connectorMap, ApplicationConnection connection) {
+            ApplicationConnection connection) {
         JSONObject jsonMap = new JSONObject();
 
         for (Entry<?, ?> entry : map.entrySet()) {
             Connector connector = (Connector) entry.getKey();
 
             // restrictToInternalTypes always false if we end up here
-            JSONValue encodedValue = encode(entry.getValue(), false,
-                    connectorMap, connection);
+            JSONValue encodedValue = encode(entry.getValue(), false, connection);
 
             jsonMap.put(connector.getConnectorId(), encodedValue);
         }
@@ -191,8 +181,7 @@ public class JsonEncoder {
     }
 
     private static JSONValue encodeStringMap(Map<Object, Object> map,
-            boolean restrictToInternalTypes, ConnectorMap connectorMap,
-            ApplicationConnection connection) {
+            boolean restrictToInternalTypes, ApplicationConnection connection) {
         JSONObject jsonMap = new JSONObject();
 
         for (Entry<?, ?> entry : map.entrySet()) {
@@ -204,7 +193,7 @@ public class JsonEncoder {
             }
 
             JSONValue encodedValue = encode(value, restrictToInternalTypes,
-                    connectorMap, connection);
+                    connection);
 
             jsonMap.put(key, encodedValue);
         }
@@ -212,14 +201,13 @@ public class JsonEncoder {
         return jsonMap;
     }
 
-    private static JSONValue encodeEnum(Enum e, ConnectorMap connectorMap,
+    private static JSONValue encodeEnum(Enum<?> e,
             ApplicationConnection connection) {
         return new JSONString(e.toString());
     }
 
     private static JSONValue encodeObjectArray(Object[] array,
-            boolean restrictToInternalTypes, ConnectorMap connectorMap,
-            ApplicationConnection connection) {
+            boolean restrictToInternalTypes, ApplicationConnection connection) {
         JSONArray jsonArray = new JSONArray();
         for (int i = 0; i < array.length; ++i) {
             // TODO handle object graph loops?
@@ -227,22 +215,19 @@ public class JsonEncoder {
             if (restrictToInternalTypes) {
                 value = new UidlValue(value);
             }
-            jsonArray.set(
-                    i,
-                    encode(value, restrictToInternalTypes, connectorMap,
-                            connection));
+            jsonArray
+                    .set(i, encode(value, restrictToInternalTypes, connection));
         }
         return jsonArray;
     }
 
     private static JSONValue encodeCollection(Collection collection,
-            boolean restrictToInternalTypes, ConnectorMap connectorMap,
-            ApplicationConnection connection) {
+            boolean restrictToInternalTypes, ApplicationConnection connection) {
         JSONArray jsonArray = new JSONArray();
         int idx = 0;
         for (Object o : collection) {
             JSONValue encodedObject = encode(o, restrictToInternalTypes,
-                    connectorMap, connection);
+                    connection);
             jsonArray.set(idx++, encodedObject);
         }
         if (collection instanceof Set) {
index f6108bbfa823f08cbcde24b8fe72d4859f12a97e..56c4bb96231a3b00f45840f145dae2e807b64a86 100644 (file)
@@ -7,7 +7,6 @@ import com.google.gwt.core.client.GWT;
 import com.google.gwt.json.client.JSONObject;
 import com.google.gwt.json.client.JSONValue;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.ConnectorMap;
 
 public class URLReference_Serializer implements JSONSerializer<URLReference> {
 
@@ -25,11 +24,10 @@ public class URLReference_Serializer implements JSONSerializer<URLReference> {
         return reference;
     }
 
-    public JSONValue serialize(URLReference value, ConnectorMap idMapper,
-            ApplicationConnection connection) {
+    public JSONValue serialize(URLReference value, ApplicationConnection connection) {
         JSONObject json = new JSONObject();
         json.put("URL",
-                JsonEncoder.encode(value.getURL(), true, idMapper, connection));
+                JsonEncoder.encode(value.getURL(), true, connection));
         return json;
     }
 
index 6e99089434af84ef5ce9b72a7af495de822d798d..6e1ebdfc7f785144a64adeb3e170e4aa717faf1f 100644 (file)
@@ -28,7 +28,6 @@ import com.google.gwt.json.client.JSONValue;
 import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
 import com.google.gwt.user.rebind.SourceWriter;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.ConnectorMap;
 import com.vaadin.terminal.gwt.client.communication.DiffJSONSerializer;
 import com.vaadin.terminal.gwt.client.communication.JSONSerializer;
 import com.vaadin.terminal.gwt.client.communication.JsonDecoder;
@@ -128,11 +127,10 @@ public class SerializerGenerator extends Generator {
 
         // Serializer
 
-        // public JSONValue serialize(Object value, ConnectorMap idMapper,
+        // public JSONValue serialize(Object value,
         // ApplicationConnection connection) {
         sourceWriter.println("public " + JSONValue.class.getName()
                 + " serialize(" + beanQualifiedSourceName + " value, "
-                + ConnectorMap.class.getName() + " idMapper, "
                 + ApplicationConnection.class.getName() + " connection) {");
         sourceWriter.indent();
         // MouseEventDetails castedValue = (MouseEventDetails) value;
@@ -306,7 +304,7 @@ public class SerializerGenerator extends Generator {
             // connection));
             sourceWriter.println("json.put(\"" + fieldName + "\",  "
                     + JsonEncoder.class.getName() + ".encode(castedValue."
-                    + getterName + "(), false, idMapper, connection));");
+                    + getterName + "(), false, connection));");
         }
         // return json;
         sourceWriter.println("return json;");