View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.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 org.kuali.rice.kew.plugin;
18  
19  import java.util.ArrayList;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import javax.xml.namespace.QName;
24  
25  import org.kuali.rice.core.config.ConfigContext;
26  import org.kuali.rice.core.resourceloader.ResourceLoader;
27  import org.kuali.rice.core.resourceloader.ResourceLoaderContainer;
28  
29  /**
30   * A base class for {@link PluginRegistry} implementations.  Is essentially a ResourceLoader 
31   * implementation that ensures plugins are the only ResourceLoaders used.  Also maintains
32   * information about the PluginEnvironments of the loaded plugins in this registry.
33   * 
34   * @see Plugin
35   * @see PluginEnvironment
36   * 
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  public abstract class BasePluginRegistry extends ResourceLoaderContainer implements PluginRegistry {
40  	
41  	private List<PluginEnvironment> pluginEnvironments = Collections.synchronizedList(new ArrayList<PluginEnvironment>());
42  	
43  	public BasePluginRegistry() {
44  		super(new QName(ConfigContext.getCurrentContextConfig().getServiceNamespace(), ResourceLoader.PLUGIN_REGISTRY_LOADER_NAME));
45  	}
46  	
47  	public BasePluginRegistry(QName name) {
48  		super(name);
49  	}
50  	    
51      public PluginEnvironment getPluginEnvironment(String pluginName) {
52      	for (PluginEnvironment environment : pluginEnvironments) {
53      		if (environment.getPluginName().equals(pluginName)) {
54      			return environment;
55      		}
56      	}
57      	return null;
58      }
59  	
60  	public void addPluginEnvironment(PluginEnvironment pluginEnvironment) {
61  		// chances are that this plugin has already been added to the resource loader
62  		if (pluginEnvironment.getPlugin() != null && !containsResourceLoader(pluginEnvironment.getPlugin())) {
63  			addResourceLoader(pluginEnvironment.getPlugin());
64  		}
65  		pluginEnvironments.add(pluginEnvironment);
66  	}
67  	
68  	public PluginEnvironment removePluginEnvironment(String pluginName) {
69  	    PluginEnvironment environment = getPluginEnvironment(pluginName);
70          if (environment == null) {
71              return null;
72          }
73          if (environment.getPlugin() != null) {
74              super.removeResourceLoader(environment.getPlugin().getName());
75          }
76  		if (!pluginEnvironments.remove(environment)) {
77  			return null;
78  		}
79  		return environment;
80  	}
81  
82  	public Plugin getPlugin(QName pluginName) {
83  		return (Plugin)getResourceLoader(pluginName);
84  	}
85  
86  	public List<QName> getPluginNames() {
87  		return super.getResourceLoaderNames();
88  	}
89  	
90  	public List<PluginEnvironment> getPluginEnvironments() {
91  		return Collections.unmodifiableList(pluginEnvironments);
92  	}
93  }