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 edu.iu.uis.eden.plugin;
18:
19: import java.io.FileNotFoundException;
20: import java.io.IOException;
21:
22: import javax.xml.namespace.QName;
23:
24: import org.kuali.rice.core.Core;
25: import org.kuali.rice.resourceloader.ResourceLoader;
26:
27: import edu.iu.uis.eden.exception.InvalidXmlException;
28: import edu.iu.uis.eden.plugin.manifest.PluginManifest;
29: import edu.iu.uis.eden.plugin.manifest.PluginManifestParser;
30:
31: /**
32: * A {@link PluginLoader} which creates a {@link Plugin} with the given ClassLoader.
33: *
34: * <p>This PluginLoader is used in the cases where the Plugin's ClassLoader was created
35: * by the calling code and doesn't need to be created by the loader.
36: *
37: * @see Plugin
38: *
39: * @author ewestfal
40: */
41: public class ClassLoaderPluginLoader implements PluginLoader {
42:
43: private String pluginManifestPath;
44: private ClassLoader classLoader;
45:
46: public ClassLoaderPluginLoader(ClassLoader classLoader) {
47: this .classLoader = classLoader;
48: }
49:
50: public Plugin load() throws Exception {
51: //for now default the embedded plugin to the M.E. of the current context
52: QName name = new QName(Core.getCurrentContextConfig()
53: .getMessageEntity(), ResourceLoader.EMBEDDED_PLUGIN);
54: Plugin plugin = new Plugin(name,
55: loadPluginManifest(pluginManifestPath), classLoader);
56: plugin.bindThread();
57: try {
58: PluginUtils.installResourceLoader(plugin);
59: PluginUtils.installPluginListeners(plugin);
60: } finally {
61: plugin.unbindThread();
62: }
63: return plugin;
64: }
65:
66: public void setPluginManifestPath(String pluginManifestPath) {
67: this .pluginManifestPath = pluginManifestPath;
68: }
69:
70: public boolean isRemoved() {
71: return false;
72: }
73:
74: public boolean isModified() {
75: return false;
76: }
77:
78: private PluginManifest loadPluginManifest(String pluginManifestPath) {
79: PluginManifestParser parser = new PluginManifestParser();
80: try {
81: PluginManifest pluginManifest = parser.parse(classLoader
82: .getResource(pluginManifestPath), Core
83: .getCurrentContextConfig());
84: pluginManifest.parseConfig();
85: return pluginManifest;
86: } catch (FileNotFoundException e) {
87: throw new PluginException(
88: "Could not locate the plugin manifest file at path "
89: + pluginManifestPath, e);
90: } catch (IOException ioe) {
91: throw new PluginException(
92: "Could not read the plugin manifest file", ioe);
93: } catch (InvalidXmlException ixe) {
94: throw new PluginException(
95: "Could not parse the plugin manifest file", ixe);
96: }
97: }
98:
99: }
|