View Javadoc

1   /*
2    * Copyright 2004-2010 the Seasar Foundation and the Others.
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,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  
17  package org.seasar.cubby.plugins.spring.spi;
18  
19  import org.seasar.cubby.routing.PathResolver;
20  import org.seasar.cubby.spi.PathResolverProvider;
21  import org.seasar.cubby.util.ActionUtils;
22  import org.springframework.beans.factory.BeanFactoryUtils;
23  import org.springframework.beans.factory.annotation.Autowired;
24  import org.springframework.context.ApplicationContext;
25  import org.springframework.context.ApplicationContextAware;
26  
27  /**
28   * パスリゾルバプロバイダの実装クラスです。
29   * 
30   * @author suzuki-kei
31   * @author someda
32   * @since 2.0.0
33   */
34  public class SpringPathResolverProvider implements PathResolverProvider,
35  		ApplicationContextAware {
36  
37  	@Autowired
38  	private PathResolver pathResolver;
39  
40  	private ApplicationContext applicationContext;
41  
42  	private boolean initialized = false;
43  
44  	/**
45  	 * アプリケーションコンテキストを設定します。
46  	 * 
47  	 * @param applicationContext
48  	 *            アプリケーションコンテキスト
49  	 */
50  	public void setApplicationContext(
51  			final ApplicationContext applicationContext) {
52  		this.applicationContext = applicationContext;
53  	}
54  
55  	/**
56  	 * このオブジェクトを初期化します。
57  	 */
58  	public void initialize() {
59  		if (initialized) {
60  			return;
61  		}
62  
63  		final String[] names = BeanFactoryUtils
64  				.beanNamesIncludingAncestors(applicationContext);
65  		for (final String beanDefinitionName : names) {
66  			final Class<?> type = applicationContext
67  					.getType(beanDefinitionName);
68  			if (ActionUtils.isActionClass(type)) {
69  				pathResolver.add(type);
70  			}
71  		}
72  
73  		initialized = true;
74  	}
75  
76  	/**
77  	 * {@inheritDoc}
78  	 */
79  	public PathResolver getPathResolver() {
80  		return pathResolver;
81  	}
82  
83  }