001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.plugin.management;
018:
019: import java.util.List;
020:
021: import org.kuali.rice.resourceloader.GlobalResourceLoader;
022:
023: import edu.iu.uis.eden.plugin.Plugin;
024: import edu.iu.uis.eden.plugin.PluginEnvironment;
025: import edu.iu.uis.eden.plugin.PluginUtils;
026:
027: /**
028: * A Management bean for interfacing with the plugin architecture.
029: *
030: * @author Eric Westfall
031: */
032: public class PluginManager {
033:
034: public String fetchPlugins() {
035: List<PluginEnvironment> plugins = getPluginEnvironments();
036: if (plugins.isEmpty()) {
037: return "No Plugins Could be located in resource loaders:\n"
038: + GlobalResourceLoader.getResourceLoader()
039: .getContents("", true);
040: }
041: StringBuffer buffer = new StringBuffer();
042: buffer.append("| Name | Is Running | Is Reloadable |\n");
043: for (PluginEnvironment pluginEnvironment : plugins) {
044: buffer.append(renderPlugin(pluginEnvironment)).append("\n");
045: }
046: return buffer.toString();
047: }
048:
049: public void stopPlugin(String pluginName) {
050: PluginEnvironment pluginEnvironment = getPluginEnvironment(pluginName);
051: if (pluginEnvironment == null) {
052: throw new IllegalArgumentException(
053: "Could not locate plugin with the given name: "
054: + pluginName);
055: }
056: pluginEnvironment.getPlugin().stop();
057: }
058:
059: public void startPlugin(String pluginName) {
060: PluginEnvironment pluginEnvironment = getPluginEnvironment(pluginName);
061: if (pluginEnvironment == null) {
062: throw new IllegalArgumentException(
063: "Could not locate plugin with the given name: "
064: + pluginName);
065: }
066: pluginEnvironment.getPlugin().start();
067: }
068:
069: public void reloadPlugin(String pluginName) throws Exception {
070: PluginEnvironment pluginEnvironment = getPluginEnvironment(pluginName);
071: if (pluginEnvironment == null) {
072: throw new IllegalArgumentException(
073: "Could not locate plugin with the given name: "
074: + pluginName);
075: }
076: pluginEnvironment.reload();
077: }
078:
079: public int getHotDeployCheckFrequency() {
080: // TODO this needs implemented
081: return 0;
082: }
083:
084: public void setHotDeployCheckFrequency(int hotDeployCheckFrequency) {
085: // TODO this method needs implemented
086: }
087:
088: // TODO add various other attributes related to hot deployment
089:
090: protected PluginEnvironment getPluginEnvironment(String name) {
091: // first compare to QNames
092: for (PluginEnvironment pluginEnvironment : getPluginEnvironments()) {
093: Plugin plugin = pluginEnvironment.getPlugin();
094: if (name.equals(plugin.getName().toString())) {
095: return pluginEnvironment;
096: }
097: }
098: // now compare to local names
099: for (PluginEnvironment pluginEnvironment : getPluginEnvironments()) {
100: Plugin plugin = pluginEnvironment.getPlugin();
101: if (name.equals(plugin.getName().getLocalPart())) {
102: return pluginEnvironment;
103: }
104: }
105: return null;
106: }
107:
108: protected List<PluginEnvironment> getPluginEnvironments() {
109: return PluginUtils.getPluginRegistry().getPluginEnvironments();
110: }
111:
112: protected String renderPlugin(PluginEnvironment pluginEnvironment) {
113: return " | " + pluginEnvironment.getPlugin().getName() + " | "
114: + pluginEnvironment.getPlugin().isStarted() + " | "
115: + pluginEnvironment.isReloadable() + " | ";
116: }
117:
118: }
|