Example usage for com.google.gwt.json.client JSONValue isBoolean

List of usage examples for com.google.gwt.json.client JSONValue isBoolean

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONValue isBoolean.

Prototype

public JSONBoolean isBoolean() 

Source Link

Document

Returns a non-null reference if this JSONValue is really a JSONBoolean.

Usage

From source file:com.qualogy.qafe.gwt.client.util.JSNIUtil.java

License:Apache License

/**
 * Convert JavaScript objects to their Java representations.
 *//*from w  ww .j av a2s . c  o m*/
static Object resolveJavaValue(JSONValue jsonValue) {
    if (jsonValue == null) {
        return null;
    }
    Object value = null;
    if (jsonValue.isArray() != null) {
        value = resolveJavaList(jsonValue.isArray());
    } else if (jsonValue.isObject() != null) {
        value = resolveJavaMap(jsonValue.isObject());
    } else if (jsonValue.isBoolean() != null) {
        value = jsonValue.isBoolean().booleanValue();
    } else if (jsonValue.isNumber() != null) {
        value = jsonValue.isNumber().doubleValue();
    } else if (jsonValue.isString() != null) {
        value = jsonValue.isString().stringValue();
    }
    return value;
}

From source file:edu.nrao.dss.client.widget.explorers.Explorer.java

License:Open Source License

protected void addRecord(HashMap<String, Object> fields) {
    JSONRequest.post(rootURL, fields, new JSONCallbackAdapter() {
        @Override//from   w  ww  . j  av  a 2  s  .com
        public void onSuccess(JSONObject json) {
            BaseModelData model = new BaseModelData();
            for (int i = 0; i < modelType.getFieldCount(); ++i) {
                DataField field = modelType.getField(i);
                String fName = field.getName();
                if (json.containsKey(fName)) {
                    // Set model value dependent on data type
                    JSONValue value = json.get(fName);
                    if (value.isNumber() != null) {
                        double numValue = value.isNumber().doubleValue();
                        // Note: we're treating even integer values like doubles here.  Doesn't appear
                        // to be an issue.  1.0 is displayed as 1 anyways.
                        model.set(fName, numValue);
                    } else if (value.isBoolean() != null) {
                        model.set(fName, value.isBoolean().booleanValue());
                    } else if (value.isString() != null) {
                        model.set(fName, value.isString().stringValue());
                    } else if (value.isNull() != null) {
                        // not raising an error seems to be fine.
                    } else {
                        Window.alert("unknown JSON value type");
                    }
                }
            }
            grid.stopEditing();
            store.insert(model, 0);
            //grid.getView().refresh(true);
            grid.getSelectionModel().select(model, false);
        }
    });
}

From source file:edu.ucsb.eucalyptus.admin.client.extensions.store.JSONUtil.java

License:Open Source License

static boolean asBoolean(JSONValue value, boolean defaultResult) {
    if (value != null) {
        JSONBoolean bool = value.isBoolean();
        if (bool != null) {
            return bool.booleanValue();
        }/*from w  ww. j a v a 2s  .  c o m*/
    }
    return defaultResult;
}

From source file:es.deusto.weblab.client.comm.CommonSerializerJSON.java

License:Open Source License

private JSONValue parseResult(String response) throws SerializationException, WebLabServerException {
    final JSONValue value;
    try {/* w  w  w .  j  a  v  a2  s  . co m*/
        value = JSONParser.parseStrict(response);
    } catch (final IllegalArgumentException e) {
        throw new SerializationException("Invalid response: " + e.getMessage(), e);
    } catch (final JSONException e) {
        throw new SerializationException("Invalid response: " + e.getMessage(), e);
    }
    final JSONObject responseObject = value.isObject();
    if (responseObject == null)
        throw new SerializationException("Expecting an object as a response; found: " + response);

    final JSONValue isException = responseObject.get("is_exception");
    final JSONBoolean isExceptionB = isException.isBoolean();
    if (isExceptionB.booleanValue())
        this.throwException(responseObject);

    final JSONValue result = responseObject.get("result");
    if (result == null)
        throw new SerializationException("Expecting 'result'; not found");
    return result;
}

From source file:es.deusto.weblab.client.comm.CommonSerializerJSON.java

License:Open Source License

protected boolean json2boolean(JSONValue value) throws SerializationException {
    if (value == null)
        throw new SerializationException("Boolean expected, found null");
    final JSONBoolean jsonstring = value.isBoolean();
    if (jsonstring == null)
        throw new SerializationException("Boolean expected, found: " + value);
    return jsonstring.booleanValue();
}

From source file:es.deusto.weblab.client.comm.CommonSerializerJSON.java

License:Open Source License

@SuppressWarnings("unused")
private boolean json2bool(JSONValue value) throws SerializationException {
    if (value == null)
        throw new SerializationException("Boolean expected, found null");
    final JSONBoolean jsonboolean = value.isBoolean();
    if (jsonboolean == null)
        throw new SerializationException("Boolean expected, found: " + value);
    return jsonboolean.booleanValue();
}

From source file:es.deusto.weblab.client.configuration.ConfigurationRetriever.java

License:Open Source License

/**
 * Retrieves a boolean property. Will throw a not found exception if the 
 * property is not located.//from www.j  a  va 2  s  . c  om
 * 
 * @param key String which uniquely identifies the boolean property
 */
