From e88a49764e1a797089f65566e77482c6cc585c91 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Tue, 5 Jun 2012 15:18:03 +0300 Subject: [PATCH] Remove redundant ConnectorMap from JsonEncoder.encode --- .../gwt/client/ApplicationConnection.java | 2 +- .../client/communication/JSONSerializer.java | 6 +- .../gwt/client/communication/JsonEncoder.java | 69 ++++++++----------- .../URLReference_Serializer.java | 6 +- .../widgetsetutils/SerializerGenerator.java | 6 +- 5 files changed, 33 insertions(+), 56 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 1b902e8e40..0a954f530b 100644 --- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -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); diff --git a/src/com/vaadin/terminal/gwt/client/communication/JSONSerializer.java b/src/com/vaadin/terminal/gwt/client/communication/JSONSerializer.java index fe879b2fa7..9820b6a895 100644 --- a/src/com/vaadin/terminal/gwt/client/communication/JSONSerializer.java +++ b/src/com/vaadin/terminal/gwt/client/communication/JSONSerializer.java @@ -47,12 +47,8 @@ public interface JSONSerializer { * * @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); } diff --git a/src/com/vaadin/terminal/gwt/client/communication/JsonEncoder.java b/src/com/vaadin/terminal/gwt/client/communication/JsonEncoder.java index df095833dc..9b0b690ed4 100644 --- a/src/com/vaadin/terminal/gwt/client/communication/JsonEncoder.java +++ b/src/com/vaadin/terminal/gwt/client/communication/JsonEncoder.java @@ -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 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 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 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 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) { diff --git a/src/com/vaadin/terminal/gwt/client/communication/URLReference_Serializer.java b/src/com/vaadin/terminal/gwt/client/communication/URLReference_Serializer.java index f6108bbfa8..56c4bb9623 100644 --- a/src/com/vaadin/terminal/gwt/client/communication/URLReference_Serializer.java +++ b/src/com/vaadin/terminal/gwt/client/communication/URLReference_Serializer.java @@ -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 { @@ -25,11 +24,10 @@ public class URLReference_Serializer implements JSONSerializer { 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; } diff --git a/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java b/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java index 6e99089434..6e1ebdfc7f 100644 --- a/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java +++ b/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java @@ -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;"); -- 2.39.5