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