}
@SuppressWarnings("unchecked")
protected void handleUriMethodReturnValue(HandlerMethods handlerMethods, final AnnotationWebScriptRequest request,
final AnnotationWebscriptResponse response, final Object returnValue) throws Exception {
Resolution resolution = null;
if (returnValue instanceof Map) {
resolution = new TemplateResolution((Map<String, Object>) returnValue);
} else if (returnValue instanceof String) {
resolution = new TemplateResolution((String)returnValue);
} else if (returnValue instanceof Resolution) {
resolution = (Resolution) returnValue;
}
if (this.handlerMethods.useResponseTemplate()) {
final String responseTemplateName = handlerMethods.getResponseTemplateName();
if (responseTemplateName != null) {
if (resolution instanceof TemplateResolution) {
if (((TemplateResolution) resolution).getTemplate() == null) {
((TemplateResolution) resolution).setTemplate(responseTemplateName);
}
} else if (resolution == null) {
resolution = new TemplateResolution(responseTemplateName);
}
}
}
if (resolution != null) {
if (resolution instanceof TemplateResolution) {
final TemplateResolution templateResolution = (TemplateResolution)resolution;
final Map<String, Object> model = request.getModel();
if (templateResolution.getModel() != null && templateResolution.getModel() != model) {
model.putAll(templateResolution.getModel());
}
templateResolution.setModel(model);
}
resolution.resolve(request, response,
new DefaultResolutionParameters(handlerMethods.getUriMethod(), description, handler)
);
}
}