org.gwtopenmaps.openlayers.client.util
Class JSObject

java.lang.Object
  extended by com.google.gwt.core.client.JavaScriptObject
      extended by org.gwtopenmaps.openlayers.client.util.JSObject

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

A JSObject is an opaque handle to a JavaScript object. Like it's parent it cannot be created directly. A JSObject has to be created via JSNI or via the static factory method createJSObject. It expands upon it's parent by offering several convenience functions, such as setter and getter methods to set properties on the JSObject. A property can be a number, boolean or string, but also another JSObject or a DOM Element. To set a function on a JSObject, it can be created via JSNI, returned as a JSObject and set as property.

The purpose of the setter and getter methods is to reduce the amount of JSNI code necessary for working with JavaScript objects.

Author:
Erdem Gunay, Edwin Commandeur - Atlis EJS

Constructor Summary
protected JSObject()
           
 
Method Summary
static JSObject createJSArray()
           
static JSObject createJSFunction()
           
static JSObject createJSObject()
           
 JSObject ensureOpaqueArray()
          Checks whether the JSObject is a JavaScript Array by duck typing.
 JSObject getProperty(String name)
           
 JSObject[] getPropertyAsArray(String name)
          Takes a property name of a JSObject that is a javascript array.
 boolean getPropertyAsBoolean(String name)
           
 com.google.gwt.user.client.Element getPropertyAsDomElement(String name)
           
 double getPropertyAsDouble(String name)
           
 float getPropertyAsFloat(String name)
           
 int getPropertyAsInt(String name)
           
 String getPropertyAsString(String name)
           
 String getPropertyNames()
          Let's you inspect the names of properties of a javascript object.
 boolean hasProperty(String name)
           
 void setProperty(String name, boolean value)
           
 void setProperty(String name, double value)
           
 void setProperty(String name, com.google.gwt.user.client.Element value)
           
 void setProperty(String name, float value)
           
 void setProperty(String name, int value)
           
 void setProperty(String name, JSObject value)
           
 void setProperty(String name, String value)
           
 void unsetProperty(String name)
          Unset/Clear the property with the given name.
 
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

JSObject

protected JSObject()
Method Detail

createJSObject

public static JSObject createJSObject()

createJSFunction

public static JSObject createJSFunction()

createJSArray

public static JSObject createJSArray()

setProperty

public final void setProperty(String name,
                              int value)

getPropertyAsInt

public final int getPropertyAsInt(String name)

setProperty

public final void setProperty(String name,
                              String value)

getPropertyAsString

public final String getPropertyAsString(String name)

setProperty

public final void setProperty(String name,
                              boolean value)

getPropertyAsBoolean

public final boolean getPropertyAsBoolean(String name)

setProperty

public final void setProperty(String name,
                              float value)

getPropertyAsFloat

public final float getPropertyAsFloat(String name)

setProperty

public final void setProperty(String name,
                              double value)

getPropertyAsDouble

public final double getPropertyAsDouble(String name)

setProperty

public final void setProperty(String name,
                              com.google.gwt.user.client.Element value)

getPropertyAsDomElement

public final com.google.gwt.user.client.Element getPropertyAsDomElement(String name)

setProperty

public final void setProperty(String name,
                              JSObject value)

getProperty

public final JSObject getProperty(String name)

getPropertyNames

public final String getPropertyNames()
Let's you inspect the names of properties of a javascript object.

Returns:
property names - A String with the names of all the properties of the object, separated by a comma. For example: prop1,prop2,prop3.

hasProperty

public final boolean hasProperty(String name)

unsetProperty

public final void unsetProperty(String name)
Unset/Clear the property with the given name. Uses the javascript operator delete

Parameters:
object - The object in which the property exists
name - The name of the property

ensureOpaqueArray

public final JSObject ensureOpaqueArray()
Checks whether the JSObject is a JavaScript Array by duck typing. If the JSObject is a JavaScript Array it is returned as is, otherwise a JavaScript Array is returned with the JSObject as element.

Returns:
JSObject - A JavaScript Array

getPropertyAsArray

public final JSObject[] getPropertyAsArray(String name)
Takes a property name of a JSObject that is a javascript array. It ensures the object is an array by calling ensureOpaqueArray so you don't have to

Parameters:
name -
Returns:
JSObject[]


Copyright © 2011 sourceforge. All Rights Reserved.