Coverage Report - org.kuali.rice.kew.plugin.BasePluginRegistry
 
Classes in this File Line Coverage Branch Coverage Complexity
BasePluginRegistry
0%
0/24
0%
0/14
2.25
 
 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  0
         private List<PluginEnvironment> pluginEnvironments = Collections.synchronizedList(new ArrayList<PluginEnvironment>());
 42  
         
 43  
         public BasePluginRegistry() {
 44  0
                 super(new QName(ConfigContext.getCurrentContextConfig().getServiceNamespace(), ResourceLoader.PLUGIN_REGISTRY_LOADER_NAME));
 45  0
         }
 46  
         
 47  
         public BasePluginRegistry(QName name) {
 48  0
                 super(name);
 49  0
         }
 50  
             
 51  
     public PluginEnvironment getPluginEnvironment(String pluginName) {
 52  0
             for (PluginEnvironment environment : pluginEnvironments) {
 53  0
                     if (environment.getPluginName().equals(pluginName)) {
 54  0
                             return environment;
 55  
                     }
 56  
             }
 57  0
             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  0
                 if (pluginEnvironment.getPlugin() != null && !containsResourceLoader(pluginEnvironment.getPlugin())) {
 63  0
                         addResourceLoader(pluginEnvironment.getPlugin());
 64  
                 }
 65  0
                 pluginEnvironments.add(pluginEnvironment);
 66  0
         }
 67  
         
 68  
         public PluginEnvironment removePluginEnvironment(String pluginName) {
 69  0
             PluginEnvironment environment = getPluginEnvironment(pluginName);
 70  0
         if (environment == null) {
 71  0
             return null;
 72  
         }
 73  0
         if (environment.getPlugin() != null) {
 74  0
             super.removeResourceLoader(environment.getPlugin().getName());
 75  
         }
 76  0
                 if (!pluginEnvironments.remove(environment)) {
 77  0
                         return null;
 78  
                 }
 79  0
                 return environment;
 80  
         }
 81  
 
 82  
         public Plugin getPlugin(QName pluginName) {
 83  0
                 return (Plugin)getResourceLoader(pluginName);
 84  
         }
 85  
 
 86  
         public List<QName> getPluginNames() {
 87  0
                 return super.getResourceLoaderNames();
 88  
         }
 89  
         
 90  
         public List<PluginEnvironment> getPluginEnvironments() {
 91  0
                 return Collections.unmodifiableList(pluginEnvironments);
 92  
         }
 93  
 }