}
@Override
protected void doHandle(CommandContext ctx) throws CommandFormatException {
final ParsedCommandLine parsedCmd = ctx.getParsedCommandLine();
String nodePath = this.nodePath.getValue(parsedCmd);
final OperationRequestAddress address;
if (nodePath != null) {
address = new DefaultOperationRequestAddress(ctx.getPrefix());
CommandLineParser.CallbackHandler handler = new DefaultCallbackHandler(address);
// this is for correct parsing of escaped characters
nodePath = ctx.getArgumentsString();
if(l.isPresent(parsedCmd)) {
nodePath = nodePath.trim();
if(nodePath.startsWith("-l ")) {
nodePath = nodePath.substring(3);
} else {
nodePath = nodePath.substring(0, nodePath.length() - 3);
}
}
try {
ctx.getCommandLineParser().parse(nodePath, handler);
} catch (CommandFormatException e) {
ctx.printLine(e.getLocalizedMessage());
}
} else {
address = new DefaultOperationRequestAddress(ctx.getPrefix());
}
List<String> names = null;
if(address.endsOnType()) {
final String type = address.getNodeType();
address.toParentNode();
names = Util.getNodeNames(ctx.getModelControllerClient(), address, type);
} else {
final ModelNode composite = new ModelNode();
composite.get(Util.OPERATION).set(Util.COMPOSITE);
composite.get(Util.ADDRESS).setEmptyList();
final ModelNode steps = composite.get(Util.STEPS);
{
final ModelNode typesRequest = new ModelNode();
typesRequest.get(Util.OPERATION).set(Util.READ_CHILDREN_TYPES);
final ModelNode addressNode = typesRequest.get(Util.ADDRESS);
if (address.isEmpty()) {
addressNode.setEmptyList();
} else {
Iterator<Node> iterator = address.iterator();
while (iterator.hasNext()) {
OperationRequestAddress.Node node = iterator.next();
if (node.getName() != null) {
addressNode.add(node.getType(), node.getName());
} else if (iterator.hasNext()) {
throw new OperationFormatException("Expected a node name for type '" + node.getType()
+ "' in path '" + ctx.getPrefixFormatter().format(address) + "'");
}
}
}
steps.add(typesRequest);
}
{
final ModelNode resourceRequest = new ModelNode();
resourceRequest.get(Util.OPERATION).set(Util.READ_RESOURCE);
final ModelNode addressNode = resourceRequest.get(Util.ADDRESS);
if (address.isEmpty()) {
addressNode.setEmptyList();
} else {
Iterator<Node> iterator = address.iterator();
while (iterator.hasNext()) {
OperationRequestAddress.Node node = iterator.next();
if (node.getName() != null) {
addressNode.add(node.getType(), node.getName());
} else if (iterator.hasNext()) {
throw new OperationFormatException("Expected a node name for type '" + node.getType()
+ "' in path '" + ctx.getPrefixFormatter().format(address) + "'");
}
}
}
resourceRequest.get(Util.INCLUDE_RUNTIME).set(Util.TRUE);
steps.add(resourceRequest);
}
final String[] additionalProps;
if(l.isPresent(parsedCmd)) {
steps.add(Util.buildRequest(ctx, address, Util.READ_RESOURCE_DESCRIPTION));
final Set<String> argNames = parsedCmd.getPropertyNames();
if(argNames.size() > 1) {
additionalProps = new String[argNames.size() - 1];
int i = 0;
for(String arg : argNames) {
if(arg.equals(l.getFullName())) {