| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ResourceLoaderUtil |
|
| 8.0;8 |
| 1 | /* | |
| 2 | * Copyright 2005-2007 The Kuali Foundation | |
| 3 | * | |
| 4 | * | |
| 5 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
| 6 | * you may not use this file except in compliance with the License. | |
| 7 | * You may obtain a copy of the License at | |
| 8 | * | |
| 9 | * http://www.opensource.org/licenses/ecl2.php | |
| 10 | * | |
| 11 | * Unless required by applicable law or agreed to in writing, software | |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | * See the License for the specific language governing permissions and | |
| 15 | * limitations under the License. | |
| 16 | */ | |
| 17 | package org.kuali.rice.core.resourceloader; | |
| 18 | ||
| 19 | import org.apache.log4j.Logger; | |
| 20 | import org.kuali.rice.core.resourceloader.ResourceLoader; | |
| 21 | ||
| 22 | /** | |
| 23 | * A class for {@link ResourceLoader} related utilities. | |
| 24 | * | |
| 25 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 26 | */ | |
| 27 | 0 | public class ResourceLoaderUtil { |
| 28 | 0 | private static final Logger LOG = Logger.getLogger(ResourceLoaderUtil.class); |
| 29 | ||
| 30 | /** | |
| 31 | * Instantiates className class via no-arg constructor, and returns a proxy | |
| 32 | * that wraps invocations with the specified classLoader as the context classloader | |
| 33 | * @param className the class to instantiate | |
| 34 | * @param classLoader the classLoader to set as the context classloader | |
| 35 | * @return a proxy that wraps an instance with code that sets and unsets the appropriate context classloader | |
| 36 | */ | |
| 37 | public static Object createObject(String className, ClassLoader classLoader) { | |
| 38 | try { | |
| 39 | 0 | Class theClass = Class.forName(className, true, classLoader); |
| 40 | 0 | return ContextClassLoaderProxy.wrap(theClass.newInstance()); |
| 41 | 0 | } catch (ClassNotFoundException e) { |
| 42 | 0 | LOG.error("Error instantiating class '" + className + "' in classloader " + classLoader, e); |
| 43 | 0 | return null; |
| 44 | 0 | } catch (InstantiationException e) { |
| 45 | 0 | throw new ResourceLoaderException(e); |
| 46 | 0 | } catch (IllegalAccessException e) { |
| 47 | 0 | throw new ResourceLoaderException(e); |
| 48 | } | |
| 49 | } | |
| 50 | ||
| 51 | } |