01: /*
02: * This file is part of "SnipSnap Radeox Rendering Engine".
03: *
04: * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
05: * All Rights Reserved.
06: *
07: * Please visit http://radeox.org/ for updates and contact.
08: *
09: * --LICENSE NOTICE--
10: * Licensed under the Apache License, Version 2.0 (the "License");
11: * you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software
17: * distributed under the License is distributed on an "AS IS" BASIS,
18: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19: * See the License for the specific language governing permissions and
20: * limitations under the License.
21: * --LICENSE NOTICE--
22: */
23:
24: package org.radeox.macro;
25:
26: import java.util.Iterator;
27:
28: import org.apache.commons.logging.Log;
29: import org.apache.commons.logging.LogFactory;
30: import org.radeox.util.Service;
31:
32: /**
33: * Plugin loader
34: *
35: * @author Stephan J. Schmidt
36: * @version $Id: PluginLoader.java 7756 2006-04-13 12:25:49Z ian@caret.cam.ac.uk $
37: */
38:
39: public abstract class PluginLoader {
40: private static Log log = LogFactory.getLog(PluginLoader.class);
41:
42: protected Repository repository;
43:
44: public Repository loadPlugins(Repository repository) {
45: return loadPlugins(repository, getLoadClass());
46: }
47:
48: public void setRepository(Repository repository) {
49: this .repository = repository;
50: }
51:
52: public Iterator getPlugins(Class klass) {
53: return Service.providers(klass);
54: }
55:
56: public Repository loadPlugins(Repository repository, Class klass) {
57: if (null != repository) {
58: /* load all macros found in the services plugin control file */
59: Iterator iterator = getPlugins(klass);
60: while (iterator.hasNext()) {
61: try {
62: Object plugin = iterator.next();
63: add(repository, plugin);
64: log.debug("PluginLoader: Loaded plugin: "
65: + plugin.getClass());
66: } catch (Exception e) {
67: log.warn("PluginLoader: unable to load plugin", e);
68: }
69: }
70: }
71: return repository;
72: }
73:
74: /**
75: * Add a plugin to the known plugin map
76: *
77: * @param plugin
78: * Plugin to add
79: */
80: public abstract void add(Repository repository, Object plugin);
81:
82: public abstract Class getLoadClass();
83: }
|