Coverage Report - org.kuali.rice.kew.plugin.ClassLoaderPluginLoader
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassLoaderPluginLoader
0%
0/27
N/A
2
 
 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.io.FileNotFoundException;
 20  
 import java.io.IOException;
 21  
 
 22  
 import javax.xml.namespace.QName;
 23  
 
 24  
 import org.kuali.rice.core.config.ConfigContext;
 25  
 import org.kuali.rice.core.resourceloader.ResourceLoader;
 26  
 import org.kuali.rice.kew.exception.InvalidXmlException;
 27  
 
 28  
 
 29  
 /**
 30  
  * A {@link PluginLoader} which creates a {@link Plugin} with the given ClassLoader.
 31  
  * 
 32  
  * <p>This PluginLoader is used in the cases where the Plugin's ClassLoader was created 
 33  
  * by the calling code and doesn't need to be created by the loader.
 34  
  * 
 35  
  * @see Plugin
 36  
  *
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  */
 39  
 public class ClassLoaderPluginLoader implements PluginLoader {
 40  
         
 41  
         private String pluginConfigPath;
 42  
         private ClassLoader classLoader;
 43  
         
 44  0
         public ClassLoaderPluginLoader(ClassLoader classLoader) {
 45  0
                 this.classLoader = classLoader;
 46  0
         }
 47  
         
 48  
         public String getPluginName() {
 49  0
             return ResourceLoader.EMBEDDED_PLUGIN;
 50  
         }
 51  
         
 52  
         public Plugin load() throws Exception {
 53  
                 //for now default the embedded plugin to the M.E. of the current context
 54  0
                 QName name = new QName(ConfigContext.getCurrentContextConfig().getServiceNamespace(), ResourceLoader.EMBEDDED_PLUGIN);
 55  0
                 Plugin plugin = new Plugin(name, loadPluginConfig(pluginConfigPath), classLoader);
 56  0
                 plugin.bindThread();
 57  
                 try {
 58  0
                         PluginUtils.installResourceLoader(plugin);
 59  0
                         PluginUtils.installPluginListeners(plugin);
 60  0
                 } finally {
 61  0
                         plugin.unbindThread();
 62  0
                 }
 63  0
                 return plugin;
 64  
         }
 65  
 
 66  
         public void setPluginConfigPath(String pluginConfigPath) {
 67  0
                 this.pluginConfigPath = pluginConfigPath;
 68  0
         }
 69  
         
 70  
         public boolean isRemoved() {
 71  0
                 return false;
 72  
         }
 73  
         
 74  
         public boolean isModified() {
 75  0
                 return false;
 76  
         }
 77  
 
 78  
     private PluginConfig loadPluginConfig(String pluginConfigPath) {
 79  0
         PluginConfigParser parser = new PluginConfigParser();
 80  
         try {
 81  0
             PluginConfig pluginConfig  = parser.parse(classLoader.getResource(pluginConfigPath), ConfigContext.getCurrentContextConfig());
 82  0
             pluginConfig.parseConfig();
 83  0
             return pluginConfig;
 84  0
         } catch (FileNotFoundException e) {
 85  0
             throw new PluginException("Could not locate the plugin config file at path " + pluginConfigPath, e);
 86  0
         } catch (IOException ioe) {
 87  0
             throw new PluginException("Could not read the plugin config file", ioe);
 88  0
         } catch (InvalidXmlException ixe) {
 89  0
             throw new PluginException("Could not parse the plugin config file", ixe);
 90  
         }
 91  
     }
 92  
         
 93  
 }