View Javadoc
1   /**
2    * Copyright 2005-2016 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_FUNCTION_BO_SERVICE = "functionBoService";
47      public static final String KRMS_TERM_BO_SERVICE = "termBoService";
48      public static final String KRMS_RULE_BO_SERVICE = "ruleBoService";
49      public static final String KRMS_AGENDA_AUTHORIZATION_SERVICE = "agendaAuthorizationService";
50      public static final String KRMS_REPOSITORY_TO_ENGINE_TRANSLATOR = "repositoryToEngineTranslator";
51      public static final String TYPE_TYPE_RELATION_BO_SERVICE = "typeTypeRelationBoService";
52      public static final String KRMS_PROPOSITION_BO_SERVICE = "propositionBoService";
53  
54  	private static KrmsAttributeDefinitionService krmsAttributeDefinitionService;
55      private static ContextBoService contextBoService;
56      private static TermBoService termBoService;
57      private static AgendaBoService agendaBoService;
58      private static FunctionBoService functionBoService;
59      private static RuleBoService ruleBoService;
60      private static AgendaAuthorizationService agendaAuthorizationService;
61      private static KrmsTypeRepositoryService krmsTypeRepositoryService;
62      private static RepositoryToEngineTranslator krmsRepositoryToEngineTranslator;
63      private static TypeTypeRelationBoService typeTypeRelationBoService;
64      private static PropositionBoService propositionBoService;
65  
66      public static <T extends Object> T getService(String serviceName) {
67  		return KrmsRepositoryServiceLocator.<T>getBean(serviceName);
68  	}
69  
70  	public static <T extends Object> T getBean(String serviceName) {
71  		if ( LOG.isDebugEnabled() ) {
72  			LOG.debug("Fetching service " + serviceName);
73  		}
74  		return GlobalResourceLoader.<T>getService(QName.valueOf(serviceName));
75  	}
76  
77      public static KrmsAttributeDefinitionService getKrmsAttributeDefinitionService() {
78  		if ( krmsAttributeDefinitionService == null ) {
79  			krmsAttributeDefinitionService = getService(KRMS_ATTRIBUTE_DEFINITION_SERVICE);
80  		}
81  		return krmsAttributeDefinitionService;
82      }
83  
84      public static CriteriaLookupService getCriteriaLookupService() {
85          return getService(CRITERIA_LOOKUP_SERVICE);
86      }
87  
88  	public static void setKrmsAttributeDefinitionService(final KrmsAttributeDefinitionService service) {
89  		krmsAttributeDefinitionService = service;
90  	}
91  
92      public static ContextBoService getContextBoService() {
93          if (contextBoService == null) {
94              contextBoService = getService(KRMS_CONTEXT_BO_SERVICE);
95          }
96          return contextBoService;
97      }
98  
99      public static TermBoService getTermBoService() {
100         if (termBoService == null) {
101             termBoService = getService(KRMS_TERM_BO_SERVICE);
102         }
103         return termBoService;
104     }
105 
106     public static AgendaBoService getAgendaBoService() {
107         if (agendaBoService == null) {
108             agendaBoService = getService(KRMS_AGENDA_BO_SERVICE);
109         }
110         return agendaBoService;
111     }
112 
113     public static FunctionBoService getFunctionBoService() {
114         if (functionBoService == null) {
115             functionBoService = getService(KRMS_FUNCTION_BO_SERVICE);
116         }
117         return functionBoService;
118     }
119 
120     public static RuleBoService getRuleBoService() {
121         if (ruleBoService == null) {
122             ruleBoService = getService(KRMS_RULE_BO_SERVICE);
123         }
124         return ruleBoService;
125     }
126 
127     public static AgendaAuthorizationService getAgendaAuthorizationService() {
128         if (agendaAuthorizationService == null) {
129             agendaAuthorizationService = getService(KRMS_AGENDA_AUTHORIZATION_SERVICE);
130         }
131         return agendaAuthorizationService;
132     }
133 
134     public static KrmsTypeRepositoryService getKrmsTypeRepositoryService() {
135         if (krmsTypeRepositoryService == null) {
136             krmsTypeRepositoryService = getService(KRMS_TYPE_REPOSITORY_SERVICE);
137         }
138         return krmsTypeRepositoryService;
139     }
140 
141     public static RepositoryToEngineTranslator getKrmsRepositoryToEngineTranslator() {
142         if (krmsRepositoryToEngineTranslator == null) {
143             krmsRepositoryToEngineTranslator = getService(KRMS_REPOSITORY_TO_ENGINE_TRANSLATOR);
144         }
145         return krmsRepositoryToEngineTranslator;
146     }
147 
148     public static TypeTypeRelationBoService getTypeTypeRelationBoService() {
149         if (typeTypeRelationBoService == null) {
150             typeTypeRelationBoService = getService(TYPE_TYPE_RELATION_BO_SERVICE);
151         }
152         return typeTypeRelationBoService;
153     }
154 
155     public static PropositionBoService getPropositionBoService() {
156         if (propositionBoService == null) {
157             propositionBoService = getService(KRMS_PROPOSITION_BO_SERVICE);
158         }
159         return propositionBoService;
160     }
161 }