View Javadoc

1   /*
2    * Copyright 2007 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.server.endpoint.mapping;
18  
19  import java.lang.annotation.Annotation;
20  
21  import org.springframework.beans.BeansException;
22  import org.springframework.beans.factory.config.BeanPostProcessor;
23  import org.springframework.ws.server.endpoint.annotation.Endpoint;
24  
25  /**
26   * Abstract base for {@link org.springframework.ws.server.EndpointMapping} implementations that map classes tagged with
27   * an annotation. By default the annotation is {@link Endpoint}, but this can be overriden in subclasses.
28   * <p/>
29   * The methods of each bean carrying @Endpoint will be registered using {@link #registerMethods(Object)}.
30   *
31   * @author Arjen Poutsma
32   * @since 1.0.0
33   */
34  public abstract class AbstractAnnotationMethodEndpointMapping extends AbstractMethodEndpointMapping
35          implements BeanPostProcessor {
36  
37      public final Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
38          return bean;
39      }
40  
41      /** Returns the 'endpoint' annotation type. Default is {@link Endpoint}. */
42      protected Class<? extends Annotation> getEndpointAnnotationType() {
43          return Endpoint.class;
44      }
45  
46      public final Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
47          if (getEndpointClass(bean).getAnnotation(getEndpointAnnotationType()) != null) {
48              registerMethods(bean);
49          }
50          return bean;
51      }
52  
53  }