01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.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.resourceloader;
18:
19: import org.apache.log4j.Logger;
20:
21: /**
22: * A class for {@link ResourceLoader} related utilities.
23: *
24: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
25: */
26: public class ResourceLoaderUtil {
27: private static final Logger LOG = Logger
28: .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,
38: ClassLoader classLoader) {
39: try {
40: Class theClass = Class
41: .forName(className, true, classLoader);
42: return ContextClassLoaderProxy.wrap(theClass.newInstance());
43: } catch (ClassNotFoundException e) {
44: LOG.error("Error instantiating class '" + className
45: + "' in classloader " + classLoader, e);
46: return null;
47: } catch (InstantiationException e) {
48: throw new ResourceLoaderException(e);
49: } catch (IllegalAccessException e) {
50: throw new ResourceLoaderException(e);
51: }
52: }
53:
54: }
|