1 37 package net.sourceforge.cruisecontrol.interceptor; 38 39 import java.io.IOException ; 40 import java.util.Map ; 41 42 import javax.management.AttributeNotFoundException ; 43 import javax.management.InstanceNotFoundException ; 44 import javax.management.MBeanException ; 45 import javax.management.ReflectionException ; 46 47 import org.jdom.JDOMException; 48 49 import net.sourceforge.cruisecontrol.Configuration; 50 import net.sourceforge.cruisecontrol.CruiseControlException; 51 import net.sourceforge.cruisecontrol.PluginDetail; 52 53 import com.opensymphony.xwork.Action; 54 import com.opensymphony.xwork.ActionContext; 55 import com.opensymphony.xwork.ActionInvocation; 56 import com.opensymphony.xwork.interceptor.AroundInterceptor; 57 58 61 public class PluginsInterceptor extends AroundInterceptor { 62 protected void before(ActionInvocation invocation) throws Exception { 63 Action action = invocation.getAction(); 64 65 if (action instanceof PluginsAware) { 66 ActionContext invocationContext = invocation.getInvocationContext(); 67 Map parameters = invocationContext.getParameters(); 68 69 String pluginType = ((String []) parameters.get("pluginType"))[0]; 70 if (pluginType != null) { 71 PluginsAware pluginsAction = (PluginsAware) action; 72 Configuration configuration = getConfiguration(invocationContext); 73 PluginLocator locator = new PluginLocator(configuration); 74 75 pluginsAction.setAvailablePlugins(getAvailablePlugins(locator, pluginType)); 76 Map session = invocation.getInvocationContext().getSession(); 77 pluginsAction.setConfiguredPlugins(getConfiguredPlugins(locator, pluginType, 78 (String ) session.get("project"))); 79 } 80 } 81 } 82 83 protected void after(ActionInvocation dispatcher, String result) throws Exception { 84 } 85 86 private PluginDetail[] getAvailablePlugins(PluginLocator locator, String pluginType) 87 throws AttributeNotFoundException , InstanceNotFoundException , MBeanException , ReflectionException , 88 IOException { 89 return locator.getAvailablePlugins(pluginType); 90 } 91 92 private PluginDetail[] getConfiguredPlugins(PluginLocator locator, String pluginType, String project) 93 throws AttributeNotFoundException , InstanceNotFoundException , MBeanException , ReflectionException , 94 IOException , CruiseControlException, JDOMException { 95 if (project != null) { 96 return locator.getConfiguredPlugins(project, pluginType); 97 } 98 99 return null; 100 } 101 102 private Configuration getConfiguration(ActionContext invocationContext) { 103 return (Configuration) invocationContext.getSession().get("cc-configuration"); 104 } 105 } 106 | Popular Tags |