1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.snamespaces.extensions;
18
19 import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
20 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
21 import org.springframework.beans.factory.config.Scope;
22 import org.springframework.core.Ordered;
23
24 /**
25 * TODO make doc
26 *
27 * @author Jonhnny Weslley
28 * @version 1.00, 13/09/2007
29 * @since 1.0
30 */
31 public class SimpleCustomScopeConfigurer implements BeanFactoryPostProcessor, Ordered {
32
33 public static final String SCOPE_BEAN_NAME_PREFIX = "scope:";
34
35 private int order = LOWEST_PRECEDENCE;
36
37 public void setOrder(final int order) {
38 this.order = order;
39 }
40
41 public int getOrder() {
42 return order;
43 }
44
45 public void postProcessBeanFactory(
46 final ConfigurableListableBeanFactory beanFactory) {
47 final String[] customScopeBeanNames = beanFactory.getBeanNamesForType(Scope.class);
48 for (final String beanName : customScopeBeanNames) {
49 if (beanName.startsWith(SCOPE_BEAN_NAME_PREFIX)) {
50 registerCustomScope(beanFactory, beanName);
51 }
52 }
53 }
54
55 private void registerCustomScope(
56 final ConfigurableListableBeanFactory beanFactory, final String beanName) {
57 final String scopeName = beanName.substring(SCOPE_BEAN_NAME_PREFIX.length());
58 final Object scope = beanFactory.getBean(beanName);
59 beanFactory.registerScope(scopeName, (Scope) scope);
60 }
61
62 }