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.getCurrentNodePath());
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);
}
}
ctx.getCommandLineParser().parse(nodePath, handler);
} else {
address = new DefaultOperationRequestAddress(ctx.getCurrentNodePath());
}
List<String> names = null;
if(address.endsOnType()) {
final String type = address.getNodeType();
address.toParentNode();
names = Util.getNodeNames(ctx.getModelControllerClient(), address, type);
printList(ctx, names, l.isPresent(parsedCmd));
return;
}
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.getNodePathFormatter().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()) {