1 37 package net.sourceforge.cruisecontrol.interceptor; 38 39 import java.io.IOException ; 40 import java.util.Collection ; 41 import java.util.LinkedList ; 42 43 import javax.management.AttributeNotFoundException ; 44 import javax.management.InstanceNotFoundException ; 45 import javax.management.MBeanException ; 46 import javax.management.ReflectionException ; 47 48 import net.sourceforge.cruisecontrol.Configuration; 49 import net.sourceforge.cruisecontrol.CruiseControlException; 50 import net.sourceforge.cruisecontrol.PluginDetail; 51 import net.sourceforge.cruisecontrol.PluginType; 52 53 import org.jdom.JDOMException; 54 55 58 public class PluginLocator { 59 private Configuration configuration; 60 61 public PluginLocator(Configuration configuration) { 62 this.configuration = configuration; 63 } 64 65 public PluginDetail[] getAvailablePlugins(String type) throws AttributeNotFoundException , 66 InstanceNotFoundException , MBeanException , ReflectionException , IOException { 67 return getAvailablePlugins(PluginType.find(type)); 68 } 69 70 public PluginDetail[] getAvailablePlugins(PluginType type) throws ReflectionException , IOException , 71 InstanceNotFoundException , MBeanException , AttributeNotFoundException { 72 PluginDetail[] availablePlugins = configuration.getPluginDetails(); 73 Collection desiredPlugins = new LinkedList (); 74 for (int i = 0; i < availablePlugins.length; i++) { 75 PluginDetail nextPlugin = availablePlugins[i]; 76 77 if (nextPlugin.getType() == type) { 78 desiredPlugins.add(nextPlugin); 79 } 80 } 81 82 return (PluginDetail[]) desiredPlugins.toArray(new PluginDetail[desiredPlugins.size()]); 83 } 84 85 public PluginDetail[] getConfiguredPlugins(String project, String type) throws AttributeNotFoundException , 86 InstanceNotFoundException , MBeanException , ReflectionException , IOException , CruiseControlException, 87 JDOMException { 88 if ("listener".equals(type)) { 89 return configuration.getConfiguredListeners(project); 90 } else if ("bootstrapper".equals(type)) { 91 return configuration.getConfiguredBootstrappers(project); 92 } else if ("sourcecontrol".equals(type)) { 93 return configuration.getConfiguredSourceControls(project); 94 } else if ("builder".equals(type)) { 95 return configuration.getConfiguredBuilders(project); 96 } else if ("logger".equals(type)) { 97 return configuration.getConfiguredLoggers(project); 98 } else if ("publisher".equals(type)) { 99 return configuration.getConfiguredPublishers(project); 100 } else { 101 return null; 102 } 103 } 104 105 public PluginDetail getPluginDetail(String name, String type) throws AttributeNotFoundException , 106 InstanceNotFoundException , MBeanException , ReflectionException , IOException { 107 PluginDetail[] plugins = getAvailablePlugins(type); 108 for (int i = 0; i < plugins.length; i++) { 109 if (plugins[i].getName().equals(name)) { 110 return plugins[i]; 111 } 112 } 113 114 return null; 115 } 116 } 117 | Popular Tags |