1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.server.endpoint.adapter.method.jaxb;
18
19 import java.lang.reflect.ParameterizedType;
20 import java.lang.reflect.Type;
21 import javax.xml.bind.JAXBElement;
22 import javax.xml.bind.JAXBException;
23
24 import org.springframework.core.MethodParameter;
25 import org.springframework.ws.context.MessageContext;
26
27
28
29
30
31
32
33
34
35 public class JaxbElementPayloadMethodProcessor extends AbstractJaxb2PayloadMethodProcessor {
36
37 @Override
38 protected boolean supportsRequestPayloadParameter(MethodParameter parameter) {
39 Class<?> parameterType = parameter.getParameterType();
40 Type genericType = parameter.getGenericParameterType();
41 return JAXBElement.class.equals(parameterType) && genericType instanceof ParameterizedType;
42 }
43
44 public JAXBElement<?> resolveArgument(MessageContext messageContext, MethodParameter parameter)
45 throws JAXBException {
46 ParameterizedType parameterizedType = (ParameterizedType) parameter.getGenericParameterType();
47 Class<?> clazz = (Class) parameterizedType.getActualTypeArguments()[0];
48 return unmarshalElementFromRequestPayload(messageContext, clazz);
49 }
50
51 @Override
52 protected boolean supportsResponsePayloadReturnType(MethodParameter returnType) {
53 Class<?> parameterType = returnType.getParameterType();
54 return JAXBElement.class.isAssignableFrom(parameterType);
55 }
56
57 public void handleReturnValue(MessageContext messageContext, MethodParameter returnType, Object returnValue)
58 throws JAXBException {
59 JAXBElement<?> element = (JAXBElement<?>) returnValue;
60 marshalToResponsePayload(messageContext, element.getDeclaredType(), element);
61 }
62 }