aboutsummaryrefslogtreecommitdiffstats
path: root/gwtquery-core
diff options
context:
space:
mode:
authorManolo Carrasco <manolo@apache.org>2011-10-19 06:34:54 +0000
committerManolo Carrasco <manolo@apache.org>2011-10-19 06:34:54 +0000
commit96f7ece62367185a8b53cb16ce2e5c1155927eed (patch)
treedefa986a508f2b030ebcbb5e15d719060c5428c9 /gwtquery-core
parent173cb815cf5fee6af492c15b059dbade7f10827f (diff)
downloadgwtquery-96f7ece62367185a8b53cb16ce2e5c1155927eed.tar.gz
gwtquery-96f7ece62367185a8b53cb16ce2e5c1155927eed.zip
setters in xml builders was not implemented
Diffstat (limited to 'gwtquery-core')
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilder.java12
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilderBase.java84
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java5
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/rebind/XmlBuilderGenerator.java11
-rw-r--r--gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTest.java12
5 files changed, 80 insertions, 44 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilder.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilder.java
index bf3153ed..781341f5 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilder.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilder.java
@@ -34,5 +34,15 @@ public interface XmlBuilder {
/**
* Returns the documentElement.
*/
- Element getDocumentElement();
+ Element getRootElement();
+
+ /**
+ * Appends a node
+ */
+ void append(XmlBuilder x);
+
+ /**
+ * Appends xml content
+ */
+ void append(String x);
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilderBase.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilderBase.java
index 0c7fe017..0b2ba4c2 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilderBase.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilderBase.java
@@ -28,35 +28,18 @@ public abstract class XmlBuilderBase<J extends XmlBuilderBase<?>> implements Xml
//TODO empty document
protected GQuery g = $(JsUtils.parseXML("<root/>"));
- @SuppressWarnings("unchecked")
- public J parse(String xml) {
- return load(JsUtils.parseXML(xml));
+ public void append(String xml) {
+ g.append(JsUtils.parseXML(xml));
}
- @SuppressWarnings("unchecked")
- public J load(Object o) {
- assert o == null || o instanceof JavaScriptObject && JsUtils.isElement((JavaScriptObject)o) || o instanceof String;
- if (o != null && o instanceof String) {
- return parse((String)o);
- }
- if (o != null) {
- g=$((Element)o);
- }
- return (J)this;
+ public void append(XmlBuilder x) {
+ g.append(x.getRootElement());
}
- public String getText() {
- return g.text();
+ protected Boolean getBooleanBase(String n) {
+ return "true".equalsIgnoreCase(getStrBase(n));
}
- public void setText(String s) {
- g.text(s);
- }
-
- public String toString() {
- return g.toString();
- }
-
protected Element getElementBase(String n) {
return g.children(n).get(0);
}
@@ -65,25 +48,62 @@ public abstract class XmlBuilderBase<J extends XmlBuilderBase<?>> implements Xml
return g.children(n).elements();
}
- public Element getDocumentElement() {
- return g.get(0);
- }
-
protected float getFloatBase(String s) {
String n = getStrBase(s).replaceAll("[^\\d\\-\\.]", "");
return n.isEmpty() ? 0 : Float.parseFloat(n);
}
- protected Boolean getBooleanBase(String n) {
- return "true".equalsIgnoreCase(getStrBase(n));
+ protected Properties getPropertiesBase(String n) {
+ // TODO:
+ return null;
+ }
+
+ public Element getRootElement() {
+ return g.get(0);
}
protected String getStrBase(String n) {
return g.attr(n);
}
- protected Properties getPropertiesBase(String n) {
- // TODO:
- return null;
+ public String getText() {
+ return g.text();
+ }
+
+ @SuppressWarnings("unchecked")
+ public J load(Object o) {
+ assert o == null || o instanceof JavaScriptObject && JsUtils.isElement((JavaScriptObject)o) || o instanceof String;
+ if (o != null && o instanceof String) {
+ return parse((String)o);
+ }
+ if (o != null) {
+ g=$((Element)o);
+ }
+ return (J)this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public J parse(String xml) {
+ return load(JsUtils.parseXML(xml));
+ }
+
+ protected <T> void setArrayBase(String n, T[] r) {
+ String v = "";
+ for (T t: r) {
+ v += String.valueOf(t);
+ }
+ setBase(n, v);
+ }
+
+ protected void setBase(String n, Object v) {
+ g.attr(n, v);
+ }
+
+ public void setText(String s) {
+ g.text(s);
+ }
+
+ public String toString() {
+ return g.toString();
}
}
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 76d5a76c..5b69a292 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
@@ -26,7 +26,6 @@ import com.google.gwt.core.ext.typeinfo.JArrayType;
import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.core.ext.typeinfo.JMethod;
import com.google.gwt.core.ext.typeinfo.JParameter;
-import com.google.gwt.core.ext.typeinfo.JPrimitiveType;
import com.google.gwt.core.ext.typeinfo.JType;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
import com.google.gwt.query.client.Properties;
@@ -115,20 +114,18 @@ public class JsonBuilderGenerator extends Generator {
sw.println("return getArrayBase(\"" + name + "\", new " + t + "[l], "
+ t + ".class);");
} else {
- sw.println("return p.get(\"" + name + "\");");
+ sw.println("return null; // Unsupported return type: " + retType);
}
sw.outdent();
sw.println("}");
} else if (params.length == 1) {
JType type = params[0].getType();
JArrayType arr = type.isArray();
- JPrimitiveType pri = type.isPrimitive();
sw.print("(" + type.getParameterizedQualifiedSourceName() + " a)");
sw.println("{");
sw.indent();
if (arr != null) {
sw.println("setArrayBase(\"" + name + "\", a);");
- } else if (pri != null) {
} else {
sw.println("p.set(\"" + name + "\", a);");
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/XmlBuilderGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/XmlBuilderGenerator.java
index b0218d7f..831ec96b 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/XmlBuilderGenerator.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/XmlBuilderGenerator.java
@@ -111,23 +111,22 @@ public class XmlBuilderGenerator extends Generator {
sw.println(" l.add(c);");
sw.println("}");
sw.println("return l.toArray(new " + q + "[0]);");
-// } else {
-// sw.println("return p.get(\"" + name + "\");");
+ } else {
+ sw.println("return null; // Unsupported return type: " + retType);
}
sw.outdent();
sw.println("}");
} else if (params.length == 1) {
JType type = params[0].getType();
JArrayType arr = type.isArray();
- JPrimitiveType pri = type.isPrimitive();
- sw.print("(" + type.getParameterizedQualifiedSourceName() + " a)");
+ String qname = type.getParameterizedQualifiedSourceName();
+ sw.print("(" + qname + " a)");
sw.println("{");
sw.indent();
if (arr != null) {
sw.println("setArrayBase(\"" + name + "\", a);");
- } else if (pri != null) {
} else {
- sw.println("p.set(\"" + name + "\", a);");
+ sw.println("setBase(\"" + name + "\", a);");
}
if (!"void".equals(retType)){
if (isTypeAssignableTo(method.getReturnType(), method.getEnclosingType())) {
diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTest.java
index 841015b4..7056a9a3 100644
--- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTest.java
+++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTest.java
@@ -59,6 +59,7 @@ public class GQueryAjaxTest extends GWTTestCase {
String[] getT();
JsonExample setT(String[] strings);
JsonExample setZ(Boolean b);
+ JsonExample setD(long l);
}
public void testJsonBuilder() {
@@ -75,10 +76,12 @@ public class GQueryAjaxTest extends GWTTestCase {
assertEquals("adios", c.getT()[1]);
assertEquals("url", c.getUrl());
c.setT(new String[]{"foo", "bar"})
- .setZ(false);
+ .setZ(false).setD(1234);
assertFalse(c.getZ());
assertEquals("foo", c.getT()[0]);
assertEquals("bar", c.getT()[1]);
+ assertEquals(1234l, c.getD());
+
}
interface XmlExample extends XmlBuilder {
@@ -90,6 +93,10 @@ public class GQueryAjaxTest extends GWTTestCase {
XmlExample[] getX();
@Name("x")
XmlExample getFirstX();
+
+ XmlExample setA(String s);
+ @Name("c")
+ XmlExample setNumber(int i);
}
public void testXmlBuilder() {
@@ -101,5 +108,8 @@ public class GQueryAjaxTest extends GWTTestCase {
assertEquals(-1, x.getNumber());
assertEquals("xa2", x.getX()[1].getA());
assertEquals("xa1", x.getFirstX().getA());
+ x.setA("X").setNumber(1234);
+ assertEquals("X", x.getA());
+ assertEquals(1234, x.getNumber());
}
}