final List<String> profiles = domain.getProfiles();
if (profiles.isEmpty()) {
throw new IllegalStateException("Cannot add resources when no profiles were defined.");
}
for (String profile : profiles) {
final CompositeOperationBuilder compositeOperationBuilder = CompositeOperationBuilder.create();
if (addCompositeResource(profile, client, resource, address, compositeOperationBuilder, true)) {
if (resource.hasBeforeAddCommands()) {
resource.getBeforeAdd().execute(client);
}
// Execute the add resource operation
reportFailure(client.execute(compositeOperationBuilder.build()));
if (resource.hasAfterAddCommands()) {
resource.getAfterAdd().execute(client);
}
}
}
} else {
final CompositeOperationBuilder compositeOperationBuilder = CompositeOperationBuilder.create();
if (addCompositeResource(null, client, resource, address, compositeOperationBuilder, true)) {
if (resource.hasBeforeAddCommands()) {
resource.getBeforeAdd().execute(client);
}
// Execute the add resource operation
reportFailure(client.execute(compositeOperationBuilder.build()));
if (resource.hasAfterAddCommands()) {
resource.getAfterAdd().execute(client);
}
}