if(result.hasDefined(Util.STEP_1)) {
final ModelNode stepOutcome = result.get(Util.STEP_1);
if(Util.isSuccess(stepOutcome)) {
if(stepOutcome.hasDefined(Util.RESULT)) {
final ModelNode valueResult = stepOutcome.get(Util.RESULT);
final ModelNodeFormatter formatter = ModelNodeFormatter.Factory.forType(valueResult.getType());
formatter.format(valueBuf, 0, valueResult);
} else {
valueBuf.append("n/a");
}
table.addLine(new String[]{"value", valueBuf.toString()});
} else {
throw new CommandFormatException("Failed to get resource description: " + response);
}
}
if(result.hasDefined(Util.STEP_2)) {
final ModelNode stepOutcome = result.get(Util.STEP_2);
if(Util.isSuccess(stepOutcome)) {
if(stepOutcome.hasDefined(Util.RESULT)) {
final ModelNode descrResult = stepOutcome.get(Util.RESULT);
if(descrResult.hasDefined(Util.ATTRIBUTES)) {
ModelNode attributes = descrResult.get(Util.ATTRIBUTES);
final String name = this.name.getValue(ctx.getParsedCommandLine());
if(name == null) {
throw new CommandFormatException("Attribute name is not available in handleResponse.");
} else if(attributes.hasDefined(name)) {
final ModelNode descr = attributes.get(name);
for(String prop : descr.keys()) {
table.addLine(new String[]{prop, descr.get(prop).asString()});
}
} else {
throw new CommandFormatException("Attribute description is not available.");
}
} else {
throw new CommandFormatException("The resource doesn't provide attribute descriptions.");
}
} else {
throw new CommandFormatException("Result is not available for read-resource-description request: " + response);
}
} else {
throw new CommandFormatException("Failed to get resource description: " + response);
}
}
ctx.printLine(table.toString(true));
} else {
final ModelNodeFormatter formatter = ModelNodeFormatter.Factory.forType(result.getType());
final StringBuilder buf = new StringBuilder();
formatter.format(buf, 0, result);
ctx.printLine(buf.toString());
}
}