1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.service.DataDictionaryService;
20 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21 import org.springframework.beans.MutablePropertyValues;
22 import org.springframework.beans.PropertyValue;
23 import org.springframework.beans.factory.config.BeanDefinition;
24 import org.springframework.beans.factory.config.BeanDefinitionHolder;
25 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
26 import org.springframework.beans.factory.config.TypedStringValue;
27
28
29
30
31
32
33 public abstract class DictionaryBeanProcessorBase implements DictionaryBeanProcessor {
34
35
36
37
38
39
40
41
42
43
44 protected Class<?> getBeanClass(BeanDefinition beanDefinition, ConfigurableListableBeanFactory beanFactory) {
45 if (StringUtils.isNotBlank(beanDefinition.getBeanClassName())) {
46 try {
47 return Class.forName(beanDefinition.getBeanClassName());
48 } catch (ClassNotFoundException e) {
49
50 return null;
51 }
52 } else if (StringUtils.isNotBlank(beanDefinition.getParentName())) {
53 BeanDefinition parentBeanDefinition = beanFactory.getBeanDefinition(beanDefinition.getParentName());
54 if (parentBeanDefinition != null) {
55 return getBeanClass(parentBeanDefinition, beanFactory);
56 }
57 }
58
59 return null;
60 }
61
62
63
64
65
66
67
68 protected String getStringValue(Object value) {
69 if (value instanceof TypedStringValue) {
70 TypedStringValue typedStringValue = (TypedStringValue) value;
71 return typedStringValue.getValue();
72 } else if (value instanceof String) {
73 return (String) value;
74 }
75
76 return null;
77 }
78
79
80
81
82
83
84
85
86 protected void applyPropertyValueToBean(String propertyPath, String propertyValue, BeanDefinition beanDefinition) {
87 applyPropertyValueToBean(propertyPath, propertyValue, beanDefinition.getPropertyValues());
88 }
89
90
91
92
93
94
95
96
97 protected void applyPropertyValueToBean(String propertyPath, String propertyValue, MutablePropertyValues pvs) {
98 pvs.addPropertyValue(propertyPath, propertyValue);
99 }
100
101
102
103
104
105
106
107
108 protected BeanDefinition getPropertyValueBeanDefinition(PropertyValue propertyValue) {
109 BeanDefinition beanDefinition = null;
110
111 Object value = propertyValue.getValue();
112 if ((value instanceof BeanDefinition) || (value instanceof BeanDefinitionHolder)) {
113 if (propertyValue instanceof BeanDefinition) {
114 beanDefinition = (BeanDefinition) propertyValue;
115 } else {
116 beanDefinition = ((BeanDefinitionHolder) value).getBeanDefinition();
117 }
118 }
119
120 return beanDefinition;
121 }
122
123
124
125
126
127
128
129 protected boolean isGeneratedBeanName(String beanName) {
130 return StringUtils.isNotBlank(beanName) && (StringUtils.contains(beanName, "$") || StringUtils.contains(
131 beanName, "#"));
132 }
133
134
135
136
137
138
139 protected DataDictionaryService getDataDictionaryService() {
140 return KRADServiceLocatorWeb.getDataDictionaryService();
141 }
142 }