1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.oxclient.util;
17
18 import net.sf.oval.constraint.AssertFieldConstraints;
19 import net.sf.oval.constraint.NotEmpty;
20 import net.sf.oval.constraint.NotNull;
21 import net.sf.oval.guard.Guarded;
22
23 import org.springframework.beans.BeansException;
24 import org.springframework.beans.factory.BeanFactory;
25 import org.springframework.beans.factory.BeanFactoryAware;
26
27
28
29
30
31 @Guarded
32 public class SpringBeanFactory implements BeanFactoryAware {
33
34 private BeanFactory beanFactory = null;
35
36 @NotNull
37 @NotEmpty
38 private String beanname;
39
40 public SpringBeanFactory(final String defaultBeanname) {
41 this.beanname = defaultBeanname;
42 }
43
44
45 public Object getBean() {
46 if (this.beanFactory == null) {
47 throw new IllegalStateException("IBeanFactory not set");
48 }
49 return this.beanFactory.getBean(this.beanname);
50 }
51
52
53
54
55 public void setBeanname(@AssertFieldConstraints final String beanname) {
56 this.beanname = beanname;
57 }
58
59
60
61
62
63 public void setBeanFactory(final BeanFactory beanFactory) throws BeansException {
64 this.beanFactory = beanFactory;
65 }
66
67 }