1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.server.endpoint.mapping;
18
19 import java.lang.reflect.Method;
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.springframework.aop.support.AopUtils;
24 import org.springframework.beans.BeansException;
25 import org.springframework.context.ApplicationContextException;
26 import org.springframework.core.JdkVersion;
27 import org.springframework.util.Assert;
28 import org.springframework.util.StringUtils;
29 import org.springframework.ws.context.MessageContext;
30 import org.springframework.ws.server.endpoint.MethodEndpoint;
31
32
33
34
35
36
37
38
39
40
41
42 public abstract class AbstractMethodEndpointMapping extends AbstractEndpointMapping {
43
44
45 private final Map endpointMap = new HashMap();
46
47
48
49
50
51
52
53
54 protected Object getEndpointInternal(MessageContext messageContext) throws Exception {
55 String key = getLookupKeyForMessage(messageContext);
56 if (!StringUtils.hasLength(key)) {
57 return null;
58 }
59 if (logger.isDebugEnabled()) {
60 logger.debug("Looking up endpoint for [" + key + "]");
61 }
62 return lookupEndpoint(key);
63 }
64
65
66
67
68
69
70 protected abstract String getLookupKeyForMessage(MessageContext messageContext) throws Exception;
71
72
73
74
75
76
77
78 protected MethodEndpoint lookupEndpoint(String key) {
79 return (MethodEndpoint) endpointMap.get(key);
80 }
81
82
83
84
85
86
87
88
89 protected void registerEndpoint(String key, MethodEndpoint endpoint) throws BeansException {
90 Object mappedEndpoint = endpointMap.get(key);
91 if (mappedEndpoint != null) {
92 throw new ApplicationContextException("Cannot map endpoint [" + endpoint + "] on registration key [" + key +
93 "]: there's already endpoint [" + mappedEndpoint + "] mapped");
94 }
95 if (endpoint == null) {
96 throw new ApplicationContextException("Could not find endpoint for key [" + key + "]");
97 }
98 endpointMap.put(key, endpoint);
99 if (logger.isDebugEnabled()) {
100 logger.debug("Mapped key [" + key + "] onto endpoint [" + endpoint + "]");
101 }
102 }
103
104
105
106
107
108
109
110
111 protected void registerMethods(Object endpoint) {
112 Assert.notNull(endpoint, "'endpoint' must not be null");
113 Method[] methods = getEndpointClass(endpoint).getMethods();
114 for (int i = 0; i < methods.length; i++) {
115 if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_15 && methods[i].isSynthetic() ||
116 methods[i].getDeclaringClass().equals(Object.class)) {
117 continue;
118 }
119 String key = getLookupKeyForMethod(methods[i]);
120 if (StringUtils.hasLength(key)) {
121 registerEndpoint(key, new MethodEndpoint(endpoint, methods[i]));
122 }
123 }
124 }
125
126
127
128
129
130
131
132
133 protected String getLookupKeyForMethod(Method method) {
134 return null;
135 }
136
137
138
139
140
141
142
143
144
145 protected Class getEndpointClass(Object endpoint) {
146 return AopUtils.getTargetClass(endpoint);
147 }
148
149 }