|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  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.KimTypeUtils;  | 
  |  24 |     | 
   import org.kuali.rice.kim.api.type.KimType;  | 
  |  25 |     | 
   import org.kuali.rice.kim.service.support.KimTypeService;  | 
  |  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 |     | 
     | 
  |  50 |     | 
     | 
  |  51 |     | 
     | 
  |  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 |     | 
     | 
  |  63 |     | 
     | 
  |  64 |     | 
     | 
  |  65 |     | 
     | 
  |  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 |     | 
                             | 
  |  76 |     | 
                             | 
  |  77 |     | 
     | 
  |  78 |    0 |                            LOG.error("Unable to find KIM type service with name: " + kimTypeServiceName, exception); | 
  |  79 |    0 |                            return null;  | 
  |  80 |     | 
                   }  | 
  |  81 |     | 
           }  | 
  |  82 |     | 
   }  |