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.kim.framework.services; 017 018import org.apache.log4j.Logger; 019import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; 020import org.kuali.rice.kim.api.type.KimType; 021import org.kuali.rice.kim.api.type.KimTypeUtils; 022import org.kuali.rice.kim.framework.type.KimTypeService; 023 024import javax.xml.namespace.QName; 025 026public class KimFrameworkServiceLocator { 027 private static final Logger LOG = Logger.getLogger(KimFrameworkServiceLocator.class); 028 029 static <T> T getService(String serviceName) { 030 return GlobalResourceLoader.<T>getService(serviceName); 031 } 032 033 /** 034 * Fetches the KimTypeService for the given KimType If the kimType passed in is null 035 * then this method will return null. This method will resolve the kimTypeServiceName 036 * on the given KimType and then delegate to {@link #getKimTypeService(javax.xml.namespace.QName)}. 037 */ 038 public static KimTypeService getKimTypeService(KimType kimType) { 039 if( kimType == null ) { 040 throw new IllegalArgumentException("Invalid service name passed, value was null."); 041 } 042 return getKimTypeService(KimTypeUtils.resolveKimTypeServiceName(kimType.getServiceName())); 043 } 044 045 /** 046 * Fetches the KimTypeService for the given kim type service name. If the given {@link javax.xml.namespace.QName} 047 * is null, then this method will throw an IllegalArgumentException. 048 * 049 * @throws IllegalArgumentException if the given kimTypeServiceName is null 050 */ 051 public static KimTypeService getKimTypeService(QName kimTypeServiceName) { 052 if (kimTypeServiceName == null) { 053 throw new IllegalArgumentException("Invalid service name passed, value was null."); 054 } 055 try { 056 return (KimTypeService) GlobalResourceLoader.getService(kimTypeServiceName); 057 } catch (Exception exception) { 058 059 // if we get an exception loading the remote KimTypeService, then instead of completly failing, 060 // we'll handle the exception and return a null reference to the service 061 062 LOG.error("Unable to find KIM type service with name: " + kimTypeServiceName, exception); 063 return null; 064 } 065 } 066}