Coverage Report - org.kuali.rice.kim.service.KIMServiceLocatorWeb
 
Classes in this File Line Coverage Branch Coverage Complexity
KIMServiceLocatorWeb
0%
0/17
0%
0/8
2.6
 
 1  
 /*
 2  
  * Copyright 2006-2011 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  
 
 17  
 package org.kuali.rice.kim.service;
 18  
 
 19  
 import org.apache.log4j.Logger;
 20  
 import org.kuali.rice.core.api.config.module.RunMode;
 21  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 22  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 23  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 24  
 import org.kuali.rice.kim.bo.KimType;
 25  
 import org.kuali.rice.kim.service.support.KimTypeService;
 26  
 import org.kuali.rice.kim.util.KimCommonUtils;
 27  
 import org.kuali.rice.kim.util.KimConstants;
 28  
 
 29  
 import javax.xml.namespace.QName;
 30  
 
 31  0
 public class KIMServiceLocatorWeb {
 32  0
     private static final Logger LOG = Logger.getLogger(KIMServiceLocatorWeb.class);
 33  
 
 34  
     public static final String KIM_RUN_MODE_PROPERTY = "kim.mode";
 35  
     public static final String KIM_TYPE_INFO_SERVICE = "kimTypeInfoService";
 36  
 
 37  
     public static Object getService(String serviceName) {
 38  0
         return getBean(serviceName);
 39  
     }
 40  
 
 41  
     public static Object getBean(String serviceName) {
 42  0
         if (LOG.isDebugEnabled()) {
 43  0
             LOG.debug("Fetching service " + serviceName);
 44  
         }
 45  0
         return GlobalResourceLoader.getResourceLoader().getService(
 46  
                 (RunMode.REMOTE.equals(RunMode.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KIM_RUN_MODE_PROPERTY)))) ?
 47  
                         new QName(KimConstants.KIM_MODULE_NAMESPACE, serviceName) : new QName(serviceName));
 48  
     }
 49  
 
 50  
         /**
 51  
          * Fetches the KimTypeService for the given KimType  If the kimType passed in is null
 52  
          * then this method will return null.  This method will resolve the kimTypeServiceName
 53  
          * on the given KimType and then delegate to {@link #getKimTypeService(QName)}.
 54  
          */
 55  
         public static KimTypeService getKimTypeService(KimType kimType) {
 56  0
                 if( kimType == null ) {
 57  0
                         LOG.warn( "null KimType passed into getKimTypeService" );
 58  0
                         return null;
 59  
                 }
 60  0
                 return getKimTypeService(KimCommonUtils.resolveKimTypeServiceName(kimType.getKimTypeServiceName()));
 61  
         }
 62  
 
 63  
         /**
 64  
          * Fetches the KimTypeService for the given kim type service name.  If the given {@link QName}
 65  
          * is null, then this method will throw an IllegalArgumentException.
 66  
          *
 67  
          * @throws IllegalArgumentException if the given kimTypeServiceName is null
 68  
          */
 69  
         public static KimTypeService getKimTypeService(QName kimTypeServiceName) {
 70  0
                 if (kimTypeServiceName == null) {
 71  0
                         throw new IllegalArgumentException("Invalid service name passed, value was null.");
 72  
                 }
 73  
                 try {
 74  0
                         return (KimTypeService) GlobalResourceLoader.getService(kimTypeServiceName);
 75  0
                 } catch (Exception exception) {
 76  
 
 77  
                         // if we get an exception loading the remote KimTypeService, then instead of completly failing,
 78  
                         // we'll handle the exception and return a null reference to the service
 79  
 
 80  0
                         LOG.error("Unable to find KIM type service with name: " + kimTypeServiceName, exception);
 81  0
                         return null;
 82  
                 }
 83  
         }
 84  
 
 85  
     public static KimTypeInfoService getTypeInfoService() {
 86  0
         return (KimTypeInfoService) getService(KIM_TYPE_INFO_SERVICE);
 87  
     }
 88  
 }