org.xwiki.gwt.dom.client
Class JavaScriptObject

java.lang.Object
  extended by com.google.gwt.core.client.JavaScriptObject
      extended by org.xwiki.gwt.dom.client.JavaScriptObject
Direct Known Subclasses:
Window

public class JavaScriptObject
extends com.google.gwt.core.client.JavaScriptObject

Extends GWT JavaScriptObject to add a fromJson method. Usage : public class MyCar extends JavaScriptObject { protected MyCar() {} public final native int getWheelNumber() / *-{ return this.wheelnb; }-* /; public final native String getColor() / *-{ return this.color; }-* /; } MyCar redcar = (MyCar) MyCar.fromJson("{ wheelnb: 4, color: 'red' }"); redcar.getWheelNumber(); redcar.getColor();

Version:
$Id$
See Also:
JavaScriptObject

Constructor Summary
protected JavaScriptObject()
          Default constructor.
 
Method Summary
static JavaScriptObject fromJson(String input)
          Create a JavaScriptObject from a JSON string.
 Object get(String key)
          Returns the reference stored in this JavaScript object for the given key.
 com.google.gwt.core.client.JsArrayString getKeys()
          Returns all the keys set in this JavaScript object, to use with get(String) to iterate over all properties, without knowing their names.
 Object remove(String key)
          Removes a property from this JavaScript object.
 Object set(String key, Object ref)
          Saves the given reference in this JavaScript object using the specified key.
 JavaScriptType typeOf(String key)
           
 
Methods inherited from class com.google.gwt.core.client.JavaScriptObject
cast, createArray, createFunction, createObject, equals, hashCode, toSource, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JavaScriptObject

protected JavaScriptObject()
Default constructor. Overlay types always have protected, zero-arguments constructors.

Method Detail

fromJson

public static final JavaScriptObject fromJson(String input)
Create a JavaScriptObject from a JSON string.

Parameters:
input - a valid JSON string.
Returns:
resulting JavaScriptObject

get

public final Object get(String key)
Returns the reference stored in this JavaScript object for the given key.

Parameters:
key - the key whose value to return
Returns:
the value of the specified key

set

public final Object set(String key,
                        Object ref)
Saves the given reference in this JavaScript object using the specified key.

Parameters:
key - the string used for storing and retrieving the reference
ref - the object whose reference will be stored
Returns:
the previous reference associated with the given key

remove

public final Object remove(String key)
Removes a property from this JavaScript object.

Parameters:
key - the name of the property to be removed
Returns:
the value of the removed property

getKeys

public final com.google.gwt.core.client.JsArrayString getKeys()
Returns all the keys set in this JavaScript object, to use with get(String) to iterate over all properties, without knowing their names.

Returns:
the array of keys set in this JavaScript object

typeOf

public final JavaScriptType typeOf(String key)
Parameters:
key - the name of a property of this JavaScript object
Returns:
the type of value assigned to the specified property


Copyright © 2004-2012 XWiki. All Rights Reserved.