1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.bo; |
17 | |
|
18 | |
import org.kuali.rice.krad.datadictionary.DataDictionaryLocationConfigurer; |
19 | |
import org.kuali.rice.krad.service.DataDictionaryService; |
20 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
21 | |
import org.kuali.rice.krad.service.PersistenceService; |
22 | |
import org.springframework.beans.factory.InitializingBean; |
23 | |
import org.springframework.context.ApplicationContext; |
24 | |
import org.springframework.context.ApplicationContextAware; |
25 | |
|
26 | |
import javax.persistence.EntityManager; |
27 | |
import java.lang.reflect.Modifier; |
28 | |
import java.util.ArrayList; |
29 | |
import java.util.Collections; |
30 | |
import java.util.List; |
31 | |
import java.util.Map; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public class ModuleConfiguration implements InitializingBean, ApplicationContextAware { |
40 | |
|
41 | |
|
42 | |
|
43 | |
protected String namespaceCode; |
44 | |
protected ApplicationContext applicationContext; |
45 | |
|
46 | |
protected List<String> packagePrefixes; |
47 | |
|
48 | |
protected List<String> databaseRepositoryFilePaths; |
49 | |
|
50 | |
protected List<String> dataDictionaryPackages; |
51 | |
|
52 | |
protected List<String> scriptConfigurationFilePaths; |
53 | |
|
54 | |
protected List<String> jobNames; |
55 | |
|
56 | |
protected List<String> triggerNames; |
57 | |
|
58 | |
|
59 | |
protected String dataSourceName; |
60 | |
|
61 | |
|
62 | |
protected EntityManager entityManager; |
63 | |
|
64 | |
protected Map<Class, Class> externalizableBusinessObjectImplementations; |
65 | |
|
66 | |
protected boolean initializeDataDictionary; |
67 | |
|
68 | |
protected PersistenceService persistenceService; |
69 | |
|
70 | |
protected DataDictionaryService dataDictionaryService; |
71 | |
|
72 | 0 | public ModuleConfiguration() { |
73 | 0 | databaseRepositoryFilePaths = new ArrayList<String>(); |
74 | 0 | dataDictionaryPackages = new ArrayList<String>(); |
75 | 0 | scriptConfigurationFilePaths = new ArrayList<String>(); |
76 | 0 | jobNames = new ArrayList<String>(); |
77 | 0 | triggerNames = new ArrayList<String>(); |
78 | 0 | } |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
public List<String> getDatabaseRepositoryFilePaths() { |
84 | 0 | return this.databaseRepositoryFilePaths; |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public void setDatabaseRepositoryFilePaths( |
91 | |
List<String> databaseRepositoryFilePaths) { |
92 | 0 | this.trimList(databaseRepositoryFilePaths); |
93 | 0 | this.databaseRepositoryFilePaths = databaseRepositoryFilePaths; |
94 | 0 | } |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public List<String> getDataDictionaryPackages() { |
100 | 0 | return this.dataDictionaryPackages; |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public void setDataDictionaryPackages(List<String> dataDictionaryPackages) { |
107 | 0 | this.trimList(dataDictionaryPackages); |
108 | 0 | this.dataDictionaryPackages = dataDictionaryPackages; |
109 | 0 | } |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public Map<Class, Class> getExternalizableBusinessObjectImplementations() { |
115 | 0 | if (this.externalizableBusinessObjectImplementations == null) |
116 | 0 | return null; |
117 | 0 | return Collections.unmodifiableMap(this.externalizableBusinessObjectImplementations); |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
public void setExternalizableBusinessObjectImplementations( |
124 | |
Map<Class, Class> externalizableBusinessObjectImplementations) { |
125 | 0 | if (externalizableBusinessObjectImplementations != null) { |
126 | 0 | for (Class implClass : externalizableBusinessObjectImplementations.values()) { |
127 | 0 | int implModifiers = implClass.getModifiers(); |
128 | 0 | if (Modifier.isInterface(implModifiers) || Modifier.isAbstract(implModifiers)) { |
129 | 0 | throw new RuntimeException("Externalizable business object implementation class " + |
130 | |
implClass.getName() + " must be a non-interface, non-abstract class"); |
131 | |
} |
132 | 0 | } |
133 | |
} |
134 | 0 | this.externalizableBusinessObjectImplementations = externalizableBusinessObjectImplementations; |
135 | 0 | } |
136 | |
|
137 | |
public List<String> getPackagePrefixes(){ |
138 | 0 | return this.packagePrefixes; |
139 | |
} |
140 | |
|
141 | |
public void setPackagePrefixes(List<String> packagePrefixes){ |
142 | 0 | this.trimList(packagePrefixes); |
143 | 0 | this.packagePrefixes = packagePrefixes; |
144 | 0 | } |
145 | |
|
146 | |
public void setInitializeDataDictionary(boolean initializeDataDictionary){ |
147 | 0 | this.initializeDataDictionary = initializeDataDictionary; |
148 | 0 | } |
149 | |
|
150 | |
public List<String> getScriptConfigurationFilePaths(){ |
151 | 0 | return this.scriptConfigurationFilePaths; |
152 | |
} |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
public List<String> getJobNames() { |
158 | 0 | return this.jobNames; |
159 | |
} |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
public void setJobNames(List<String> jobNames) { |
165 | 0 | this.jobNames = jobNames; |
166 | 0 | } |
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
public List<String> getTriggerNames() { |
173 | 0 | return this.triggerNames; |
174 | |
} |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
public void setTriggerNames(List<String> triggerNames) { |
180 | 0 | this.triggerNames = triggerNames; |
181 | 0 | } |
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
public boolean isInitializeDataDictionary() { |
187 | 0 | return this.initializeDataDictionary; |
188 | |
} |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
public void setScriptConfigurationFilePaths( |
194 | |
List<String> scriptConfigurationFilePaths) { |
195 | 0 | this.scriptConfigurationFilePaths = scriptConfigurationFilePaths; |
196 | 0 | } |
197 | |
|
198 | |
@Override |
199 | |
public void afterPropertiesSet() throws Exception { |
200 | 0 | if (isInitializeDataDictionary() && getDataDictionaryPackages() != null && !getDataDictionaryPackages().isEmpty() ) { |
201 | 0 | if ( getDataDictionaryService() == null ) { |
202 | 0 | setDataDictionaryService(KRADServiceLocatorWeb.getDataDictionaryService()); |
203 | |
} |
204 | 0 | if ( getDataDictionaryService() == null ) { |
205 | 0 | setDataDictionaryService((DataDictionaryService)applicationContext.getBean( KRADServiceLocatorWeb.DATA_DICTIONARY_SERVICE )); |
206 | |
} |
207 | 0 | DataDictionaryLocationConfigurer ddl = new DataDictionaryLocationConfigurer( getDataDictionaryService() ); |
208 | 0 | ddl.setDataDictionaryPackages(getDataDictionaryPackages()); |
209 | 0 | ddl.afterPropertiesSet(); |
210 | |
} |
211 | 0 | if (getDatabaseRepositoryFilePaths() != null) { |
212 | 0 | for (String repositoryLocation : getDatabaseRepositoryFilePaths()) { |
213 | |
|
214 | 0 | if (getPersistenceService() == null) { |
215 | 0 | setPersistenceService(KRADServiceLocatorWeb.getPersistenceServiceOjb()); |
216 | |
} |
217 | 0 | if ( persistenceService == null ) { |
218 | 0 | setPersistenceService((PersistenceService)applicationContext.getBean( KRADServiceLocatorWeb.PERSISTENCE_SERVICE_OJB )); |
219 | |
} |
220 | 0 | getPersistenceService().loadRepositoryDescriptor( repositoryLocation ); |
221 | |
} |
222 | |
} |
223 | 0 | } |
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
public String getNamespaceCode() { |
229 | 0 | return this.namespaceCode; |
230 | |
} |
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
public void setNamespaceCode(String namespaceCode) { |
236 | 0 | this.namespaceCode = namespaceCode; |
237 | 0 | } |
238 | |
|
239 | |
@Override |
240 | |
public void setApplicationContext(ApplicationContext applicationContext) { |
241 | 0 | this.applicationContext = applicationContext; |
242 | 0 | } |
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
public DataDictionaryService getDataDictionaryService() { |
248 | 0 | return this.dataDictionaryService; |
249 | |
} |
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
public void setDataDictionaryService(DataDictionaryService dataDictionaryService) { |
255 | 0 | this.dataDictionaryService = dataDictionaryService; |
256 | 0 | } |
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
public PersistenceService getPersistenceService() { |
262 | 0 | return this.persistenceService; |
263 | |
} |
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
public void setPersistenceService(PersistenceService persistenceService) { |
269 | 0 | this.persistenceService = persistenceService; |
270 | 0 | } |
271 | |
|
272 | |
public String getDataSourceName() { |
273 | 0 | return this.dataSourceName; |
274 | |
} |
275 | |
|
276 | |
public void setDataSourceName(String dataSourceName) { |
277 | 0 | this.dataSourceName = dataSourceName; |
278 | 0 | } |
279 | |
|
280 | |
public EntityManager getEntityManager() { |
281 | 0 | return this.entityManager; |
282 | |
} |
283 | |
|
284 | |
public void setEntityManager(EntityManager entityManager) { |
285 | 0 | this.entityManager = entityManager; |
286 | 0 | } |
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
protected void trimList(List<String> stringList){ |
295 | 0 | if(stringList != null){ |
296 | |
|
297 | |
|
298 | 0 | for(int i=0; i<stringList.size(); i++){ |
299 | 0 | String elmt = stringList.get(i); |
300 | 0 | elmt = elmt.trim(); |
301 | 0 | stringList.set(i, elmt); |
302 | |
} |
303 | |
} |
304 | 0 | } |
305 | |
|
306 | |
} |