001    /*
002     * Copyright 2011 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 1.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/ecl1.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     */
016    package org.kuali.rice.krms.impl.util;
017    
018    import javax.xml.namespace.QName;
019    
020    import org.apache.log4j.Logger;
021    import org.kuali.rice.core.api.config.module.RunMode;
022    import org.kuali.rice.core.api.config.property.ConfigContext;
023    import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
024    
025    /**
026     * This is a description of what this class does - gilesp don't forget to fill this in. 
027     * 
028     * @author Kuali Rice Team (rice.collab@kuali.org)
029     *
030     */
031    public class KRMSServiceLocatorInternal {
032            
033            public static final String KRMS_RUN_MODE_PROPERTY = "krms.mode";
034            public static final String KRMS_MODULE_NAMESPACE = "KRMS";
035            
036            private static final Logger LOG = Logger.getLogger(KRMSServiceLocatorInternal.class);
037    
038            
039            @SuppressWarnings("unchecked")
040            public static <A> A getService(String serviceName) {
041                    return (A)getBean(serviceName);
042            }
043            
044            public static Object getBean(String serviceName) {
045                    if ( LOG.isDebugEnabled() ) {
046                            LOG.debug("Fetching service " + serviceName);
047                    }
048                    return GlobalResourceLoader.getResourceLoader().getService(
049                                    (RunMode.REMOTE.equals(RunMode.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KRMS_RUN_MODE_PROPERTY)))) ?
050                                                    new QName(KRMS_MODULE_NAMESPACE, serviceName) : new QName(serviceName) );
051            }
052            
053    //    public static BusinessObjectService getBusinessObjectService() {
054    //      return getService(KRMS_BO_SERVICE);
055    //    }
056            
057    }