private Object getMapVal(String key) { if ("".equals(key)) { if (commandData instanceof Map) { addError("value of the command is an object should be primitive"); } return commandData; } if (commandData instanceof Map) { Map metaData = (Map) commandData; return metaData.get(key); } else { String msg = " value has to be an object for operation :" + name; if (!errors.contains(msg)) errors.add(msg); return null; } }
public Map<String, Object> getDataMap() { if (commandData instanceof Map) { //noinspection unchecked return (Map<String, Object>) commandData; } addError(StrUtils.formatString("The command ''{0}'' should have the values as a json object '{'key:val'}' format but is ''{1}''", name, commandData)); return Collections.emptyMap(); }
public void unknownOperation() { addError(formatString("Unknown operation ''{0}'' ", name)); }
public Integer getInt(String name, Integer def) { Object o = getVal(name); if (o == null) return def; if (o instanceof Number) { Number number = (Number) o; return number.intValue(); } else { try { return Integer.parseInt(o.toString()); } catch (NumberFormatException e) { addError(StrUtils.formatString("{0} is not a valid integer", name)); return null; } } }
public Map getMap(String key, Map def) { Object o = getMapVal(key); if (o == null) return def; if (!(o instanceof Map)) { addError(StrUtils.formatString("''{0}'' must be a map", key)); return def; } else { return (Map) o; } }