001: /*
002: * Copyright 2005-2006 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;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import javax.xml.namespace.QName;
023:
024: import org.kuali.rice.core.Core;
025: import org.kuali.rice.resourceloader.ResourceLoader;
026: import org.kuali.rice.resourceloader.ResourceLoaderContainer;
027:
028: import edu.emory.mathcs.backport.java.util.Collections;
029:
030: /**
031: * A base class for {@link PluginRegistry} implementations. Is essentially a ResourceLoader
032: * implementation that ensures plugins are the only ResourceLoaders used. Also maintains
033: * information about the PluginEnvironments of the loaded plugins in this registry.
034: *
035: * @see Plugin
036: * @see PluginEnvironment
037: *
038: * @author ewestfal
039: */
040: public abstract class BasePluginRegistry extends
041: ResourceLoaderContainer implements PluginRegistry {
042:
043: private List<PluginEnvironment> pluginEnvironments = Collections
044: .synchronizedList(new ArrayList<PluginEnvironment>());
045:
046: public BasePluginRegistry() {
047: super (new QName(Core.getCurrentContextConfig()
048: .getMessageEntity(),
049: ResourceLoader.PLUGIN_REGISTRY_LOADER_NAME));
050: }
051:
052: public BasePluginRegistry(QName name) {
053: super (name);
054: }
055:
056: public PluginEnvironment getPluginEnvironment(QName pluginName) {
057: for (PluginEnvironment environment : pluginEnvironments) {
058: if (environment.getPlugin().getName().equals(pluginName)) {
059: return environment;
060: }
061: }
062: return null;
063: }
064:
065: public void addPluginEnvironment(PluginEnvironment pluginEnvironment) {
066: // chances are that this plugin has already been added to the resource loader
067: if (!containsResourceLoader(pluginEnvironment.getPlugin())) {
068: addResourceLoader(pluginEnvironment.getPlugin());
069: }
070: pluginEnvironments.add(pluginEnvironment);
071: }
072:
073: public PluginEnvironment removePluginEnvironment(QName pluginName) {
074: super .removeResourceLoader(pluginName);
075: PluginEnvironment environment = getPluginEnvironment(pluginName);
076: if (environment == null) {
077: return null;
078: }
079: if (!pluginEnvironments.remove(environment)) {
080: return null;
081: }
082: return environment;
083: }
084:
085: public Plugin getPlugin(QName pluginName) {
086: return (Plugin) getResourceLoader(pluginName);
087: }
088:
089: public List<QName> getPluginNames() {
090: return super .getResourceLoaderNames();
091: }
092:
093: // public PluginEnvironment removePlugin(QName pluginName) {
094: // super.removeResourceLoader(pluginName);
095: // for (Iterator<PluginEnvironment> iterator = pluginEnvironments.iterator(); iterator.hasNext();) {
096: // PluginEnvironment environment = iterator.next();
097: // if (environment.getPlugin().getName().equals(pluginName)) {
098: // iterator.remove();
099: // return environment;
100: // }
101: // }
102: // return null;
103: // }
104:
105: public Plugin getInstitutionalPlugin() {
106: return null;
107: }
108:
109: public List<PluginEnvironment> getPluginEnvironments() {
110: return Collections.unmodifiableList(pluginEnvironments);
111: }
112: }
|