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

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

Introduction

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

Prototype

public JSONObject isObject() 

Source Link

Document

Returns non-null if this JSONValue is really a JSONObject.

Usage

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

License:Open Source License

public String getProviderUri() {
    JSONValue providerValue = object.get("provider");
    if (providerValue != null) {
        JSONObject providerObject = providerValue.isObject();
        if (providerObject != null) {
            return JSONUtil.asString(providerObject.get("uri"));
        }/*  w  w w  . jav  a  2 s .  co  m*/
    }
    return null;
}

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

License:Open Source License

public String getActionUri(Action action) {
    JSONValue actionsValue = object.get("actions");
    if (actionsValue != null) {
        JSONObject actionsObject = actionsValue.isObject();
        if (actionsObject != null) {
            String actionKey = action.toString().toLowerCase().replace('_', '-');
            return JSONUtil.asString(actionsObject.get(actionKey));
        }//from w  w  w. j  a  v  a2  s. c o  m
    }
    return null;
}

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

License:Open Source License

static public JSONObject parseObject(String data) {
    JSONObject jsonObject = null;//  ww  w  .  j a  va2s.c o m
    try {
        JSONValue jsonValue = JSONParser.parse(data);
        jsonObject = jsonValue.isObject();
    } catch (JSONException e) {
        GWT.log("Tried to parse bad JSON data", e);
        JSONValue jsonValue = JSONParser.parse("{\"error-message\": \"Received bad JSON data.\"}");
        jsonObject = jsonValue.isObject();
    }
    return jsonObject;
}

From source file:edu.umn.msi.tropix.webgui.client.utils.JObject.java

License:Open Source License

public JObject getJObjectOrNull(final String key) {
    final JSONValue value = this.getObject().get(key);
    if (value == null) {
        return null;
    }/*from   ww w  . j a v  a 2  s  .co  m*/
    return new JObjectImpl(value.isObject());
}

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

License:Open Source License

protected User parseUser(JSONObject jsonUser) throws SerializationException {
    final String login = this.json2string(jsonUser.get("login"));
    final String email = this.json2string(jsonUser.get("email"));
    final String fullName = this.json2string(jsonUser.get("full_name"));
    String adminUrl = this.json2string(jsonUser.get("admin_url"), true);
    if (adminUrl == null)
        adminUrl = "";

    final JSONValue roleValue = jsonUser.get("role");
    if (roleValue == null)
        throw new SerializationException("Expected role field in User");
    final JSONObject jsonRole = roleValue.isObject();
    if (jsonRole == null)
        throw new SerializationException("Expected JSON Object as Role, found: " + roleValue);
    final Role role = this.parseRole(jsonRole);

    return new User(login, fullName, email, role, adminUrl);
}

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

License:Open Source License

protected JSONObject parseResultObject(String response) throws SerializationException, WebLabServerException {
    final JSONValue result = this.parseResult(response);
    final JSONObject resultObject = result.isObject();
    if (resultObject == null)
        throw new SerializationException("Expecting an object as a result; found: " + result);
    return resultObject;
}

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 {//from   w ww. ja  v  a 2s  .  com
        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 JSONObject json2object(JSONValue value, boolean supportNull) throws SerializationException {
    final JSONObject jsonobj = value.isObject();
    if (jsonobj == null && !supportNull)
        throw new SerializationException("Object expected, found: " + value);
    return jsonobj;
}

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

License:Open Source License

public void start() {
    final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, this.configurationPath);
    try {//from w  w  w  .j av  a2  s . c  o  m
        builder.sendRequest(null, new RequestCallback() {
            @Override
            public void onError(Request request, Throwable exception) {
                ConfigurationManager.this.callback.onFailure(exception);
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() / 100 == 2 || response.getStatusCode() / 100 == 3) {
                    final JSONValue value;
                    try {
                        value = JSONParser.parseLenient(response.getText());
                    } catch (final Exception e) {
                        ConfigurationManager.this.callback.onFailure(new ConfigurationException(
                                "Error parsing configuration: " + e.getMessage(), e));
                        return;
                    }

                    final JSONObject objValue = value.isObject();
                    if (objValue == null) {
                        ConfigurationManager.this.callback.onFailure(
                                new ConfigurationException("Error parsing configuration: object expected"));
                        return;
                    }

                    for (final String key : objValue.keySet()) {
                        final JSONValue currentValue = objValue.get(key);
                        if (currentValue == null) {
                            ConfigurationManager.this.callback.onFailure(new ConfigurationException(
                                    "Error parsing configuration: empty value for key: " + key));
                            return;
                        }
                        ConfigurationManager.this.configurationMap.put(key, currentValue);
                    }

                    ConfigurationManager.this.callback.onLoaded();
                } else {
                    ConfigurationManager.this.callback
                            .onFailure(new ConfigurationException("Invalid status code: "
                                    + response.getStatusCode() + "; " + response.getStatusText()));
                }
            }
        });
    } catch (final RequestException e1) {
        ConfigurationManager.this.callback
                .onFailure(new ConfigurationException("Exception thrown creating request: " + e1.getMessage()));
    }
}

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

License:Open Source License

@Override
public IConfigurationRetriever[] getExperimentsConfiguration(String experimentType)
        throws InvalidConfigurationValueException {
    final JSONValue value = this.configurationMap.get("experiments");
    if (value == null) // If no experiment is configured, just return an empty array
        return new IConfigurationRetriever[] {};

    final JSONObject objectValue = value.isObject();
    if (objectValue == null)
        throw new InvalidConfigurationValueException(
                "'experiments' field in the configuration file must be an object!!!");

    final JSONValue experimentTypeValue = objectValue.get(experimentType);
    if (experimentTypeValue == null) // If no experiment of that type is configured, just return an empty array
        return new IConfigurationRetriever[] {};

    final JSONArray experimentTypeArray = experimentTypeValue.isArray();
    if (experimentTypeArray == null)
        throw new InvalidConfigurationValueException(
                "Any experiment type in the 'experiments' field of the configuration file must be an array!");

    final IConfigurationRetriever[] resultingConfigurationRetrievers = new IConfigurationRetriever[experimentTypeArray
            .size()];/* w w  w.j av a  2 s  .com*/
    for (int i = 0; i < experimentTypeArray.size(); ++i) {
        final JSONValue currentExperimentConfiguration = experimentTypeArray.get(i);
        final JSONObject currentExperimentConfigurationObject = currentExperimentConfiguration.isObject();
        if (currentExperimentConfigurationObject == null)
            throw new InvalidConfigurationValueException(
                    "Any experiment in the array of experiment types of 'experiments' in the configuration file must be an object!");

        final Map<String, JSONValue> experimentConfiguration = new HashMap<String, JSONValue>();
        for (final String key : currentExperimentConfigurationObject.keySet())
            experimentConfiguration.put(key, currentExperimentConfigurationObject.get(key));

        resultingConfigurationRetrievers[i] = new ConfigurationRetriever(experimentConfiguration, this);
    }

    return resultingConfigurationRetrievers;
}