aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>2014-01-07 07:52:46 +0100
committerManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>2014-01-07 07:52:46 +0100
commit235ee04e1a8b1fb274be05c7755c511377908404 (patch)
treeb0e43f3cd4610eace465a71f16620481ba0b0c9d
parent678d438e2183286844a3f0444b10bd5bd92ff228 (diff)
downloadgwtquery-235ee04e1a8b1fb274be05c7755c511377908404.tar.gz
gwtquery-235ee04e1a8b1fb274be05c7755c511377908404.zip
Implement as method to convert between types
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/Binder.java7
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java7
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java8
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilder.java2
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java6
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java1
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java6
7 files changed, 30 insertions, 7 deletions
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/Binder.java
index ba45ceb1..2f0e47e5 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/Binder.java
@@ -15,6 +15,8 @@
*/
package com.google.gwt.query.client;
+import com.google.gwt.query.client.builders.JsonBuilder;
+
/**
* Interface using for Data Binders valid for JVM and JS.
@@ -73,5 +75,8 @@ public interface Binder {
/**
* return the name for this type
*/
- String getName();
+ String getJsonName();
+
+
+ <T extends JsonBuilder> T as (Class<T> clz);
}
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 5120bf3d..46cee7e1 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
@@ -22,7 +22,6 @@ import com.google.gwt.query.client.plugins.ajax.Ajax.AjaxTransport;
import com.google.gwt.query.client.plugins.ajax.AjaxTransportJs;
import com.google.gwt.query.vm.AjaxTransportJre;
import com.google.gwt.query.vm.JsonFactoryJre;
-import com.google.gwt.user.client.Window;
public abstract class GQ {
@@ -39,6 +38,12 @@ public abstract class GQ {
return ret;
}
+ public static <T extends JsonBuilder> T create(Class<T> clz, Binder obj) {
+ T ret = create(clz);
+ ret.load(obj.getBound());
+ return ret;
+ }
+
public static <T extends Binder> T create(String s) {
return getFactory().create(s);
}
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 b367e19f..60ac6a6b 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
@@ -18,6 +18,7 @@ package com.google.gwt.query.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayMixed;
+import com.google.gwt.query.client.builders.JsonBuilder;
import com.google.gwt.query.client.js.JsCache;
import com.google.gwt.query.client.js.JsUtils;
@@ -230,8 +231,13 @@ public class Properties extends JavaScriptObject implements Binder {
return (J)this;
}
- public final String getName() {
+ public final String getJsonName() {
return "jso";
}
+ public final <T extends JsonBuilder> T as(Class<T> clz) {
+ T ret = GQ.create(clz);
+ ret.load(this);
+ return ret;
+ }
}
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 6508d300..6e6d6f3a 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
@@ -40,5 +40,5 @@ public interface JsonBuilder extends Binder {
/**
* return the short name of this class, to use in json structures.
*/
- String getName();
+ String getJsonName();
}
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 dd45ec7d..c4b5af88 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
@@ -97,7 +97,7 @@ public abstract class JsonBuilderBase<J extends JsonBuilderBase<?>> implements J
}
public String toJsonWithName() {
- return "{\"" + getName() + "\":" + p.tostring() + "}";
+ return "{\"" + getJsonName() + "\":" + p.tostring() + "}";
}
@SuppressWarnings("unchecked")
@@ -126,4 +126,8 @@ public abstract class JsonBuilderBase<J extends JsonBuilderBase<?>> implements J
p.set(key, val);
return (T)this;
}
+
+ public <T extends JsonBuilder> T as(Class<T> clz) {
+ return p.as(clz);
+ }
}
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 e1c905af..38f32b0e 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
@@ -273,7 +273,6 @@ public class JsonBuilderGenerator extends Generator {
public void generateToJsonMethod(SourceWriter sw, String name, TreeLogger logger) {
sw.println("public final String getJsonName() {return \"" + name + "\";}");
- sw.println("public final String getName() {return \"" + name + "\";}");
}
protected SourceWriter getSourceWriter(TreeLogger logger,
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 d3820772..abef1b8f 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
@@ -16,6 +16,7 @@ import org.json.JSONObject;
import com.google.gwt.query.client.Binder;
import com.google.gwt.query.client.Function;
+import com.google.gwt.query.client.GQ;
import com.google.gwt.query.client.Properties;
import com.google.gwt.query.client.builders.JsonBuilder;
import com.google.gwt.query.client.builders.JsonFactory;
@@ -165,7 +166,10 @@ public class JsonFactoryJre implements JsonFactory {
if ("getFieldNames".equals(mname)) {
return JSONObject.getNames(jsonObject);
- } else if ("getName".equals(mname)) {
+ } else if ("as".equals(mname)) {
+ Class<? extends JsonBuilder> clz = (Class<? extends JsonBuilder>)args[0];
+ return jsonFactory.create(clz, jsonObject);
+ } else if ("getJsonName".equals(mname)) {
return JsonBuilderGenerator.classNameToJsonName(getDataBindingClassName(proxy.getClass()));
} else if (mname.matches("getProperties|getBound")) {
return jsonObject;