1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.util.spring;
17
18 import org.springframework.beans.factory.BeanFactory;
19 import org.springframework.beans.factory.BeanFactoryAware;
20 import org.springframework.beans.factory.config.AbstractFactoryBean;
21
22
23
24
25
26
27
28
29
30 public class IfExistsFactoryBean extends AbstractFactoryBean implements BeanFactoryAware {
31 private BeanFactory beanFactory;
32 private String beanName;
33 private Object customReturnValue;
34
35 @Override
36 protected Object createInstance() throws Exception {
37 if (beanFactory.containsBean(beanName)) {
38 if (customReturnValue != null) {
39 return customReturnValue;
40 } else {
41 return beanFactory.getBean(beanName);
42 }
43 }
44 return null;
45 }
46
47
48
49
50
51
52 @Override
53 public Class getObjectType() {
54 return null;
55 }
56
57 public BeanFactory getBeanFactory() {
58 return this.beanFactory;
59 }
60
61 public String getBeanName() {
62 return this.beanName;
63 }
64
65 public Object getCustomReturnValue() {
66 return this.customReturnValue;
67 }
68
69 public void setBeanFactory(BeanFactory beanFactory) {
70 this.beanFactory = beanFactory;
71 }
72
73 public void setBeanName(String beanName) {
74 this.beanName = beanName;
75 }
76
77 public void setCustomReturnValue(Object customReturnValue) {
78 this.customReturnValue = customReturnValue;
79 }
80
81 }