View Javadoc

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