}
public void onSaveResource(final String addressString, final String name, Map<String, Object> changedValues,
final Callback... callback) {
final ResourceAddress address = new ResourceAddress(addressString, statementContext);
final ModelNodeAdapter adapter = new ModelNodeAdapter();
// name can be omitted
ModelNode operation = name!=null ?
adapter.fromChangeset(changedValues, address.asFqAddress(name)) :
adapter.fromChangeset(changedValues, address);
dispatcher.execute(new DMRAction(operation), new AsyncCallback<DMRResponse>() {
@Override
public void onFailure(Throwable caught) {
for (Callback cb : callback) {
cb.onFailure(address, name, caught);
}
}
@Override
public void onSuccess(DMRResponse dmrResponse) {
ModelNode response = dmrResponse.get();
if (response.isFailure()) {
Console.error("Failed to save " + address.toString(), response.getFailureDescription());
for (Callback cb : callback) {
cb.onFailure(address, name, new RuntimeException("Failed to add resource " + name +":"+ response.getFailureDescription()));
}
}
else {
Console.info("Successfully saved " + address.toString());
for (Callback cb : callback) {
cb.onSuccess(address, name);
}
}
}