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.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  import org.kuali.rice.krms.impl.provider.repository.RepositoryToEngineTranslator;
24  
25  import javax.xml.namespace.QName;
26  
27  /**
28   * This class keeps track of the KRMS Repository Services
29   * 
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   *
32   */
33  public final class KrmsRepositoryServiceLocator {
34  
35      private KrmsRepositoryServiceLocator() {
36          // private constructor since this is class is all static utility methods
37      }
38  
39  	private static final Logger LOG = Logger.getLogger(KrmsRepositoryServiceLocator.class);
40  
41      public static final String KRMS_ATTRIBUTE_DEFINITION_SERVICE = "krmsAttributeDefinitionService";
42      public static final String KRMS_TYPE_REPOSITORY_SERVICE = "krmsTypeRepositoryService";
43      public static final String CRITERIA_LOOKUP_SERVICE = "criteriaLookupService";
44      public static final String KRMS_CONTEXT_BO_SERVICE = "contextBoService";
45      public static final String KRMS_AGENDA_BO_SERVICE = "agendaBoService";
46      public static final String KRMS_TERM_BO_SERVICE = "termBoService";
47      public static final String KRMS_RULE_BO_SERVICE = "ruleBoService";
48      public static final String KRMS_AGENDA_AUTHORIZATION_SERVICE = "agendaAuthorizationService";
49      public static final String KRMS_REPOSITORY_TO_ENGINE_TRANSLATOR = "repositoryToEngineTranslator";
50  
51  	private static KrmsAttributeDefinitionService krmsAttributeDefinitionService;
52      private static ContextBoService contextBoService;
53      private static TermBoService termBoService;
54      private static AgendaBoService agendaBoService;
55      private static RuleBoService ruleBoService;
56      private static AgendaAuthorizationService agendaAuthorizationService;
57      private static KrmsTypeRepositoryService krmsTypeRepositoryService;
58      private static RepositoryToEngineTranslator krmsRepositoryToEngineTranslator;
59  
60      public static <T extends Object> T getService(String serviceName) {
61  		return KrmsRepositoryServiceLocator.<T>getBean(serviceName);
62  	}
63  
64  	public static <T extends Object> T getBean(String serviceName) {
65  		if ( LOG.isDebugEnabled() ) {
66  			LOG.debug("Fetching service " + serviceName);
67  		}
68  		return GlobalResourceLoader.<T>getService(QName.valueOf(serviceName));
69  	}
70  
71      public static KrmsAttributeDefinitionService getKrmsAttributeDefinitionService() {
72  		if ( krmsAttributeDefinitionService == null ) {
73  			krmsAttributeDefinitionService = getService(KRMS_ATTRIBUTE_DEFINITION_SERVICE);
74  		}
75  		return krmsAttributeDefinitionService;
76      }
77  
78      public static CriteriaLookupService getCriteriaLookupService() {
79          return getService(CRITERIA_LOOKUP_SERVICE);
80      }
81  
82  	public static void setKrmsAttributeDefinitionService(final KrmsAttributeDefinitionService service) {
83  		krmsAttributeDefinitionService = service;
84  	}
85  
86      public static ContextBoService getContextBoService() {
87          if (contextBoService == null) {
88              contextBoService = getService(KRMS_CONTEXT_BO_SERVICE);
89          }
90          return contextBoService;
91      }
92  
93      public static TermBoService getTermBoService() {
94          if (termBoService == null) {
95              termBoService = getService(KRMS_TERM_BO_SERVICE);
96          }
97          return termBoService;
98      }
99  
100     public static AgendaBoService getAgendaBoService() {
101         if (agendaBoService == null) {
102             agendaBoService = getService(KRMS_AGENDA_BO_SERVICE);
103         }
104         return agendaBoService;
105     }
106 
107     public static RuleBoService getRuleBoService() {
108         if (ruleBoService == null) {
109             ruleBoService = getService(KRMS_RULE_BO_SERVICE);
110         }
111         return ruleBoService;
112     }
113 
114     public static AgendaAuthorizationService getAgendaAuthorizationService() {
115         if (agendaAuthorizationService == null) {
116             agendaAuthorizationService = getService(KRMS_AGENDA_AUTHORIZATION_SERVICE);
117         }
118         return agendaAuthorizationService;
119     }
120 
121     public static KrmsTypeRepositoryService getKrmsTypeRepositoryService() {
122         if (krmsTypeRepositoryService == null) {
123             krmsTypeRepositoryService = getService(KRMS_TYPE_REPOSITORY_SERVICE);
124         }
125         return krmsTypeRepositoryService;
126     }
127 
128     public static RepositoryToEngineTranslator getKrmsRepositoryToEngineTranslator() {
129         if (krmsRepositoryToEngineTranslator == null) {
130             krmsRepositoryToEngineTranslator = getService(KRMS_REPOSITORY_TO_ENGINE_TRANSLATOR);
131         }
132         return krmsRepositoryToEngineTranslator;
133     }
134 }