1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.data.config;
17
18 import org.apache.log4j.Logger;
19 import org.kuali.rice.krad.data.KradDataServiceLocator;
20 import org.kuali.rice.krad.data.provider.Provider;
21 import org.kuali.rice.krad.data.provider.ProviderRegistry;
22 import org.springframework.beans.BeansException;
23 import org.springframework.beans.factory.InitializingBean;
24 import org.springframework.context.ApplicationContext;
25 import org.springframework.context.ApplicationContextAware;
26
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.List;
30
31
32
33
34 public class ProviderRegistrationFactory implements InitializingBean{
35 private static final Logger LOG = Logger.getLogger(ProviderRegistrationFactory.class);
36
37 protected ProviderRegistry providerRegistry;
38
39 @SuppressWarnings("unchecked")
40 protected List<Provider> providers = Collections.unmodifiableList(Collections.EMPTY_LIST);
41
42 @Override
43 public void afterPropertiesSet() throws Exception {
44 if ( getProviders() != null ) {
45 if ( getProviderRegistry() != null ) {
46 for ( Provider provider : getProviders() ) {
47 LOG.info( "Registering data module provider for "+ provider);
48 getProviderRegistry().registerProvider(provider);
49 }
50 } else {
51 LOG.error( "Provider registry not initialized.");
52 }
53 }
54 }
55
56
57
58
59
60 public void setProviders(List<Provider> providers) {
61 this.providers = Collections.unmodifiableList(new ArrayList<Provider>(providers));
62 }
63
64 public List<Provider> getProviders() {
65 return providers;
66 }
67
68 public ProviderRegistry getProviderRegistry() {
69 if(this.providerRegistry == null){
70 return KradDataServiceLocator.getProviderRegistry();
71 }
72 return this.providerRegistry;
73 }
74
75 public void setProviderRegistry(ProviderRegistry providerRegistry) {
76 this.providerRegistry = providerRegistry;
77 }
78 }