Class JSObject

java.lang.Object
com.google.gwt.core.client.JavaScriptObject
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 Details

  • Method Details

    • createJSObject

      public static JSObject createJSObject()
    • createJSFunction

      public static JSObject createJSFunction()
    • createJSArray

      public static JSObject createJSArray()
    • setProperty

      public final void setProperty​(java.lang.String name, int value)
    • getPropertyAsInt

      public final int getPropertyAsInt​(java.lang.String name)
    • setProperty

      public final void setProperty​(java.lang.String name, java.lang.String value)
    • getPropertyAsString

      public final java.lang.String getPropertyAsString​(java.lang.String name)
    • setProperty

      public final void setProperty​(java.lang.String name, boolean value)
    • getPropertyAsBoolean

      public final boolean getPropertyAsBoolean​(java.lang.String name)
    • setProperty

      public final void setProperty​(java.lang.String name, float value)
    • getPropertyAsFloat

      public final float getPropertyAsFloat​(java.lang.String name)
    • setProperty

      public final void setProperty​(java.lang.String name, double value)
    • getPropertyAsDouble

      public final double getPropertyAsDouble​(java.lang.String name)
    • setProperty

      public final void setProperty​(java.lang.String name, com.google.gwt.dom.client.Element value)
    • getPropertyAsDomElement

      public final com.google.gwt.dom.client.Element getPropertyAsDomElement​(java.lang.String name)
    • setProperty

      public final void setProperty​(java.lang.String name, JSObject value)
    • getProperty

      public final JSObject getProperty​(java.lang.String name)
    • getPropertyNames

      public final java.lang.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.
    • getPropertyValues

      public final java.lang.String getPropertyValues()
    • hasProperty

      public final boolean hasProperty​(java.lang.String name)
    • unsetProperty

      public final void unsetProperty​(java.lang.String name)
      Unset/Clear the property with the given name. Uses the javascript operator delete
      Parameters:
      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​(java.lang.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[]