View Javadoc

1   /*
2    * Copyright 2005-2010 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.util.Assert;
24  import org.springframework.ws.server.endpoint.MethodEndpoint;
25  
26  /**
27   * Abstract base class for WS-Addressing <code>Action</code>-mapped [email protected] org.springframework.ws.server.EndpointMapping}
28   * implementations that map to [email protected] MethodEndpoint}s. Provides infrastructure for mapping endpoint methods to
29   * actions.
30   *
31   * @author Arjen Poutsma
32   * @since 1.5.0
33   */
34  public abstract class AbstractActionMethodEndpointMapping extends AbstractActionEndpointMapping {
35  
36      /**
37       * Helper method that registers the methods of the given bean. This method iterates over the methods of the bean,
38       * and calls [email protected] #getActionForMethod(java.lang.reflect.Method)} for each. If this returns a URI, the method is
39       * registered using [email protected] #registerEndpoint(java.net.URI, Object)}.
40       *
41       * @see #getActionForMethod (java.lang.reflect.Method)
42       */
43      protected void registerMethods(Object endpoint) {
44          Assert.notNull(endpoint, "'endpoint' must not be null");
45          Method[] methods = AopUtils.getTargetClass(endpoint).getMethods();
46          for (Method method : methods) {
47              if (method.isSynthetic() || method.getDeclaringClass().equals(Object.class)) {
48                  continue;
49              }
50              URI action = getActionForMethod(method);
51              if (action != null) {
52                  registerEndpoint(action, new MethodEndpoint(endpoint, method));
53              }
54          }
55      }
56  
57      /** Returns the action value for the specified method. */
58      protected abstract URI getActionForMethod(Method method);
59  
60      /**
61       * Return the class or interface to use for method reflection.
62       * <p/>
63       * Default implementation delegates to [email protected] AopUtils#getTargetClass(Object)}.
64       *
65       * @param endpoint the bean instance (might be an AOP proxy)
66       * @return the bean class to expose
67       */
68      protected Class<?> getEndpointClass(Object endpoint) {
69          return AopUtils.getTargetClass(endpoint);
70      }
71  
72  }