class SoapHeaderElementMethodArgumentResolver implements MethodArgumentResolver {

	@Override
	public Object resolveArgument(MessageContext messageContext, MethodParameter parameter) throws Exception {
		Assert.isInstanceOf(SoapMessage.class, messageContext.getRequest());
		SoapMessage request = (SoapMessage) messageContext.getRequest();
		org.springframework.ws.soap.SoapHeader soapHeader = request.getSoapHeader();

		String paramValue = parameter.getParameterAnnotation(SoapHeader.class).value();

		Assert.isTrue(QNameUtils.validateQName(paramValue),
				"Invalid header qualified name [" + paramValue + "]. " + "QName must be of the form '{namespace}localPart'.");

		QName qname = QName.valueOf(paramValue);

		Class<?> parameterType = parameter.getParameterType();

		if (SoapHeaderElement.class.equals(parameterType)) {
			return extractSoapHeader(qname, soapHeader);
		} else if (List.class.equals(parameterType)) {
			return extractSoapHeaderList(qname, soapHeader);
		}
		// should not happen
		throw new UnsupportedOperationException();
	}

}