StatusBuilder statusBuilder = (StatusBuilder) builderFactory.getBuilder(Status.DEFAULT_ELEMENT_NAME);
Status status = statusBuilder.buildObject();
// build a status code object
StatusCodeBuilder statusCodeBuilder = (StatusCodeBuilder) builderFactory.getBuilder(StatusCode.DEFAULT_ELEMENT_NAME);
StatusCode statusCode = statusCodeBuilder.buildObject();
// TODO now discriminates by exception but the code must be improved
if (e instanceof VersionMismatchException) {
statusCode.setValue(StatusCode.VERSION_MISMATCH_URI);
} else if (e instanceof MissingIssuerException || e instanceof WrongFormatIssuerException) {
// set the status code
statusCode.setValue(StatusCode.REQUESTER_URI);
// set status message with some details, when provided
if (e.getMessage() != null) {
StatusMessageBuilder statusMessageBuilder = (StatusMessageBuilder) builderFactory.getBuilder(StatusMessage.DEFAULT_ELEMENT_NAME);
StatusMessage statusMessage = statusMessageBuilder.buildObject();
statusMessage.setMessage(e.getMessage());
// add StatusMessage to Status
status.setStatusMessage(statusMessage);
}
} else {
/* set status code */
statusCode.setValue(StatusCode.RESPONDER_URI);
}
// add StatusCode to Status
status.setStatusCode(statusCode);