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