}
try {
boolean sawFile = false;
JSONObject obj = new JSONObject(str);
obj = obj.getJSONObject("command");
CachedCommandModel cm = new CachedCommandModel(obj.getString("@name"), etag);
cm.dashOk = obj.optBoolean("@unknown-options-are-operands", false);
cm.managedJob = obj.optBoolean("@managed-job", false);
cm.setUsage(obj.optString("usage", null));
Object optns = obj.opt("option");
if (!JSONObject.NULL.equals(optns)) {
JSONArray jsonOptions;
if (optns instanceof JSONArray) {
jsonOptions = (JSONArray) optns;
} else {
jsonOptions = new JSONArray();
jsonOptions.put(optns);
}
for (int i = 0; i < jsonOptions.length(); i++) {
JSONObject jsOpt = jsonOptions.getJSONObject(i);
String type = jsOpt.getString("@type");
ParamModelData opt = new ParamModelData(
jsOpt.getString("@name"),
typeOf(type),
jsOpt.optBoolean("@optional", false),
jsOpt.optString("@default"),
jsOpt.optString("@short"),
jsOpt.optBoolean("@obsolete", false),
jsOpt.optString("@alias"));
opt.param._acceptableValues = jsOpt.optString("@acceptable-values");
if ("PASSWORD".equals(type)) {
opt.param._password = true;
opt.prompt = jsOpt.optString("@prompt");
opt.promptAgain = jsOpt.optString("@prompt-again");
} else if ("FILE".equals(type)) {
sawFile = true;
}
if (jsOpt.optBoolean("@primary", false)) {
opt.param._primary = true;
}
if (jsOpt.optBoolean("@multiple", false)) {
if (opt.type == File.class) {
opt.type = File[].class;
} else {
opt.type = List.class;
}
opt.param._multiple = true;
}
cm.add(opt);
}
}
if (sawFile) {
cm.add(new ParamModelData("upload", Boolean.class,
true, null));
addedUploadOption = true;
cm.setAddedUploadOption(true);
}
this.usage = cm.getUsage();
Metrix.event("parseMetadata() = parse command model - done");
return cm;
} catch (JSONException ex) {
logger.log(Level.FINER, "Can not parse command metadata", ex);
Metrix.event("parseMetadata() = parse command model - done");