001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krms.impl.repository; 017 018import org.apache.log4j.Logger; 019import org.kuali.rice.core.api.criteria.CriteriaLookupService; 020import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; 021import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService; 022import org.kuali.rice.krms.impl.authorization.AgendaAuthorizationService; 023import org.kuali.rice.krms.impl.provider.repository.RepositoryToEngineTranslator; 024 025import javax.xml.namespace.QName; 026 027/** 028 * This class keeps track of the KRMS Repository Services 029 * 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 * 032 */ 033public final class KrmsRepositoryServiceLocator { 034 035 private KrmsRepositoryServiceLocator() { 036 // private constructor since this is class is all static utility methods 037 } 038 039 private static final Logger LOG = Logger.getLogger(KrmsRepositoryServiceLocator.class); 040 041 public static final String KRMS_ATTRIBUTE_DEFINITION_SERVICE = "krmsAttributeDefinitionService"; 042 public static final String KRMS_TYPE_REPOSITORY_SERVICE = "krmsTypeRepositoryService"; 043 public static final String CRITERIA_LOOKUP_SERVICE = "criteriaLookupService"; 044 public static final String KRMS_CONTEXT_BO_SERVICE = "contextBoService"; 045 public static final String KRMS_AGENDA_BO_SERVICE = "agendaBoService"; 046 public static final String KRMS_TERM_BO_SERVICE = "termBoService"; 047 public static final String KRMS_RULE_BO_SERVICE = "ruleBoService"; 048 public static final String KRMS_AGENDA_AUTHORIZATION_SERVICE = "agendaAuthorizationService"; 049 public static final String KRMS_REPOSITORY_TO_ENGINE_TRANSLATOR = "repositoryToEngineTranslator"; 050 051 private static KrmsAttributeDefinitionService krmsAttributeDefinitionService; 052 private static ContextBoService contextBoService; 053 private static TermBoService termBoService; 054 private static AgendaBoService agendaBoService; 055 private static RuleBoService ruleBoService; 056 private static AgendaAuthorizationService agendaAuthorizationService; 057 private static KrmsTypeRepositoryService krmsTypeRepositoryService; 058 private static RepositoryToEngineTranslator krmsRepositoryToEngineTranslator; 059 060 public static <T extends Object> T getService(String serviceName) { 061 return KrmsRepositoryServiceLocator.<T>getBean(serviceName); 062 } 063 064 public static <T extends Object> T getBean(String serviceName) { 065 if ( LOG.isDebugEnabled() ) { 066 LOG.debug("Fetching service " + serviceName); 067 } 068 return GlobalResourceLoader.<T>getService(QName.valueOf(serviceName)); 069 } 070 071 public static KrmsAttributeDefinitionService getKrmsAttributeDefinitionService() { 072 if ( krmsAttributeDefinitionService == null ) { 073 krmsAttributeDefinitionService = getService(KRMS_ATTRIBUTE_DEFINITION_SERVICE); 074 } 075 return krmsAttributeDefinitionService; 076 } 077 078 public static CriteriaLookupService getCriteriaLookupService() { 079 return getService(CRITERIA_LOOKUP_SERVICE); 080 } 081 082 public static void setKrmsAttributeDefinitionService(final KrmsAttributeDefinitionService service) { 083 krmsAttributeDefinitionService = service; 084 } 085 086 public static ContextBoService getContextBoService() { 087 if (contextBoService == null) { 088 contextBoService = getService(KRMS_CONTEXT_BO_SERVICE); 089 } 090 return contextBoService; 091 } 092 093 public static TermBoService getTermBoService() { 094 if (termBoService == null) { 095 termBoService = getService(KRMS_TERM_BO_SERVICE); 096 } 097 return termBoService; 098 } 099 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}