1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
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 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 6 | public class SpringPathResolverProvider implements PathResolverProvider, |
34 | |
ApplicationContextAware { |
35 | |
|
36 | |
@Autowired |
37 | |
private PathResolver pathResolver; |
38 | |
|
39 | |
private ApplicationContext applicationContext; |
40 | |
|
41 | 6 | private boolean initialized = false; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
public void setApplicationContext( |
50 | |
final ApplicationContext applicationContext) { |
51 | 6 | this.applicationContext = applicationContext; |
52 | 6 | } |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
public void initialize() { |
58 | 6 | if (initialized) { |
59 | 0 | return; |
60 | |
} |
61 | |
|
62 | 6 | final String[] names = BeanFactoryUtils |
63 | |
.beanNamesIncludingAncestors(applicationContext); |
64 | 131 | for (final String beanDefinitionName : names) { |
65 | 125 | final Class<?> type = applicationContext |
66 | |
.getType(beanDefinitionName); |
67 | 125 | if (ActionUtils.isActionClass(type)) { |
68 | 6 | pathResolver.add(type); |
69 | |
} |
70 | |
} |
71 | |
|
72 | 6 | initialized = true; |
73 | 6 | } |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public PathResolver getPathResolver() { |
79 | 1 | return pathResolver; |
80 | |
} |
81 | |
|
82 | |
} |