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 javax.xml.bind.JAXBElement;
20 import javax.xml.bind.JAXBException;
21 import javax.xml.bind.annotation.XmlRootElement;
22 import javax.xml.bind.annotation.XmlType;
23
24 import org.springframework.core.MethodParameter;
25 import org.springframework.ws.context.MessageContext;
26
27
28
29
30
31
32
33
34
35
36 public class XmlRootElementPayloadMethodProcessor extends AbstractJaxb2PayloadMethodProcessor {
37
38 @Override
39 protected boolean supportsRequestPayloadParameter(MethodParameter parameter) {
40 Class<?> parameterType = parameter.getParameterType();
41 return parameterType.isAnnotationPresent(XmlRootElement.class) ||
42 parameterType.isAnnotationPresent(XmlType.class);
43 }
44
45 public Object resolveArgument(MessageContext messageContext, MethodParameter parameter) throws JAXBException {
46 Class<?> parameterType = parameter.getParameterType();
47
48 if (parameterType.isAnnotationPresent(XmlRootElement.class)) {
49 return unmarshalFromRequestPayload(messageContext, parameterType);
50 }
51 else {
52 JAXBElement<?> element = unmarshalElementFromRequestPayload(messageContext, parameterType);
53 return element != null ? element.getValue() : null;
54 }
55 }
56
57 @Override
58 protected boolean supportsResponsePayloadReturnType(MethodParameter returnType) {
59 Class<?> parameterType = returnType.getParameterType();
60 return parameterType.isAnnotationPresent(XmlRootElement.class);
61 }
62
63 public void handleReturnValue(MessageContext messageContext, MethodParameter returnType, Object returnValue)
64 throws JAXBException {
65 Class<?> parameterType = returnType.getParameterType();
66 marshalToResponsePayload(messageContext, parameterType, returnValue);
67 }
68
69
70 }