View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.krms.impl.repository;
17  
18  import org.apache.log4j.Logger;
19  import org.kuali.rice.core.api.criteria.CriteriaLookupService;
20  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
21  import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService;
22  import org.kuali.rice.krms.impl.authorization.AgendaAuthorizationService;
23  
24  /**
25   * This class keeps track of the KRMS Repository Services
26   * 
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   *
29   */
30  public final class KrmsRepositoryServiceLocator {
31  
32  	private static final Logger LOG = Logger.getLogger(KrmsRepositoryServiceLocator.class);
33  
34      public static final String KRMS_ATTRIBUTE_DEFINITION_SERVICE = "krmsAttributeDefinitionService";
35      public static final String KRMS_TYPE_REPOSITORY_SERVICE = "krmsTypeRepositoryService";
36      public static final String CRITERIA_LOOKUP_SERVICE = "criteriaLookupService";
37      public static final String KRMS_CONTEXT_BO_SERVICE = "contextBoService";
38      public static final String KRMS_AGENDA_BO_SERVICE = "agendaBoService";
39      public static final String KRMS_RULE_BO_SERVICE = "ruleBoService";
40      public static final String KRMS_AGENDA_AUTHORIZATION_SERVICE = "agendaAuthorizationService";
41  
42  	private static KrmsAttributeDefinitionService krmsAttributeDefinitionService;
43      private static ContextBoService contextBoService;
44      private static AgendaBoService agendaBoService;
45      private static RuleBoService ruleBoService;
46      private static AgendaAuthorizationService agendaAuthorizationService;
47      private static KrmsTypeRepositoryService krmsTypeRepositoryService;
48  
49      public static <T extends Object> T getService(String serviceName) {
50  		return KrmsRepositoryServiceLocator.<T>getBean(serviceName);
51  	}
52  
53  	public static <T extends Object> T getBean(String serviceName) {
54  		if ( LOG.isDebugEnabled() ) {
55  			LOG.debug("Fetching service " + serviceName);
56  		}
57  		return GlobalResourceLoader.<T>getService(serviceName);
58  	}
59  
60      public static KrmsAttributeDefinitionService getKrmsAttributeDefinitionService() {
61  		if ( krmsAttributeDefinitionService == null ) {
62  			krmsAttributeDefinitionService = getService(KRMS_ATTRIBUTE_DEFINITION_SERVICE);
63  		}
64  		return krmsAttributeDefinitionService;
65      }
66  
67      public static CriteriaLookupService getCriteriaLookupService() {
68          return getService(CRITERIA_LOOKUP_SERVICE);
69      }
70  
71  	public static void setKrmsAttributeDefinitionService(final KrmsAttributeDefinitionService service) {
72  		krmsAttributeDefinitionService = service;
73  	}
74  
75      public static ContextBoService getContextBoService() {
76          if (contextBoService == null) {
77              contextBoService = getService(KRMS_CONTEXT_BO_SERVICE);
78          }
79          return contextBoService;
80      }
81  
82      public static AgendaBoService getAgendaBoService() {
83          if (agendaBoService == null) {
84              agendaBoService = getService(KRMS_AGENDA_BO_SERVICE);
85          }
86          return agendaBoService;
87      }
88  
89      public static RuleBoService getRuleBoService() {
90          if (ruleBoService == null) {
91              ruleBoService = getService(KRMS_RULE_BO_SERVICE);
92          }
93          return ruleBoService;
94      }
95  
96      public static AgendaAuthorizationService getAgendaAuthorizationService() {
97          if (agendaAuthorizationService == null) {
98              agendaAuthorizationService = getService(KRMS_AGENDA_AUTHORIZATION_SERVICE);
99          }
100         return agendaAuthorizationService;
101     }
102 
103     public static KrmsTypeRepositoryService getKrmsTypeRepositoryService() {
104         if (krmsTypeRepositoryService == null) {
105             krmsTypeRepositoryService = getService(KRMS_TYPE_REPOSITORY_SERVICE);
106         }
107         return krmsTypeRepositoryService;
108     }
109 
110 }