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