From: Joonas Lehtinen Date: Wed, 6 Jun 2007 09:18:43 +0000 (+0000) Subject: drafting implementation X-Git-Tag: 6.7.0.beta1~6328 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d0c3d7f4290936083e5ff5eb68fe66fd7e813d29;p=vaadin-framework.git drafting implementation svn changeset:1617/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/UIDL.java b/src/com/itmill/toolkit/terminal/gwt/client/UIDL.java index 1b391a93c8..54a6eeda08 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/UIDL.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/UIDL.java @@ -4,40 +4,55 @@ import java.util.Iterator; import java.util.Set; import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONBoolean; +import com.google.gwt.json.client.JSONNumber; import com.google.gwt.json.client.JSONObject; import com.google.gwt.json.client.JSONString; +import com.google.gwt.json.client.JSONValue; public class UIDL { - JSONObject json; + JSONArray json; - public UIDL(JSONObject json) { + public UIDL(JSONArray json) { this.json = json; } - public int getId() { - String id = getAttribute("id"); - if (id==null) return -1; - return Integer.parseInt(id); + public String getId() { + return getStringAttribute("id"); } public String getTag() { - Set keys = json.keySet(); - return "" + keys.iterator().next(); + return json.get(0).toString(); } - public String getAttribute(String name) { - JSONObject attrs = (JSONObject) json.get("a"); - if (attrs == null) return null; - return ""+ attrs.get(name); + public String getStringAttribute(String name) { + JSONValue val = ((JSONObject)json.get(1)).get(name); + return ((JSONString)val).stringValue(); + } + + public int getIntAttribute(String name) { + JSONValue val = ((JSONObject)json.get(1)).get(name); + double num = ((JSONNumber)val).getValue(); + return (int) num; + } + + public long getLongAttribute(String name) { + JSONValue val = ((JSONObject)json.get(1)).get(name); + double num = ((JSONNumber)val).getValue(); + return (long) num; + } + + public boolean getBooleanAttribute(String name) { + JSONValue val = ((JSONObject)json.get(1)).get(name); + return ((JSONBoolean)val).booleanValue(); } public Iterator getChildIterator() { return new Iterator() { - JSONArray children = (JSONArray) ((JSONObject)json.get(getTag())).get("c"); - int index=0; + int index=2; public void remove() { throw new UnsupportedOperationException(); @@ -45,13 +60,18 @@ public class UIDL { public Object next() { - if (children != null) - return new UIDL((JSONObject)children.get(index++)); + if (json.size() > index) { + JSONValue c = json.get(index++); + if (c.isString() != null) return c.isString().stringValue(); + else if (c.isArray() != null) return new UIDL(c.isArray()); + else if (c.isObject() != null) return new XML(c.isObject()); + else throw new IllegalStateException("Illegal child of type "+c.getClass().toString()+" in tag " + getTag() + " at index " + index); + } return null; } public boolean hasNext() { - return children != null && children.size() > index; + return json.size() > index; } }; @@ -65,7 +85,7 @@ public class UIDL { Iterator i = getChildIterator(); while (i.hasNext()) { - UIDL c = (UIDL) i.next(); + Object c = i.next(); s += c.toString(); } @@ -73,4 +93,15 @@ public class UIDL { return s; } + + public class XML { + JSONObject x; + private XML(JSONObject x) { + this.x = x; + } + + public String getXMLAsString() { + return x.get("x").toString(); + } + } }