class XPathParamMethodArgumentResolver implements MethodArgumentResolver {

	@Override
	public Object resolveArgument(MessageContext messageContext, MethodParameter parameter)
			throws TransformerException, XPathExpressionException {
		Class<?> parameterType = parameter.getParameterType();
		QName evaluationReturnType = getReturnType(parameterType);
		boolean useConversionService = false;
		if (evaluationReturnType == null) {
			evaluationReturnType = XPathConstants.STRING;
			useConversionService = true;
		}

		XPath xpath = createXPath();
		xpath.setNamespaceContext(NamespaceUtils.getNamespaceContext(parameter.getMethod()));

		Element rootElement = getRootElement(messageContext.getRequest().getPayloadSource());
		String expression = parameter.getParameterAnnotation(XPathParam.class).value();
		Object result = xpath.evaluate(expression, rootElement, evaluationReturnType);
		return useConversionService ? conversionService.convert(result, parameterType) : result;
	}

}