use of iso.std.iso_iec._24727.tech.schema.CancelResponse in project open-ecard by ecsec.
the class IFD method cancel.
@Override
public CancelResponse cancel(Cancel parameters) {
CancelResponse response;
// you thought of a different IFD obviously
if (!ByteUtils.compare(ctxHandle, parameters.getContextHandle())) {
String msg = "Invalid context handle specified.";
Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_CONTEXT_HANDLE, msg);
response = WSHelper.makeResponse(CancelResponse.class, r);
return response;
}
String ifdName = parameters.getIFDName();
String session = parameters.getSessionIdentifier();
if (session != null) {
// async wait
Future<List<IFDStatusType>> f = this.asyncWaitThreads.get(session);
if (f != null) {
f.cancel(true);
response = WSHelper.makeResponse(CancelResponse.class, WSHelper.makeResultOK());
} else {
String msg = "No matching Wait call exists for the given session.";
Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.IO.CANCEL_NOT_POSSIBLE, msg);
response = WSHelper.makeResponse(CancelResponse.class, r);
}
} else if (ifdName != null) {
// sync wait
synchronized (this) {
if (syncWaitThread != null) {
syncWaitThread.cancel(true);
// not really needed but seems cleaner
syncWaitThread = null;
response = WSHelper.makeResponse(CancelResponse.class, WSHelper.makeResultOK());
} else {
String msg = "No synchronous Wait to cancel.";
Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.IO.CANCEL_NOT_POSSIBLE, msg);
response = WSHelper.makeResponse(CancelResponse.class, r);
}
}
} else {
// nothing to cancel
String msg = "Invalid parameters given.";
response = WSHelper.makeResponse(CancelResponse.class, WSHelper.makeResultUnknownError(msg));
}
return response;
}
Aggregations