1 37 package net.sourceforge.cruisecontrol.interceptor; 38 39 import java.io.IOException ; 40 import java.net.InetAddress ; 41 import java.util.Map ; 42 43 import javax.management.MalformedObjectNameException ; 44 45 import net.sourceforge.cruisecontrol.Configuration; 46 47 import com.opensymphony.xwork.Action; 48 import com.opensymphony.xwork.ActionInvocation; 49 import com.opensymphony.xwork.interceptor.AroundInterceptor; 50 51 54 public class ConfigurationInterceptor extends AroundInterceptor { 55 protected void before(ActionInvocation invocation) throws Exception { 56 Action action = invocation.getAction(); 57 58 Map parameters = invocation.getInvocationContext().getParameters(); 59 if (parameters.get("project") != null) { 60 Map session = invocation.getInvocationContext().getSession(); 61 session.put("project", ((String []) parameters.get("project"))[0]); 62 } 63 64 Configuration configuration = getConfiguration(invocation); 65 66 if (action instanceof ConfigurationAware) { 67 ((ConfigurationAware) action).setConfiguration(configuration); 68 } 69 } 70 71 protected void after(ActionInvocation dispatcher, String result) throws Exception { 72 } 73 74 private Configuration createConfiguration() throws IOException , MalformedObjectNameException { 75 int rmiPort = Integer.parseInt(System.getProperty("cruisecontrol.rmiport")); 76 Configuration configuration = new Configuration(getJMXServer(), rmiPort); 77 return configuration; 78 } 79 80 private Configuration getConfiguration(ActionInvocation invocation) 81 throws IOException , MalformedObjectNameException { 82 Map session = invocation.getInvocationContext().getSession(); 83 Configuration configuration = (Configuration) session.get("cc-configuration"); 84 85 if (configuration == null) { 86 configuration = createConfiguration(); 87 session.put("cc-configuration", configuration); 88 invocation.getInvocationContext().setSession(session); 89 } 90 91 return configuration; 92 } 93 94 private String getJMXServer() { 95 String jmxServer; 96 try { 97 jmxServer = InetAddress.getLocalHost().getHostName(); 98 } catch (IOException e) { 99 jmxServer = "localhost"; 100 } 101 return jmxServer; 102 } 103 } 104 | Popular Tags |