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_FUNCTION_BO_SERVICE = "functionBoService";
047    public static final String KRMS_TERM_BO_SERVICE = "termBoService";
048    public static final String KRMS_RULE_BO_SERVICE = "ruleBoService";
049    public static final String KRMS_AGENDA_AUTHORIZATION_SERVICE = "agendaAuthorizationService";
050    public static final String KRMS_REPOSITORY_TO_ENGINE_TRANSLATOR = "repositoryToEngineTranslator";
051    public static final String TYPE_TYPE_RELATION_BO_SERVICE = "typeTypeRelationBoService";
052
053        private static KrmsAttributeDefinitionService krmsAttributeDefinitionService;
054    private static ContextBoService contextBoService;
055    private static TermBoService termBoService;
056    private static AgendaBoService agendaBoService;
057    private static FunctionBoService functionBoService;
058    private static RuleBoService ruleBoService;
059    private static AgendaAuthorizationService agendaAuthorizationService;
060    private static KrmsTypeRepositoryService krmsTypeRepositoryService;
061    private static RepositoryToEngineTranslator krmsRepositoryToEngineTranslator;
062    private static TypeTypeRelationBoService typeTypeRelationBoService;
063
064    public static <T extends Object> T getService(String serviceName) {
065                return KrmsRepositoryServiceLocator.<T>getBean(serviceName);
066        }
067
068        public static <T extends Object> T getBean(String serviceName) {
069                if ( LOG.isDebugEnabled() ) {
070                        LOG.debug("Fetching service " + serviceName);
071                }
072                return GlobalResourceLoader.<T>getService(QName.valueOf(serviceName));
073        }
074
075    public static KrmsAttributeDefinitionService getKrmsAttributeDefinitionService() {
076                if ( krmsAttributeDefinitionService == null ) {
077                        krmsAttributeDefinitionService = getService(KRMS_ATTRIBUTE_DEFINITION_SERVICE);
078                }
079                return krmsAttributeDefinitionService;
080    }
081
082    public static CriteriaLookupService getCriteriaLookupService() {
083        return getService(CRITERIA_LOOKUP_SERVICE);
084    }
085
086        public static void setKrmsAttributeDefinitionService(final KrmsAttributeDefinitionService service) {
087                krmsAttributeDefinitionService = service;
088        }
089
090    public static ContextBoService getContextBoService() {
091        if (contextBoService == null) {
092            contextBoService = getService(KRMS_CONTEXT_BO_SERVICE);
093        }
094        return contextBoService;
095    }
096
097    public static TermBoService getTermBoService() {
098        if (termBoService == null) {
099            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}