}
try {
ParserUtil.parseOperationRequest(typePath, callback);
} catch (CommandFormatException e) {
throw new CommandFormatException("Failed to validate input: " + e.getLocalizedMessage());
}
OperationRequestAddress typeAddress = callback.getAddress();
if(!typeAddress.endsOnType()) {
throw new CommandFormatException("Node path '" + typePath + "' doesn't appear to end on a type.");
}
final String typeName = typeAddress.toParentNode().getType();
for(OperationRequestAddress.Node node : typeAddress) {
address.add(node.getType(), node.getName());
}
request.get(Util.OPERATION).set(Util.READ_CHILDREN_TYPES);
ModelNode result;
try {
result = ctx.getModelControllerClient().execute(request);
} catch (IOException e) {
throw new CommandFormatException("Failed to validate input: " + e.getLocalizedMessage());
}
if(!result.hasDefined(Util.RESULT)) {
throw new CommandFormatException("Failed to validate input: operation response doesn't contain result info.");
}
boolean pathValid = false;
for(ModelNode typeNode : result.get(Util.RESULT).asList()) {
if(typeNode.asString().equals(typeName)) {
pathValid = true;
break;
}
}
if(!pathValid) {
throw new CommandFormatException("Type '" + typeName + "' not found among child types of '" + ctx.getNodePathFormatter().format(typeAddress) + "'");
}
address.add(typeName, "?");
request.get(Util.OPERATION).set(Util.READ_RESOURCE_DESCRIPTION);
try {
result = ctx.getModelControllerClient().execute(request);
} catch (IOException e) {
throw new CommandFormatException(e.getLocalizedMessage());
}
if(!result.hasDefined(Util.RESULT)) {
throw new CommandFormatException("Failed to validate input: operation response doesn't contain result info.");
}
result = result.get(Util.RESULT);
if(!result.hasDefined("attributes")) {
throw new CommandFormatException("Failed to validate input: description of attributes is missing for " + typePath);
}
if(propertyName != null) {
for(Property prop : result.get(Util.ATTRIBUTES).asPropertyList()) {
if(prop.getName().equals(propertyName)) {
ModelNode value = prop.getValue();
if(value.has(Util.ACCESS_TYPE) && Util.READ_ONLY.equals(value.get(Util.ACCESS_TYPE).asString())) {
return;
}
throw new CommandFormatException("Property " + propertyName + " is not read-only.");
}
}
} else {
return;
}
throw new CommandFormatException("Property '" + propertyName + "' wasn't found among the properties of " + typePath);
}