*/
package com.google.gwt.query.client;
+import com.google.gwt.query.client.builders.JsonBuilder;
+
/**
* Interface using for Data Binders valid for JVM and JS.
/**
* return the name for this type
*/
- String getName();
+ String getJsonName();
+
+
+ <T extends JsonBuilder> T as (Class<T> clz);
}
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 {
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);
}
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;
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;
+ }
}
/**
* return the short name of this class, to use in json structures.
*/
- String getName();
+ String getJsonName();
}
}
public String toJsonWithName() {
- return "{\"" + getName() + "\":" + p.tostring() + "}";
+ return "{\"" + getJsonName() + "\":" + p.tostring() + "}";
}
@SuppressWarnings("unchecked")
p.set(key, val);
return (T)this;
}
+
+ public <T extends JsonBuilder> T as(Class<T> clz) {
+ return p.as(clz);
+ }
}
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,
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;
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;