1 /*
2 * Copyright 2008 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.springframework.ws.soap.addressing.server;
18
19 import java.lang.reflect.Method;
20 import java.net.URI;
21
22 import org.springframework.aop.support.AopUtils;
23 import org.springframework.core.JdkVersion;
24 import org.springframework.util.Assert;
25 import org.springframework.ws.server.endpoint.MethodEndpoint;
26
27 /**
28 * Abstract base class for WS-Addressing <code>Action</code>-mapped {@link org.springframework.ws.server.EndpointMapping}
29 * implementations that map to {@link MethodEndpoint}s. Provides infrastructure for mapping endpoint methods to
30 * actions.
31 *
32 * @author Arjen Poutsma
33 * @since 1.5.0
34 */
35 public abstract class AbstractActionMethodEndpointMapping extends AbstractActionEndpointMapping {
36
37 /**
38 * Helper method that registers the methods of the given bean. This method iterates over the methods of the bean,
39 * and calls {@link #getActionForMethod(java.lang.reflect.Method)} for each. If this returns a URI, the method is
40 * registered using {@link #registerEndpoint(java.net.URI, Object)}.
41 *
42 * @see #getActionForMethod (java.lang.reflect.Method)
43 */
44 protected void registerMethods(Object endpoint) {
45 Assert.notNull(endpoint, "'endpoint' must not be null");
46 Method[] methods = AopUtils.getTargetClass(endpoint).getMethods();
47 for (int i = 0; i < methods.length; i++) {
48 if (JdkVersion.isAtLeastJava15() && methods[i].isSynthetic() ||
49 methods[i].getDeclaringClass().equals(Object.class)) {
50 continue;
51 }
52 URI action = getActionForMethod(methods[i]);
53 if (action != null) {
54 registerEndpoint(action, new MethodEndpoint(endpoint, methods[i]));
55 }
56 }
57 }
58
59 /** Returns the action value for the specified method. */
60 protected abstract URI getActionForMethod(Method method);
61
62 /**
63 * Return the class or interface to use for method reflection.
64 * <p/>
65 * Default implementation delegates to {@link AopUtils#getTargetClass(Object)}.
66 *
67 * @param endpoint the bean instance (might be an AOP proxy)
68 * @return the bean class to expose
69 */
70 protected Class getEndpointClass(Object endpoint) {
71 return AopUtils.getTargetClass(endpoint);
72 }
73
74 }