@Override
public boolean getBoolProperty(String key)
        throws ConfigurationKeyNotFoundException, InvalidConfigurationValueException {
    final JSONValue value = this.getJSONProperty(key);
    if (value == null)
        throw new ConfigurationKeyNotFoundException("Configuration key: " + key + " not found");

    final JSONBoolean booleanValue = value.isBoolean();
    if (booleanValue == null)
        throw new InvalidConfigurationValueException("Invalid boolean format for key " + key);

    return booleanValue.booleanValue();
}

From source file:es.deusto.weblab.client.configuration.ConfigurationRetriever.java

License:Open Source License

/**
 * Retrieves a boolean property. If the property is not found,
 * a default value will be returned./*from w ww  .j  a  va 2  s.  c om*/
 * 
 * @param key String that uniquely identifies the property.
 * @param def Value to be returned if a boolean with the specified key is not found.
 * @return The value for the key if found, the default value otherwise.
 */
@Override
public boolean getBoolProperty(String key, boolean def) {
    final JSONValue value = this.configurationMap.get(key);
    if (value == null)
        return def;

    final JSONBoolean booleanValue = value.isBoolean();
    if (booleanValue == null)
        return def;

    return booleanValue.booleanValue();
}

From source file:es.deusto.weblab.client.experiments.visir.VisirSetupData.java

License:Open Source License

/**
 * Parses the string, storing the received parameters for them
 * to be retrieved through various getters.
 * @param response Response that was received
 * @return true if the response was successfully parsed, false otherwise
 */// w w  w .  ja  v a 2s  .c  o  m
public boolean parseData(String response) {

    try {

        final JSONValue val = JSONParser.parseStrict(response);
        final JSONObject obj = val.isObject();
        if (obj == null)
            return false;

        final JSONValue cookieval = obj.get("cookie");
        final JSONValue savedataval = obj.get("savedata");
        final JSONValue urlval = obj.get("url");
        final JSONValue teacherval = obj.get("teacher");

        final JSONValue circuitsList = obj.get("circuits");

        if (cookieval == null || savedataval == null || urlval == null)
            return false;

        final JSONString cookiestr = cookieval.isString();
        final JSONString savedatastr = savedataval.isString();
        final JSONString urlstr = urlval.isString();

        if (cookiestr == null || savedatastr == null || urlstr == null)
            return false;

        this.cookie = cookiestr.stringValue();
        this.saveData = savedatastr.stringValue();
        this.url = urlstr.stringValue();

        if (teacherval != null) {
            JSONBoolean teacherbool = teacherval.isBoolean();
            this.teacher = teacherbool != null && teacherbool.booleanValue();
        } else
            this.teacher = false;

        // We will now parse the list of available circuits. This is a list containing
        // the names of available circuits. Their actual data is not included and needs to 
        // be requested separatedly.
        this.circuitsAvailable = new ArrayList<String>();
        if (circuitsList == null) {
        } else {
            JSONArray circuitsAvailableArray = circuitsList.isArray();

            for (int i = 0; i < circuitsAvailableArray.size(); ++i) {
                final JSONValue circuitName = circuitsAvailableArray.get(i);
                final String circuitNameStr = circuitName.isString().stringValue();
                this.circuitsAvailable.add(circuitNameStr);
            }
        }

    } catch (Throwable e) {
        return false;
    }

    return true;
}

From source file:fast.servicescreen.client.gui.RuleUtil.java

License:Open Source License

/**
 * Recursive method for retrieving all jsonvalues for a specified tagName
 * *//*w w  w  .  j  a v  a2 s.  c  om*/
public static void jsonValuesByTagName(JSONArray elements, JSONValue root, String tagName) {
    //if object search on first layer. on failure begin depth-search
    JSONObject object = root.isObject();
    if (object != null) {
        //get (first layer) keys contained in the JSONValue
        Set<String> keys = object.keySet();

        //seek on first layer
        for (Iterator<String> iterator = keys.iterator(); iterator.hasNext();) {
            String key = (String) iterator.next();

            //found - add it and stop
            if (key.equals(tagName)) {
                int index = elements.size();
                elements.set(index, object.get(key));
                //stop - key can occur only once on first layer
                break;
            }
            //nothing found - depth-search
            else {
                jsonValuesByTagName(elements, object.get(key), tagName);
            }
        }
    }

    //if it's an array, search among it's children by calling recursive method
    //for every child
    JSONArray jsonArray = root.isArray();
    if (jsonArray != null) {
        for (int i = 0; i < jsonArray.size(); i++) {
            jsonValuesByTagName(elements, jsonArray.get(i), tagName);
        }
    }

    //if it's a matching boolean, number or string: add it
    JSONBoolean jsonBoolean = root.isBoolean();
    if (jsonBoolean != null && tagName.equals(jsonBoolean.booleanValue())) {
        int index = elements.size();
        elements.set(index, jsonBoolean);
    }
    JSONNumber jsonNumber = root.isNumber();
    if (jsonNumber != null && tagName.equals(jsonNumber.doubleValue())) {
        int index = elements.size();
        elements.set(index, jsonNumber);
    }
    JSONString jsonString = root.isString();
    if (jsonString != null && tagName.equals(jsonString.stringValue())) {
        int index = elements.size();
        elements.set(index, jsonString);
    }
}