Example usage for org.json.simple.parser ParseException ERROR_UNEXPECTED_EXCEPTION

List of usage examples for org.json.simple.parser ParseException ERROR_UNEXPECTED_EXCEPTION

Introduction

In this page you can find the example usage for org.json.simple.parser ParseException ERROR_UNEXPECTED_EXCEPTION.

Prototype

int ERROR_UNEXPECTED_EXCEPTION

To view the source code for org.json.simple.parser ParseException ERROR_UNEXPECTED_EXCEPTION.

Click Source Link

Usage

From source file:org.jitsi.impl.reservation.rest.json.AbstractJsonHandler.java

/**
 * Methods is used to verify if given <tt>oldValue</tt> has not been
 * modified during parsing. It can be used to enforce read-only policy on
 * some fields. Exception will be thrown only if <tt>oldValue</tt> is not
 * <tt>null</tt> nor empty which means that it has been set on edited
 * instance./*from www .  j a v  a  2 s .  com*/
 *
 * @param oldValue old value of the field to be checked. If <tt>null</tt>
 *                 no exception will be thrown which means that value has
 *                 not been assigned yet.
 * @param newValue the new value to be verified if it matches the
 *                 previous one(if old value is not null nor empty).
 * @param key the name of read-only key which will be included in
 *            exception message.
 *
 * @return <tt>true</tt> if read only policy has not been violated.
 *
 * @throws ParseException if <tt>oldValue</tt> is not null nor empty and
 *         <tt>newValue</tt> is not equal to the same as the old one.
 */
protected boolean checkImmutableString(String oldValue, String newValue, String key) throws ParseException {
    if (!StringUtils.isNullOrEmpty(oldValue) && !oldValue.equals(newValue)) {
        throw new ParseException(ParseException.ERROR_UNEXPECTED_EXCEPTION,
                "Attempt to modify immutable " + key + " property: " + oldValue + " -> " + newValue);
    } else {
        return true;
    }
}

From source file:project.cs.netinfutilities.metadata.MetadataParser.java

/**
 * Returns a map that represents the meta-data key value pairs
 * contained in the specified meta-data.
 *
 * @param metadata          The JSON object corresponding to the meta-data.
 * @return                  The map with all meta-data values
 * @throws JSONException    Thrown, if no meta-data could be extracted at all
 *///from   w  w w .j  av a  2s. c om
public static Map<String, Object> toMap(JSONObject metadata) throws ParseException {

    Map<String, Object> map = new LinkedHashMap<String, Object>();

    metadata = (JSONObject) metadata.get("meta");

    if (metadata == null) {
        throw new ParseException(ParseException.ERROR_UNEXPECTED_TOKEN,
                "\"meta\" tag not present in JSON Object");
    }

    // We iterate through the metadata by getting a set of keys from the metadata and
    // we walk through that set.
    @SuppressWarnings("unchecked")
    Set<String> keys = (Set<String>) metadata.keySet();

    Iterator<String> iterator = keys.iterator();

    while (iterator.hasNext()) {
        String key = iterator.next();
        Object value;

        value = metadata.get(key);

        if (value instanceof JSONArray) {
            List<String> list = extractList((JSONArray) value);
            map.put(key, list);
        } else {
            map.put(key, value);
        }
    }

    if (map.size() == 0) {
        throw new ParseException(ParseException.ERROR_UNEXPECTED_EXCEPTION, "No meta-data could be extracted.");
    }

    return map;
}