Building Mobile Enterprise Applications : webMethods Mobile Development Help : Code Snippets : Chaining Multiple Operations
Chaining Multiple Operations
Let us assume that you need to call an operation GetID to get a particular ID of an object and that you need to call GetDetails afterwards to get more information about this object. In this case, you need to chain GetID and GetDetails, and you have to keep error and result handling in mind. To achieve this goal, it is recommended that you handle one particular result code for an operation with one IOperationDelegate. In our case, you need to introduce three classes which implement IOperationDelegate:
public class ErrorDelegate implements IOperationDelegate {

public void onOperationFailed(final IOperation operation) {
new MessageDialog(AbstractApplicationController.getInstance()).open();
}

public void onOperationFinished(final IOperation operation) {
if (operation.getResultCode() != HttpConnection.HTTP_OK) {
onOperationFailed(operation);
}
}
}

public class GetIDResultDelegate extends ErrorDelegate {

public void onOperationFinished(final IOperation operation) {
super.onOperationFinished(operation);

if (operation.getResultCode() == HttpConnection.HTTP_OK) {
final GetDetails getDetailsOperation = new GetDetails();
getDetailsOperation
.addOperationDelegate(
new GetDetailsResultDelegate());
getDetailsOperation.execute();
}
}
}

public class GetDetailsResultDelegate extends ErrorDelegate {

public void onOperationFinished(final IOperation operation) {
super.onOperationFinished(operation);

if(operation.getResultCode() == HttpConnection.HTTP_OK) {
final String details = operation.getResult();
// do something
}
}
}
Extending from ErrorDelegate allows for implicit error handling. If an operation requires error handling that differs from the standard behavior in ErrorDelegate, it is also possible to use different OperationDelegates.
For complex scenarios, see Getting the Current GPS Position and Translating it into a Human-readable Location and Downloading an Image from a Remote Host.
Copyright © 2007-2017 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback