View Javadoc
1   /**
2    * Copyright 2005-2014 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.provider;
17  
18  import org.apache.log4j.Logger;
19  import org.kuali.rice.krad.data.KradDataServiceLocator;
20  import org.springframework.beans.factory.InitializingBean;
21  
22  import java.util.ArrayList;
23  import java.util.Collections;
24  import java.util.List;
25  
26  /**
27   * Provides a mechanism for registering Providers in the {@link ProviderRegistry} using Spring.
28   *
29   * @see Provider
30   * @see ProviderRegistry
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class ProviderRegistrar implements InitializingBean {
35  
36      private static final Logger LOG = Logger.getLogger(ProviderRegistrar.class);
37  
38      /**
39       * The provider registry.
40       */
41      protected ProviderRegistry providerRegistry;
42  
43      /**
44       * The providers currently assigned to the registry.
45       */
46      protected List<Provider> providers = Collections.unmodifiableList(Collections.<Provider>emptyList());
47  
48      /**
49       * {@inheritDoc}
50       */
51      @Override
52      public void afterPropertiesSet() throws Exception {
53          if ( getProviders() != null ) {
54              if ( getProviderRegistry() != null ) {
55                  for ( Provider provider : getProviders() ) {
56                      LOG.info( "Registering data module provider for "+ provider);
57                      getProviderRegistry().registerProvider(provider);
58                  }
59              } else {
60                  LOG.error( "Provider registry not initialized.");
61              }
62          }
63      }
64  
65      /**
66       * Sets the list of providers for this module.
67       *
68       * @param providers list of providers
69       */
70      public void setProviders(List<Provider> providers) {
71          this.providers = Collections.unmodifiableList(new ArrayList<Provider>(providers));
72      }
73  
74      /**
75       * Gets the list of providers for this module.
76       *
77       * @return the list of providers for this module.
78       */
79      public List<Provider> getProviders() {
80          return providers;
81      }
82  
83      /**
84       * Gets the provider registry.
85       *
86       * @return the provider registry.
87       */
88      public ProviderRegistry getProviderRegistry() {
89          if(this.providerRegistry == null){
90              return KradDataServiceLocator.getProviderRegistry();
91          }
92          return this.providerRegistry;
93      }
94  
95      /**
96       * Setter for the provider registry.
97       *
98       * @param providerRegistry the provider registry to set.
99       */
100     public void setProviderRegistry(ProviderRegistry providerRegistry) {
101         this.providerRegistry = providerRegistry;
102     }
103 
104 }