View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Provides method to register Providers outside of ModuleConfiguration
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       * Sets the list of providers for this module
58       * @param providers list of providers
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  }