01: /*
02: * Copyright 2001-2007 Hippo (www.hippo.nl)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package nl.hippo.util.components;
17:
18: import org.apache.avalon.framework.container.ContainerUtil;
19: import org.apache.avalon.framework.logger.Logger;
20: import org.apache.avalon.framework.service.ServiceException;
21: import org.apache.avalon.framework.service.ServiceManager;
22:
23: public class DynamicComponentLoader {
24:
25: private Logger m_logger;
26:
27: private ServiceManager m_manager;
28:
29: public DynamicComponentLoader() {
30: super ();
31: }
32:
33: public void setLogger(Logger logger) {
34: m_logger = logger;
35: }
36:
37: public void setServiceManager(ServiceManager manager) {
38: m_manager = manager;
39: }
40:
41: public Object load(String className) throws InstantiationException,
42: IllegalAccessException, ClassNotFoundException,
43: ServiceException {
44: Object result = Class.forName(className).newInstance();
45: if (result != null) {
46: ContainerUtil.enableLogging(result, m_logger);
47: ContainerUtil.service(result, m_manager);
48: }
49: return result;
50: }
51:
52: }
|