diff options
author | Artur Signell <artur@vaadin.com> | 2015-01-11 12:18:11 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2015-01-11 13:28:16 +0200 |
commit | 44d34f59c0faf23e12cd3439199b7ee05509a35d (patch) | |
tree | dc1b64d94c2aab719dd30b1a16d8e14a4336960f | |
parent | 38a9f36eb2a2c3de1959c70a0a992466858f4c20 (diff) | |
download | vaadin-framework-44d34f59c0faf23e12cd3439199b7ee05509a35d.tar.gz vaadin-framework-44d34f59c0faf23e12cd3439199b7ee05509a35d.zip |
Move elemental json dependency to DWS (#15544)
Change-Id: I1b525e4d8df60f8e36bad9e5054d948da5b34813
9 files changed, 80 insertions, 80 deletions
diff --git a/client/src/com/vaadin/DefaultWidgetSet.gwt.xml b/client/src/com/vaadin/DefaultWidgetSet.gwt.xml index 7694be9de6..3047924ac7 100755 --- a/client/src/com/vaadin/DefaultWidgetSet.gwt.xml +++ b/client/src/com/vaadin/DefaultWidgetSet.gwt.xml @@ -8,6 +8,9 @@ <inherits name="com.vaadin.Vaadin" /> + <!-- Elemental is used for handling Json only --> + <inherits name="elemental.Json" /> + <entry-point class="com.vaadin.client.ApplicationConfiguration" /> <generate-with diff --git a/client/src/com/vaadin/Vaadin.gwt.xml b/client/src/com/vaadin/Vaadin.gwt.xml index 2072df67d9..1bbece6bd6 100644 --- a/client/src/com/vaadin/Vaadin.gwt.xml +++ b/client/src/com/vaadin/Vaadin.gwt.xml @@ -10,8 +10,6 @@ <inherits name="com.google.gwt.http.HTTP" /> - <inherits name="elemental.Json" /> - <inherits name="com.google.gwt.logging.Logging" /> <set-property name="gwt.logging.enabled" value="TRUE" /> diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index a84b7d7472..ac0656505a 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -2158,7 +2158,7 @@ public class ApplicationConnection implements HasHandlers { JavaScriptObject jso = states .getJavaScriptObject(connectorId); - JsonObject stateJson = WidgetUtil.jso2json(jso); + JsonObject stateJson = Util.jso2json(jso); if (connector instanceof HasJavaScriptConnectorHelper) { ((HasJavaScriptConnectorHelper) connector) @@ -2530,7 +2530,7 @@ public class ApplicationConnection implements HasHandlers { VConsole.log(" * Performing server to client RPC calls"); - JsonArray rpcCalls = WidgetUtil.jso2json(json + JsonArray rpcCalls = Util.jso2json(json .getJavaScriptObject("rpc")); int rpcLength = rpcCalls.length(); diff --git a/client/src/com/vaadin/client/JavaScriptConnectorHelper.java b/client/src/com/vaadin/client/JavaScriptConnectorHelper.java index 524e1ee9aa..11511f9c36 100644 --- a/client/src/com/vaadin/client/JavaScriptConnectorHelper.java +++ b/client/src/com/vaadin/client/JavaScriptConnectorHelper.java @@ -319,7 +319,7 @@ public class JavaScriptConnectorHelper { iface = findWildcardInterface(method); } - JsonArray argumentsArray = WidgetUtil.jso2json(arguments); + JsonArray argumentsArray = Util.jso2json(arguments); Object[] parameters = new Object[arguments.length()]; for (int i = 0; i < parameters.length; i++) { parameters[i] = argumentsArray.get(i); @@ -383,7 +383,7 @@ public class JavaScriptConnectorHelper { }-*/; public Object[] decodeRpcParameters(JsonArray parametersJson) { - return new Object[] { WidgetUtil.json2jso(parametersJson) }; + return new Object[] { Util.json2jso(parametersJson) }; } public void setTag(int tag) { @@ -397,11 +397,10 @@ public class JavaScriptConnectorHelper { if ("com.vaadin.ui.JavaScript$JavaScriptCallbackRpc".equals(iface) && "call".equals(method)) { String callbackName = parametersJson.getString(0); - JavaScriptObject arguments = WidgetUtil.json2jso(parametersJson - .get(1)); + JavaScriptObject arguments = Util.json2jso(parametersJson.get(1)); invokeCallback(getConnectorWrapper(), callbackName, arguments); } else { - JavaScriptObject arguments = WidgetUtil.json2jso(parametersJson); + JavaScriptObject arguments = Util.json2jso(parametersJson); invokeJsRpc(rpcMap, iface, method, arguments); // Also invoke wildcard interface invokeJsRpc(rpcMap, "", method, arguments); diff --git a/client/src/com/vaadin/client/Util.java b/client/src/com/vaadin/client/Util.java index ee3e8a5781..778f7c3861 100644 --- a/client/src/com/vaadin/client/Util.java +++ b/client/src/com/vaadin/client/Util.java @@ -22,6 +22,8 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; +import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.event.dom.client.KeyEvent; @@ -37,6 +39,9 @@ import com.vaadin.shared.communication.MethodInvocation; import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.util.SharedUtil; +import elemental.js.json.JsJsonValue; +import elemental.json.JsonValue; + public class Util { /** @@ -895,4 +900,64 @@ public class Util { WidgetUtil.setSelectionRange(elem, pos, length, direction); } + /** + * Converts a native {@link JavaScriptObject} into a {@link JsonValue}. This + * is a no-op in GWT code compiled to javascript, but needs some special + * handling to work when run in JVM. + * + * @param jso + * the java script object to represent as json + * @return the json representation + */ + public static <T extends JsonValue> T jso2json(JavaScriptObject jso) { + if (GWT.isProdMode()) { + return (T) jso.<JsJsonValue> cast(); + } else { + return elemental.json.Json.instance().parse(stringify(jso)); + } + } + + /** + * Converts a {@link JsonValue} into a native {@link JavaScriptObject}. This + * is a no-op in GWT code compiled to javascript, but needs some special + * handling to work when run in JVM. + * + * @param jsonValue + * the json value + * @return a native javascript object representation of the json value + */ + public static JavaScriptObject json2jso(JsonValue jsonValue) { + if (GWT.isProdMode()) { + return ((JavaScriptObject) jsonValue.toNative()).cast(); + } else { + return parse(jsonValue.toJson()); + } + } + + /** + * Convert a {@link JavaScriptObject} into a string representation. + * + * @param json + * a JavaScript object to be converted to a string + * @return JSON in string representation + */ + private native static String stringify(JavaScriptObject json) + /*-{ + return JSON.stringify(json); + }-*/; + + /** + * Parse a string containing JSON into a {@link JavaScriptObject}. + * + * @param <T> + * the overlay type to expect from the parse + * @param jsonAsString + * @return a JavaScript object constructed from the parse + */ + public native static <T extends JavaScriptObject> T parse( + String jsonAsString) + /*-{ + return JSON.parse(jsonAsString); + }-*/; + } diff --git a/client/src/com/vaadin/client/VUIDLBrowser.java b/client/src/com/vaadin/client/VUIDLBrowser.java index 137b5241be..08f4c653a5 100644 --- a/client/src/com/vaadin/client/VUIDLBrowser.java +++ b/client/src/com/vaadin/client/VUIDLBrowser.java @@ -161,7 +161,7 @@ public class VUIDLBrowser extends SimpleTree { } else { setText("Unknown connector (" + connectorId + ")"); } - dir((JsonObject) WidgetUtil.jso2json(stateChanges), this); + dir((JsonObject) Util.jso2json(stateChanges), this); } @Override diff --git a/client/src/com/vaadin/client/WidgetUtil.java b/client/src/com/vaadin/client/WidgetUtil.java index e05155d440..96f161c4a8 100644 --- a/client/src/com/vaadin/client/WidgetUtil.java +++ b/client/src/com/vaadin/client/WidgetUtil.java @@ -21,8 +21,6 @@ import java.util.HashMap; import java.util.Map; import java.util.logging.Logger; -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.AnchorElement; @@ -48,9 +46,6 @@ import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.util.SharedUtil; -import elemental.js.json.JsJsonValue; -import elemental.json.JsonValue; - /** * Utility methods which are related to client side code only */ @@ -1224,66 +1219,6 @@ public class WidgetUtil { }-*/; /** - * Converts a native {@link JavaScriptObject} into a {@link JsonValue}. This - * is a no-op in GWT code compiled to javascript, but needs some special - * handling to work when run in JVM. - * - * @param jso - * the java script object to represent as json - * @return the json representation - */ - public static <T extends JsonValue> T jso2json(JavaScriptObject jso) { - if (GWT.isProdMode()) { - return (T) jso.<JsJsonValue> cast(); - } else { - return elemental.json.Json.instance().parse(stringify(jso)); - } - } - - /** - * Converts a {@link JsonValue} into a native {@link JavaScriptObject}. This - * is a no-op in GWT code compiled to javascript, but needs some special - * handling to work when run in JVM. - * - * @param jsonValue - * the json value - * @return a native javascript object representation of the json value - */ - public static JavaScriptObject json2jso(JsonValue jsonValue) { - if (GWT.isProdMode()) { - return ((JavaScriptObject) jsonValue.toNative()).cast(); - } else { - return parse(jsonValue.toJson()); - } - } - - /** - * Convert a {@link JavaScriptObject} into a string representation. - * - * @param json - * a JavaScript object to be converted to a string - * @return JSON in string representation - */ - private native static String stringify(JavaScriptObject json) - /*-{ - return JSON.stringify(json); - }-*/; - - /** - * Parse a string containing JSON into a {@link JavaScriptObject}. - * - * @param <T> - * the overlay type to expect from the parse - * @param jsonAsString - * @return a JavaScript object constructed from the parse - */ - public native static <T extends JavaScriptObject> T parse( - String jsonAsString) - /*-{ - return JSON.parse(jsonAsString); - }-*/; - - /** * The allowed value inaccuracy when comparing two double-typed pixel * values. * <p> diff --git a/client/src/com/vaadin/client/communication/StateChangeEvent.java b/client/src/com/vaadin/client/communication/StateChangeEvent.java index eeb0a76fb9..c2c1ceaea9 100644 --- a/client/src/com/vaadin/client/communication/StateChangeEvent.java +++ b/client/src/com/vaadin/client/communication/StateChangeEvent.java @@ -25,11 +25,12 @@ import com.vaadin.client.FastStringSet; import com.vaadin.client.JsArrayObject; import com.vaadin.client.Profiler; import com.vaadin.client.ServerConnector; -import com.vaadin.client.WidgetUtil; +import com.vaadin.client.Util; import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler; import com.vaadin.client.metadata.NoDataException; import com.vaadin.client.metadata.Property; import com.vaadin.client.ui.AbstractConnector; + import elemental.json.JsonObject; public class StateChangeEvent extends @@ -204,7 +205,7 @@ public class StateChangeEvent extends return true; } else if (stateJson != null) { // Check whether it's in the json object - return isInJson(property, WidgetUtil.json2jso(stateJson)); + return isInJson(property, Util.json2jso(stateJson)); } else { // Legacy cases if (changedProperties != null) { diff --git a/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java b/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java index 7950d2f94a..d48571452e 100644 --- a/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java +++ b/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java @@ -22,7 +22,7 @@ import java.util.Set; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; import com.vaadin.client.ServerConnector; -import com.vaadin.client.WidgetUtil; +import com.vaadin.client.Util; import com.vaadin.client.communication.JavaScriptMethodInvocation; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.extensions.AbstractExtensionConnector; @@ -116,8 +116,7 @@ public class JavaScriptManagerConnector extends AbstractExtensionConnector { }-*/; public void sendRpc(String name, JsArray<JavaScriptObject> arguments) { - Object[] parameters = new Object[] { name, - WidgetUtil.jso2json(arguments) }; + Object[] parameters = new Object[] { name, Util.jso2json(arguments) }; /* * Must invoke manually as the RPC interface can't be used in GWT |