+++ /dev/null
-/*
- * Copyright 2013, The gwtquery team.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.query.client;
-
-import com.google.gwt.query.client.builders.JsonBuilder;
-
-
-/**
- * Interface using for Data Binders valid for JVM and JS.
- */
-public interface Binder {
- /**
- * load a properties object.
- */
- <T extends Binder> T load(Object prp);
-
- /**
- * parses a json string and loads the resulting properties object.
- */
- <T extends Binder> T parse(String json);
-
- /**
- * Returns the underlying object, normally a Properties jso in client
- * and a Json implementation in JVM.
- */
- <T> T getBound();
-
- /**
- * Return the Object with the given key.
- */
- <T> T get(Object key);
-
- /**
- * Set an Object with the given key.
- */
- <T extends Binder> T set(Object key, Object val);
-
- /**
- * return a list of field names.
- */
- String[] getFieldNames();
-
- /**
- * return a json string which represents the object.
- * Example {"name":"manolo","surname":"carrasco"}
- */
- String toJson();
-
- /**
- * return a string which represents the object with an alias for the
- * className useful for serialization.
- *
- * Example {"user":{"name":"manolo","surname":"carrasco"}}
- */
- String toJsonWithName();
-
- /**
- * return a string which represents the object in a queryString format.
- */
- String toQueryString();
-
- /**
- * return the name for this type
- */
- String getJsonName();
-
-
- <T extends JsonBuilder> T as (Class<T> clz);
-}
return ret;
}
- public static <T extends JsonBuilder> T create(Class<T> clz, Binder obj) {
+ public static <T extends JsonBuilder> T create(Class<T> 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();
}
--- /dev/null
+/*
+ * Copyright 2013, The gwtquery team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.query.client;
+
+import com.google.gwt.query.client.builders.JsonBuilder;
+
+
+/**
+ * Interface using for Data Binders valid for JVM and JS.
+ */
+public interface IsProperties {
+ /**
+ * load a properties object.
+ */
+ <T extends IsProperties> T load(Object prp);
+
+ /**
+ * parses a json string and loads the resulting properties object.
+ */
+ <T extends IsProperties> T parse(String json);
+
+ /**
+ * Returns the underlying object, normally a Properties jso in client
+ * and a Json implementation in the JVM.
+ */
+ <T> T getDataImpl();
+
+ /**
+ * Return the Object with the given key.
+ */
+ <T> T get(Object key);
+
+ /**
+ * Set an Object with the given key.
+ */
+ <T extends IsProperties> T set(Object key, Object val);
+
+ /**
+ * return a list of field names.
+ */
+ String[] getFieldNames();
+
+ /**
+ * return a json string which represents the object.
+ * Example {"name":"manolo","surname":"carrasco"}
+ */
+ String toJson();
+
+ /**
+ * return a string which represents the object with an alias for the
+ * className useful for serialization.
+ *
+ * Example {"user":{"name":"manolo","surname":"carrasco"}}
+ */
+ String toJsonWithName();
+
+ /**
+ * return a string which represents the object in a queryString format.
+ */
+ String toQueryString();
+
+ /**
+ * return the name for this type
+ */
+ String getJsonName();
+
+
+ <T extends JsonBuilder> T as (Class<T> clz);
+}
/**
* 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();
return c().length() == 0;
}
- public final <J extends Binder> J load(Object prp) {
+ public final <J extends IsProperties> J load(Object prp) {
c().clear();
if (prp instanceof JsCache) {
c().copy((JsCache)prp);
}
- return getBound();
+ return getDataImpl();
}
- public final <J extends Binder> J parse(String json) {
+ public final <J extends IsProperties> J parse(String json) {
return load(JsUtils.parseJSON(json));
}
}
@SuppressWarnings("unchecked")
- public final <J> J getBound() {
+ public final <J> J getDataImpl() {
return (J)this;
}
*/
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,
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;
if (r.length > 0 && r[0] instanceof JsonBuilder) {
JsArray<JavaScriptObject> a = JavaScriptObject.createArray().cast();
for (T o : r) {
- a.push(((JsonBuilder)o).<Properties>getBound());
+ a.push(((JsonBuilder)o).<Properties>getDataImpl());
}
p.set(n, a);
} else {
@SuppressWarnings("unchecked")
@Override
- public Properties getBound() {
+ public Properties getDataImpl() {
return p;
}
}
@SuppressWarnings("unchecked")
- public <T extends Binder> T set(Object key, Object val) {
- if (val instanceof Binder) {
- p.set(key, ((Binder)val).getBound());
+ public <T extends IsProperties> T set(Object key, Object val) {
+ if (val instanceof IsProperties) {
+ p.set(key, ((IsProperties)val).getDataImpl());
} else {
p.set(key, val);
}
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 extends JsonBuilder> T create(Class<T> clz);
- Binder create(String s);
- Binder create();
+ IsProperties create(String s);
+ IsProperties create();
}
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;
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();
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);
}
});
- public static Promise ajax(Binder p) {
+ public static Promise ajax(IsProperties p) {
Settings s = createSettings();
s.load(p);
return ajax(s);
}
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.<JavaScriptObject>getBound())) {
+ if (data.getDataImpl() instanceof JavaScriptObject && JsUtils.isFormData(data.<JavaScriptObject>getDataImpl())) {
dataString = null;
contentType = FormPanel.ENCODING_URLENCODED;
} else if (settings.getType().matches("(POST|PUT)") && "json".equalsIgnoreCase(settings.getDataType())) {
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);
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;
}
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");
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");
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");
);
}
- 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");
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+.+$", ""));
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;
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.<JavaScriptObject>getBound());
+ Boolean isFormData = data != null && data.getDataImpl() instanceof JavaScriptObject && JsUtils.isFormData(data.<JavaScriptObject>getDataImpl());
XMLHttpRequest xmlHttpRequest = XMLHttpRequest.create();
try {
}
}));
- Binder headers = settings.getHeaders();
+ IsProperties headers = settings.getHeaders();
if (headers != null) {
for (String headerKey : headers.getFieldNames()) {
xmlHttpRequest.setRequestHeader(headerKey, String.valueOf(headers.get(headerKey)));
});
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);
}
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;
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());
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;
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));
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;
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);
}
}
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()) {
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]));
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();
}
}
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;
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() {
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();
}})
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.<Binder>get("error").<Number>get("code").intValue());
+ assertEquals(400, p.<IsProperties>get("error").<Number>get("code").intValue());
finishTest();
}
})