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