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 javax.xml.namespace.QName;
20:
21: import org.apache.commons.lang.StringUtils;
22: import org.kuali.rice.config.Config;
23: import org.kuali.rice.core.Core;
24:
25: import edu.iu.uis.eden.util.ClassLoaderUtils;
26:
27: /**
28: * A PluginRegistry implementation which loads the embedded plugin from the classpath
29: * and loads a plugin manifest based on the client's protocol configuration.
30: *
31: * @author Eric Westfall
32: */
33: public class ClientProtocolPluginRegistry extends BasePluginRegistry {
34:
35: private static final String DEFAULT_EMBEDDED_PLUGIN_LOCATION = "classpath:embedded";
36:
37: public ClientProtocolPluginRegistry(QName name) {
38: super (name);
39: }
40:
41: public void start() throws Exception {
42: Config config = Core.getCurrentContextConfig();
43: String pluginName = "embedded";
44: PluginLoader loader = null;
45: String embeddedPluginLocation = getEmbeddedPluginLocation();
46: String path = getPath(embeddedPluginLocation);
47: if (isDeferToCurrentClassLoader()) {
48: loader = new ClassLoaderPluginLoader(ClassLoaderUtils
49: .getDefaultClassLoader());
50: } else if (isClasspath(embeddedPluginLocation)) {
51: loader = new ClasspathPluginLoader(pluginName, path, null,
52: ClassLoaderUtils.getDefaultClassLoader(), Core
53: .getCurrentContextConfig(), false);
54: } else {
55: throw new PluginException(
56: "Failed to start the embedded plugin because the embedded plugin location is invalid, value was: "
57: + embeddedPluginLocation);
58: }
59: loader.setPluginManifestPath("META-INF/"
60: + config.getClientProtocol() + "-workflow.xml");
61: PluginEnvironment environment = new PluginEnvironment(loader,
62: this );
63: environment.setSupressStartupFailure(false);
64: environment.load();
65: // Plugin plugin = loader.load();
66: // PluginUtils.installResourceLoader(plugin);
67: // PluginUtils.installPluginListeners(plugin);
68: // plugin.setSupressStartupFailure(false);
69: addPluginEnvironment(environment);
70: super .start();
71: }
72:
73: protected String getEmbeddedPluginLocation() {
74: String embeddedPluginLocation = Core.getCurrentContextConfig()
75: .getEmbeddedPluginLocation();
76: if (StringUtils.isEmpty(embeddedPluginLocation)) {
77: embeddedPluginLocation = DEFAULT_EMBEDDED_PLUGIN_LOCATION;
78: }
79: return embeddedPluginLocation;
80: }
81:
82: protected boolean isDeferToCurrentClassLoader() {
83: return new Boolean(Core.getCurrentContextConfig().getProperty(
84: Config.EMBEDDED_PLUGIN_DEFAULT_CURRENT_CLASS_LOADER));
85: }
86:
87: protected boolean isClasspath(String location) {
88: return location.startsWith("classpath:");
89: }
90:
91: protected boolean isFile(String location) {
92: return location.startsWith("file:");
93: }
94:
95: protected String getPath(String location) {
96: return location.substring(location.indexOf(":") + 1);
97: }
98: }
|