* @return whether the child exists or not
* @throws IOException
* @throws MgmtOperationException
*/
public static boolean exists(PathAddress address, ModelControllerClient client) throws IOException, MgmtOperationException {
final PathElement element = address.getLastElement();
final PathAddress subAddress = address.subAddress(0, address.size() -1);
final boolean checkType = element.isWildcard();
final ModelNode e;
final ModelNode operation;
if(checkType) {
e = new ModelNode().set(element.getKey());
operation = createOperation(READ_CHILDREN_TYPES_OPERATION, subAddress);
} else {
e = new ModelNode().set(element.getValue());
operation = createOperation(READ_CHILDREN_NAMES_OPERATION, subAddress);
operation.get(CHILD_TYPE).set(element.getKey());
}
try {
final ModelNode result = executeForResult(operation, client);
return result.asList().contains(e);
} catch (MgmtOperationException ex) {
if(! checkType) {
final String failureDescription = ex.getResult().get(FAILURE_DESCRIPTION).asString();
if(failureDescription.contains("JBAS014793") && failureDescription.contains(element.getKey())) {
return false;
}
}
throw ex;
}