From 8a0328a2d3edc5319aa4206d2061356a48f35e72 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Mon, 27 Jan 2014 12:30:33 +0100 Subject: [PATCH] Refactoring using more meaningful names for properties interface and getter --- .../java/com/google/gwt/query/client/GQ.java | 8 ++-- .../client/{Binder.java => IsProperties.java} | 12 ++--- .../google/gwt/query/client/Properties.java | 10 ++-- .../query/client/builders/JsonBuilder.java | 4 +- .../client/builders/JsonBuilderBase.java | 12 ++--- .../query/client/builders/JsonFactory.java | 6 +-- .../gwt/query/client/plugins/ajax/Ajax.java | 46 +++++++++---------- .../plugins/deferred/PromiseReqBuilder.java | 10 ++-- .../query/rebind/JsonBuilderGenerator.java | 4 +- .../google/gwt/query/vm/AjaxTransportJre.java | 4 +- .../google/gwt/query/vm/JsonFactoryJre.java | 24 +++++----- .../gwt/query/client/ajax/AjaxTests.java | 10 ++-- 12 files changed, 75 insertions(+), 75 deletions(-) rename gwtquery-core/src/main/java/com/google/gwt/query/client/{Binder.java => IsProperties.java} (87%) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java index 27dbbe78..ea2fcce3 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java @@ -38,17 +38,17 @@ public abstract class GQ { return ret; } - public static T create(Class clz, Binder obj) { + public static T create(Class clz, IsProperties obj) { T ret = create(clz); - ret.load(obj.getBound()); + ret.load(obj.getDataImpl()); return ret; } - public static Binder create(String s) { + public static IsProperties create(String s) { return getFactory().create(s); } - public static Binder create() { + public static IsProperties create() { return getFactory().create(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Binder.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java similarity index 87% rename from gwtquery-core/src/main/java/com/google/gwt/query/client/Binder.java rename to gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java index 852a3c41..f973afb0 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Binder.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java @@ -21,22 +21,22 @@ import com.google.gwt.query.client.builders.JsonBuilder; /** * Interface using for Data Binders valid for JVM and JS. */ -public interface Binder { +public interface IsProperties { /** * load a properties object. */ - T load(Object prp); + T load(Object prp); /** * parses a json string and loads the resulting properties object. */ - T parse(String json); + T parse(String json); /** * Returns the underlying object, normally a Properties jso in client - * and a Json implementation in JVM. + * and a Json implementation in the JVM. */ - T getBound(); + T getDataImpl(); /** * Return the Object with the given key. @@ -46,7 +46,7 @@ public interface Binder { /** * Set an Object with the given key. */ - T set(Object key, Object val); + T set(Object key, Object val); /** * return a list of field names. diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java index d24a7f98..ce703aed 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java @@ -25,7 +25,7 @@ import com.google.gwt.query.client.js.JsUtils; /** * JSO for accessing Javascript objective literals used by GwtQuery functions. */ -public class Properties extends JavaScriptObject implements Binder { +public class Properties extends JavaScriptObject implements IsProperties { public static Properties create() { return JsCache.create().cast(); @@ -202,15 +202,15 @@ public class Properties extends JavaScriptObject implements Binder { return c().length() == 0; } - public final J load(Object prp) { + public final J load(Object prp) { c().clear(); if (prp instanceof JsCache) { c().copy((JsCache)prp); } - return getBound(); + return getDataImpl(); } - public final J parse(String json) { + public final J parse(String json) { return load(JsUtils.parseJSON(json)); } @@ -227,7 +227,7 @@ public class Properties extends JavaScriptObject implements Binder { } @SuppressWarnings("unchecked") - public final J getBound() { + public final J getDataImpl() { return (J)this; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilder.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilder.java index 6e6d6f3a..b5f30451 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilder.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilder.java @@ -15,13 +15,13 @@ */ package com.google.gwt.query.client.builders; -import com.google.gwt.query.client.Binder; +import com.google.gwt.query.client.IsProperties; /** * Tagging interface used to generate JsonBuilder classes. */ -public interface JsonBuilder extends Binder { +public interface JsonBuilder extends IsProperties { /** * parses a json string and loads the resulting properties object, diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java index cfa77296..8ccc9e75 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java @@ -17,7 +17,7 @@ package com.google.gwt.query.client.builders; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; -import com.google.gwt.query.client.Binder; +import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.Properties; import com.google.gwt.query.client.js.JsObjectArray; import com.google.gwt.query.client.js.JsUtils; @@ -55,7 +55,7 @@ public abstract class JsonBuilderBase> implements J if (r.length > 0 && r[0] instanceof JsonBuilder) { JsArray a = JavaScriptObject.createArray().cast(); for (T o : r) { - a.push(((JsonBuilder)o).getBound()); + a.push(((JsonBuilder)o).getDataImpl()); } p.set(n, a); } else { @@ -114,7 +114,7 @@ public abstract class JsonBuilderBase> implements J @SuppressWarnings("unchecked") @Override - public Properties getBound() { + public Properties getDataImpl() { return p; } @@ -123,9 +123,9 @@ public abstract class JsonBuilderBase> implements J } @SuppressWarnings("unchecked") - public T set(Object key, Object val) { - if (val instanceof Binder) { - p.set(key, ((Binder)val).getBound()); + public T set(Object key, Object val) { + if (val instanceof IsProperties) { + p.set(key, ((IsProperties)val).getDataImpl()); } else { p.set(key, val); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonFactory.java index 4bc57c9c..847fcfbd 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonFactory.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonFactory.java @@ -1,9 +1,9 @@ package com.google.gwt.query.client.builders; -import com.google.gwt.query.client.Binder; +import com.google.gwt.query.client.IsProperties; public interface JsonFactory { T create(Class clz); - Binder create(String s); - Binder create(); + IsProperties create(String s); + IsProperties create(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java index 566ab14d..7b472ba5 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java @@ -6,7 +6,7 @@ import com.google.gwt.core.client.ScriptInjector; import com.google.gwt.dom.client.Element; import com.google.gwt.http.client.Request; import com.google.gwt.http.client.Response; -import com.google.gwt.query.client.Binder; +import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQ; import com.google.gwt.query.client.GQuery; @@ -52,11 +52,11 @@ public class Ajax extends GQuery { public interface Settings extends JsonBuilder { String getContentType(); Element getContext(); - Binder getData(); + IsProperties getData(); String getDataString(); String getDataType(); Function getError(); - Binder getHeaders(); + IsProperties getHeaders(); String getPassword(); Function getSuccess(); int getTimeout(); @@ -70,7 +70,7 @@ public class Ajax extends GQuery { Settings setDataString(String d); Settings setDataType(String t); Settings setError(Function f); - Settings setHeaders(Binder p); + Settings setHeaders(IsProperties p); Settings setPassword(String p); Settings setSuccess(Function f); Settings setTimeout(int t); @@ -86,7 +86,7 @@ public class Ajax extends GQuery { } }); - public static Promise ajax(Binder p) { + public static Promise ajax(IsProperties p) { Settings s = createSettings(); s.load(p); return ajax(s); @@ -198,10 +198,10 @@ public class Ajax extends GQuery { } settings.setType(type); - Binder data = settings.getData(); + IsProperties data = settings.getData(); if (data != null) { String dataString = null, contentType = null; - if (data.getBound() instanceof JavaScriptObject && JsUtils.isFormData(data.getBound())) { + if (data.getDataImpl() instanceof JavaScriptObject && JsUtils.isFormData(data.getDataImpl())) { dataString = null; contentType = FormPanel.ENCODING_URLENCODED; } else if (settings.getType().matches("(POST|PUT)") && "json".equalsIgnoreCase(settings.getDataType())) { @@ -233,7 +233,7 @@ public class Ajax extends GQuery { return ajax(s); } - public static Promise ajax(String url, Binder p) { + public static Promise ajax(String url, IsProperties p) { Settings s = createSettings(); s.load(p); s.setUrl(url); @@ -255,9 +255,9 @@ public class Ajax extends GQuery { return s; } - public static Settings createSettings(Binder p) { + public static Settings createSettings(IsProperties p) { Settings s = GQ.create(Settings.class); - s.load(p.getBound()); + s.load(p.getDataImpl()); return s; } @@ -265,11 +265,11 @@ public class Ajax extends GQuery { return get(url, null); } - public static Promise get(String url, Binder data) { - return get(url, (Binder)data, null); + public static Promise get(String url, IsProperties data) { + return get(url, (IsProperties)data, null); } - public static Promise get(String url, Binder data, Function onSuccess) { + public static Promise get(String url, IsProperties data, Function onSuccess) { Settings s = createSettings(); s.setUrl(url); s.setDataType("txt"); @@ -279,11 +279,11 @@ public class Ajax extends GQuery { return ajax(s); } - public static Promise getJSON(String url, Binder data) { + public static Promise getJSON(String url, IsProperties data) { return getJSON(url, data, null); } - public static Promise getJSON(String url, Binder data, Function onSuccess) { + public static Promise getJSON(String url, IsProperties data, Function onSuccess) { Settings s = createSettings(); s.setUrl(url); s.setDataType("json"); @@ -297,11 +297,11 @@ public class Ajax extends GQuery { return getJSONP(url, null); } - public static Promise getJSONP(String url, Binder data) { - return getJSONP(url, (Binder)data, null); + public static Promise getJSONP(String url, IsProperties data) { + return getJSONP(url, (IsProperties)data, null); } - public static Promise getJSONP(String url, Binder data, Function onSuccess) { + public static Promise getJSONP(String url, IsProperties data, Function onSuccess) { Settings s = createSettings(); s.setUrl(url); s.setDataType("jsonp"); @@ -354,11 +354,11 @@ public class Ajax extends GQuery { ); } - public static Promise post(String url, Binder data) { - return post(url, (Binder)data, null); + public static Promise post(String url, IsProperties data) { + return post(url, (IsProperties)data, null); } - public static Promise post(String url, Binder data, final Function onSuccess) { + public static Promise post(String url, IsProperties data, final Function onSuccess) { Settings s = createSettings(); s.setUrl(url); s.setDataType("txt"); @@ -372,11 +372,11 @@ public class Ajax extends GQuery { super(gq); } - public Ajax load(String url, Binder data) { + public Ajax load(String url, IsProperties data) { return load(url, data); } - public Ajax load(String url, Binder data, final Function onSuccess) { + public Ajax load(String url, IsProperties data, final Function onSuccess) { Settings s = createSettings(); final String filter = url.contains(" ") ? url.replaceFirst("^[^\\s]+\\s+", "") : ""; s.setUrl(url.replaceAll("\\s+.+$", "")); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilder.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilder.java index 4aec8a37..41f32b37 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilder.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilder.java @@ -21,7 +21,7 @@ import com.google.gwt.http.client.RequestCallback; import com.google.gwt.http.client.RequestException; import com.google.gwt.http.client.RequestPermissionException; import com.google.gwt.http.client.Response; -import com.google.gwt.query.client.Binder; +import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.js.JsCache; import com.google.gwt.query.client.js.JsUtils; @@ -66,9 +66,9 @@ public class PromiseReqBuilder extends DeferredPromiseImpl implements RequestCal public PromiseReqBuilder(Settings settings) { String httpMethod = settings.getType(); String url = settings.getUrl(); - Binder data = settings.getData(); + IsProperties data = settings.getData(); String ctype = settings.getContentType(); - Boolean isFormData = data != null && data.getBound() instanceof JavaScriptObject && JsUtils.isFormData(data.getBound()); + Boolean isFormData = data != null && data.getDataImpl() instanceof JavaScriptObject && JsUtils.isFormData(data.getDataImpl()); XMLHttpRequest xmlHttpRequest = XMLHttpRequest.create(); try { @@ -107,7 +107,7 @@ public class PromiseReqBuilder extends DeferredPromiseImpl implements RequestCal } })); - Binder headers = settings.getHeaders(); + IsProperties headers = settings.getHeaders(); if (headers != null) { for (String headerKey : headers.getFieldNames()) { xmlHttpRequest.setRequestHeader(headerKey, String.valueOf(headers.get(headerKey))); @@ -134,7 +134,7 @@ public class PromiseReqBuilder extends DeferredPromiseImpl implements RequestCal }); try { - JsUtils.runJavascriptFunction(xmlHttpRequest, "send", isFormData ? data.getBound() : settings.getDataString()); + JsUtils.runJavascriptFunction(xmlHttpRequest, "send", isFormData ? data.getDataImpl() : settings.getDataString()); } catch (JavaScriptException e) { onError(null, e); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java index 3fc7868c..729f3a46 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java @@ -38,7 +38,7 @@ import com.google.gwt.core.ext.typeinfo.JType; import com.google.gwt.core.ext.typeinfo.TypeOracle; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.Properties; -import com.google.gwt.query.client.Binder; +import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.builders.JsonBuilder; import com.google.gwt.query.client.builders.JsonBuilderBase; import com.google.gwt.query.client.builders.JsonFactory; @@ -84,7 +84,7 @@ public class JsonBuilderGenerator extends Generator { JClassType clazz = oracle.findType(requestedClass); jsonBuilderType = oracle.findType(JsonBuilder.class.getName()); - settingsType = oracle.findType(Binder.class.getName()); + settingsType = oracle.findType(IsProperties.class.getName()); stringType = oracle.findType(String.class.getName()); jsType = oracle.findType(JavaScriptObject.class.getName()); listType = oracle.findType(List.class.getName()); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java b/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java index 9da7f420..d6f2fcdb 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java @@ -10,7 +10,7 @@ import java.net.URL; import com.google.gwt.http.client.RequestException; import com.google.gwt.http.client.Response; -import com.google.gwt.query.client.Binder; +import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQ; import com.google.gwt.query.client.GQuery; @@ -146,7 +146,7 @@ public class AjaxTransportJre implements AjaxTransport { c.setReadTimeout(s.getTimeout()); } - Binder headers = s.getHeaders(); + IsProperties headers = s.getHeaders(); if (headers != null) { for (String h : headers.getFieldNames()) { c.setRequestProperty(h, "" + headers.get(h)); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java b/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java index 4a1b9c3c..80881507 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java @@ -14,7 +14,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import com.google.gwt.query.client.Binder; +import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQ; import com.google.gwt.query.client.Properties; @@ -101,7 +101,7 @@ public class JsonFactoryJre implements JsonFactory { if (ret instanceof JSONObject) { if (clz == Object.class) { ret = jsonFactory.createBinder((JSONObject)ret); - } else if (Binder.class.isAssignableFrom(clz) && !clz.isAssignableFrom(ret.getClass())) { + } else if (IsProperties.class.isAssignableFrom(clz) && !clz.isAssignableFrom(ret.getClass())) { ret = jsonFactory.create(clz, (JSONObject)ret); } } @@ -136,8 +136,8 @@ public class JsonFactoryJre implements JsonFactory { return obj != null ? obj.put(attr, o) : arr.put(o); } else if (o instanceof Date) { return obj != null ? obj.put(attr, ((Date) o).getTime()) : arr.put(((Date) o).getTime()); - } else if (o instanceof Binder) { - return obj != null ? obj.put(attr, ((Binder) o).getBound()) : arr.put(((Binder) o).getBound()); + } else if (o instanceof IsProperties) { + return obj != null ? obj.put(attr, ((IsProperties) o).getDataImpl()) : arr.put(((IsProperties) o).getDataImpl()); } else if (o.getClass().isArray() || o instanceof List) { Object[] arg; if (o.getClass().isArray()) { @@ -175,7 +175,7 @@ public class JsonFactoryJre implements JsonFactory { return jsonFactory.create(clz, jsonObject); } else if ("getJsonName".equals(mname)) { return JsonBuilderGenerator.classNameToJsonName(getDataBindingClassName(proxy.getClass())); - } else if (mname.matches("getProperties|getBound")) { + } else if (mname.matches("getProperties|getDataImpl")) { return jsonObject; } else if (largs > 0 && ("parse".equals(mname) || "load".equals(mname))) { jsonObject = new JSONObject(String.valueOf(args[0])); @@ -282,25 +282,25 @@ public class JsonFactoryJre implements JsonFactory { return (T) Proxy.newProxyInstance(clz.getClassLoader(), new Class[] {clz}, handler); } - public Binder createBinder() { + public IsProperties createBinder() { InvocationHandler handler = new JsonBuilderHandler(); - return (Binder)Proxy.newProxyInstance(Binder.class.getClassLoader(), new Class[] {Binder.class}, handler); + return (IsProperties)Proxy.newProxyInstance(IsProperties.class.getClassLoader(), new Class[] {IsProperties.class}, handler); } - public Binder createBinder(JSONObject jso) { + public IsProperties createBinder(JSONObject jso) { InvocationHandler handler = new JsonBuilderHandler(jso); - return (Binder)Proxy.newProxyInstance(Binder.class.getClassLoader(), new Class[] {Binder.class}, handler); + return (IsProperties)Proxy.newProxyInstance(IsProperties.class.getClassLoader(), new Class[] {IsProperties.class}, handler); } @Override - public Binder create(String s) { - Binder ret = createBinder(); + public IsProperties create(String s) { + IsProperties ret = createBinder(); ret.parse(Properties.wrapPropertiesString(s)); return ret; } @Override - public Binder create() { + public IsProperties create() { return createBinder(); } } diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/ajax/AjaxTests.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/ajax/AjaxTests.java index ee3005c9..f5d0cbf5 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/ajax/AjaxTests.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/ajax/AjaxTests.java @@ -21,7 +21,7 @@ import com.google.gwt.http.client.Response; import com.google.gwt.junit.DoNotRunWith; import com.google.gwt.junit.Platform; import com.google.gwt.junit.client.GWTTestCase; -import com.google.gwt.query.client.Binder; +import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQ; import com.google.gwt.query.client.Promise; @@ -34,7 +34,7 @@ import com.google.gwt.query.client.plugins.ajax.Ajax.Settings; public abstract class AjaxTests extends GWTTestCase { protected String echoUrl, echoUrlCORS; - protected Binder json, jsonGET; + protected IsProperties json, jsonGET; protected String servletPath = "test.json"; private Function failFunction = new Function() { @@ -58,7 +58,7 @@ public abstract class AjaxTests extends GWTTestCase { delayTestFinish(5000); return Ajax.ajax(s) .done(new Function(){public void f() { - Binder p = arguments(0); + IsProperties p = arguments(0); assertEquals("abc", p.get("a")); finishTest(); }}) @@ -183,10 +183,10 @@ public abstract class AjaxTests extends GWTTestCase { Ajax.getJSONP("https://www.googleapis.com/blogger/v2/blogs/user_id/posts/post_id?callback=?&key=NO-KEY") .done(new Function(){ public void f() { - Binder p = arguments(0); + IsProperties p = arguments(0); // It should return error since we do not use a valid key // {"error":{"errors":[{"domain":"usageLimits","reason":"keyInvalid","message":"Bad Request"}],"code":400,"message":"Bad Request"}} - assertEquals(400, p.get("error").get("code").intValue()); + assertEquals(400, p.get("error").get("code").intValue()); finishTest(); } }) -- 2.39.5