Author: veithen
Date: Fri May 29 14:16:09 2009
New Revision: 779987

URL: http://svn.apache.org/viewvc?rev=779987&view=rev
Log:
Some refactorings to reduce coupling between classes.

Modified:
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/AdminPane.java
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java
    
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/TCPMon.java

Modified: 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java?rev=779987&r1=779986&r2=779987&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java
 (original)
+++ 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java
 Fri May 29 14:16:09 2009
@@ -61,29 +61,30 @@
 
     public final Vector requestResponses = new Vector();
 
-    public String HTTPProxyHost = null;
-    public int HTTPProxyPort = 80;
+    private String HTTPProxyHost = null;
+    private int HTTPProxyPort = 80;
 
-    public Listener(TabFolder tabFolder, String name, int listenPort,
-                    String host, int targetPort, boolean isProxy,
-                    ThrottleConfiguration throttleConfig) {
+    public Listener(TabFolder tabFolder, String name,
+                    Configuration config) {
         if (name == null) {
-            name = TCPMonBundle.getMessage("port01", "Port") + " " + 
listenPort;
+            name = TCPMonBundle.getMessage("port01", "Port") + " " + 
config.getListenPort();
         }
         // set the slow link to the passed down link
         if (throttleConfig != null) {
-            this.throttleConfig = throttleConfig;
+            this.throttleConfig = config.getThrottleConfiguration();
         } else {
             // or make up a no-op one.
             this.throttleConfig = new ThrottleConfiguration(0, 0);
         }
+        HTTPProxyHost = config.getHttpProxyHost();
+        HTTPProxyPort = config.getHttpProxyPort();
 
         this.tabFolder = tabFolder;
-        createPortTab(isProxy, listenPort, host, targetPort);
+        createPortTab(config);
 
     }
 
-    public void createPortTab(boolean isProxy, int listenPort, String host, 
int targetPort) {
+    public void createPortTab(Configuration config) {
         portTabItem = new TabItem(tabFolder, SWT.NONE);
 
         final Composite composite = new Composite(tabFolder, SWT.NONE);
@@ -106,7 +107,7 @@
         listenPortLabel.setText(TCPMonBundle.getMessage("listenPort01", 
"Listen Port:"));
 
         portField = new Text(composite, SWT.BORDER);
-        portField.setText("" + listenPort);
+        portField.setText("" + config.getListenPort());
         gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
         gd.widthHint = 40;
         portField.setLayoutData(gd);
@@ -114,7 +115,7 @@
         (new Label(composite, 
SWT.NONE)).setText(TCPMonBundle.getMessage("host00", "Host:"));
 
         hostField = new Text(composite, SWT.BORDER);
-        hostField.setText(host);
+        hostField.setText(config.getTargetHost());
         gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
         gd.widthHint = 202;
         hostField.setLayoutData(gd);
@@ -122,7 +123,7 @@
         (new Label(composite, 
SWT.NONE)).setText(TCPMonBundle.getMessage("port02", "Port:"));
 
         tPortField = new Text(composite, SWT.BORDER);
-        tPortField.setText("" + targetPort);
+        tPortField.setText("" + config.getTargetPort());
         gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
         gd.widthHint = 40;
         tPortField.setLayoutData(gd);
@@ -141,7 +142,7 @@
                 hostField.setEnabled(!state);
             }
         });
-        isProxyBox.setSelection(isProxy);
+        isProxyBox.setSelection(config.isProxy());
         portField.setEditable(false);
         hostField.setEditable(false);
         tPortField.setEditable(false);

Modified: 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java?rev=779987&r1=779986&r2=779987&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java
 (original)
+++ 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java
 Fri May 29 14:16:09 2009
@@ -17,6 +17,7 @@
 
 
 import org.apache.ws.commons.tcpmon.TCPMonBundle;
+import org.apache.ws.commons.tcpmon.core.Configuration;
 import org.apache.ws.commons.tcpmon.core.filter.throttle.ThrottleConfiguration;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
@@ -105,41 +106,16 @@
         addButton.addSelectionListener(new SelectionAdapter() {
             public void widgetSelected(final SelectionEvent e) {
                 if (add.equals(((Button) e.getSource()).getText())) {
-                    String text;
-                    Listener l = null;
-                    int lPort;
-                    lPort = getValue(0, port.getText());
-                    if (lPort == 0) {
+                    Configuration config = getConfiguration();
+                    if (config == null) {
                         return;
                     }
-                    String tHost = host.getText();
-                    int tPort;
-                    tPort = getValue(0, tport.getText());
-                    ThrottleConfiguration throttleConfig = null;
-                    if (delayBox.getSelection()) {
-                        int bytes = getValue(0, delayBytes.getText());
-                        int time = getValue(0, delayTime.getText());
-                        throttleConfig = new ThrottleConfiguration(bytes, 
time);
-                    }
                     try {
-                        l = new Listener(tabFolder, null, lPort, tHost, tPort,
-                                proxyButton.getSelection(),
-                                throttleConfig);
+                        new Listener(tabFolder, null, config);
                     } catch (Exception exp) {
                         exp.printStackTrace();
                     }
 
-                    text = hTTPProxyHost.getText();
-                    if ("".equals(text)) {
-                        text = null;
-                    }
-
-                    l.HTTPProxyHost = text;
-                    text = hTTPProxyPort.getText();
-                    int proxyPort = getValue(-1, hTTPProxyPort.getText());
-                    if (proxyPort != -1) {
-                        l.HTTPProxyPort = Integer.parseInt(text);
-                    }
                     port.setText("");
                 }
             }
@@ -147,6 +123,35 @@
         configTab.setControl(composite);
     }
 
+    private Configuration getConfiguration() {
+        Configuration config = new Configuration();
+        
+        int lPort = getValue(0, port.getText());
+        if (lPort == 0) {
+            return null;
+        }
+        config.setListenPort(lPort);
+        config.setProxy(proxyButton.getSelection());
+        config.setTargetHost(host.getText());
+        config.setTargetPort(getValue(0, tport.getText()));
+        ThrottleConfiguration throttleConfig = null;
+        if (delayBox.getSelection()) {
+            throttleConfig = new ThrottleConfiguration(getValue(0, 
delayBytes.getText()), getValue(0, delayTime.getText()));
+        }
+        config.setThrottleConfiguration(throttleConfig);
+        
+        String text = hTTPProxyHost.getText();
+        if (text.length() > 0) {
+            config.setHttpProxyHost(text);
+        }
+        text = hTTPProxyPort.getText();
+        int proxyPort = getValue(-1, hTTPProxyPort.getText());
+        if (proxyPort != -1) {
+            config.setHttpProxyPort(Integer.parseInt(text));
+        }
+        
+        return config;
+    }
 
     private void addActAsOptions(Composite composite) {
         GridData gd = new GridData();

Modified: 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/AdminPane.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/AdminPane.java?rev=779987&r1=779986&r2=779987&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/AdminPane.java
 (original)
+++ 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/AdminPane.java
 Fri May 29 14:16:09 2009
@@ -32,6 +32,7 @@
 import javax.swing.text.Document;
 import javax.swing.text.PlainDocument;
 
+import org.apache.ws.commons.tcpmon.core.Configuration;
 import org.apache.ws.commons.tcpmon.core.filter.throttle.ThrottleConfiguration;
 
 import java.awt.BorderLayout;
@@ -372,45 +373,18 @@
         addButton.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent event) {
                 if (add.equals(event.getActionCommand())) {
-                    String text;
-                    Listener l = null;
-                    int lPort;
-                    lPort = port.getValue(0);
-                    if (lPort == 0) {
+                    Configuration config = getConfiguration();
+                    if (config == null) {
 
                         // no port, button does nothing
                         return;
                     }
-                    String tHost = host.getText();
-                    int tPort = 0;
-                    tPort = tport.getValue(0);
-                    ThrottleConfiguration throttleConfig = null;
-                    if (delayBox.isSelected()) {
-                        int bytes = delayBytes.getValue(0);
-                        int time = delayTime.getValue(0);
-                        throttleConfig = new ThrottleConfiguration(bytes, 
time);
-                    }
                     try {
-                        l = new Listener(noteb, null, lPort, tHost, tPort,
-                                proxyButton.isSelected(),
-                                throttleConfig);
+                        new Listener(noteb, null, config);
                     } catch (Exception e) {
                         e.printStackTrace();
                     }
 
-                    // Pick-up the HTTP Proxy settings
-                    // /////////////////////////////////////////////////
-                    text = HTTPProxyHost.getText();
-                    if ("".equals(text)) {
-                        text = null;
-                    }
-                    l.HTTPProxyHost = text;
-                    text = HTTPProxyPort.getText();
-                    int proxyPort = HTTPProxyPort.getValue(-1);
-                    if (proxyPort != -1) {
-                        l.HTTPProxyPort = Integer.parseInt(text);
-                    }
-
                     // reset the port
                     port.setText(null);
                 }
@@ -423,6 +397,39 @@
         notebook.setSelectedIndex(notebook.getTabCount() - 1);
     }
     
+    private Configuration getConfiguration() {
+        Configuration config = new Configuration();
+        
+        int lPort = port.getValue(0);
+        if (lPort == 0) {
+            // no port, no configuration
+            return null;
+        }
+        config.setListenPort(lPort);
+        config.setProxy(proxyButton.isSelected());
+        config.setTargetHost(host.getText());
+        config.setTargetPort(tport.getValue(0));
+        ThrottleConfiguration throttleConfig = null;
+        if (delayBox.isSelected()) {
+            throttleConfig = new ThrottleConfiguration(delayBytes.getValue(0), 
delayTime.getValue(0));
+        }
+        config.setThrottleConfiguration(throttleConfig);
+
+        // Pick-up the HTTP Proxy settings
+        // /////////////////////////////////////////////////
+        String text = HTTPProxyHost.getText();
+        if (text.length() > 0) {
+            config.setHttpProxyHost(text);
+        }
+        text = HTTPProxyPort.getText();
+        int proxyPort = HTTPProxyPort.getValue(-1);
+        if (proxyPort != -1) {
+            config.setHttpProxyPort(Integer.parseInt(text));
+        }
+        
+        return config;
+    }
+    
     /**
      * a text field with a restricted set of characters
      */

Modified: 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java?rev=779987&r1=779986&r2=779987&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java
 (original)
+++ 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java
 Fri May 29 14:16:09 2009
@@ -155,17 +155,17 @@
     /**
      * Field HTTPProxyHost
      */
-    public String HTTPProxyHost = null;
+    private String HTTPProxyHost = null;
 
     /**
      * Field HTTPProxyPort
      */
-    public int HTTPProxyPort = 80;
+    private int HTTPProxyPort = 80;
 
     /**
      * Field slowLink
      */
-    public ThrottleConfiguration throttleConfig;
+    private ThrottleConfiguration throttleConfig;
 
     /**
      * Field connections
@@ -183,22 +183,23 @@
      * @param isProxy
      * @param slowLink   optional reference to a slow connection
      */
-    public Listener(JTabbedPane _notebook, String name, int listenPort,
-                    String host, int targetPort, boolean isProxy,
-                    ThrottleConfiguration throttleConfig) {
+    public Listener(JTabbedPane _notebook, String name,
+                    Configuration config) {
         notebook = _notebook;
         if (name == null) {
-            name = TCPMonBundle.getMessage("port01", "Port") + " " + 
listenPort;
+            name = TCPMonBundle.getMessage("port01", "Port") + " " + 
config.getListenPort();
         }
 
         // set the slow link to the passed down link
         if (throttleConfig != null) {
-            this.throttleConfig = throttleConfig;
+            this.throttleConfig = config.getThrottleConfiguration();
         } else {
 
             // or make up a no-op one.
             this.throttleConfig = new ThrottleConfiguration(0, 0);
         }
+        HTTPProxyHost = config.getHttpProxyHost();
+        HTTPProxyPort = config.getHttpProxyPort();
         panel = new JPanel(new BorderLayout());
 
         // 1st component is just a row of labels and 1-line entry fields
@@ -210,13 +211,13 @@
         top.addSeparator();
         top.add(new JLabel(TCPMonBundle.getMessage("listenPort01", "Listen 
Port:")
                 + " ", SwingConstants.RIGHT));
-        top.add(portField = new JTextField("" + listenPort, 4));
+        top.add(portField = new JTextField("" + config.getListenPort(), 4));
         top.add(new JLabel("  " + TCPMonBundle.getMessage("host00", "Host:") + 
" ",
                 SwingConstants.RIGHT));
-        top.add(hostField = new JTextField(host, 15));
+        top.add(hostField = new JTextField(config.getTargetHost(), 15));
         top.add(new JLabel("  " + TCPMonBundle.getMessage("port02", "Port:") + 
" ",
                 SwingConstants.RIGHT));
-        top.add(tPortField = new JTextField("" + targetPort, 4));
+        top.add(tPortField = new JTextField("" + config.getTargetPort(), 4));
         top.add(isProxyBox = new JCheckBox(TCPMonBundle.getMessage("proxy00", 
"Proxy")));
         isProxyBox.addChangeListener(new BasicButtonListener(isProxyBox) {
             public void stateChanged(ChangeEvent event) {
@@ -226,7 +227,7 @@
                 hostField.setEnabled(!state);
             }
         });
-        isProxyBox.setSelected(isProxy);
+        isProxyBox.setSelected(config.isProxy());
         portField.setEditable(false);
         portField.setMaximumSize(portField.getPreferredSize());
         hostField.setEditable(false);

Modified: 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/TCPMon.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/TCPMon.java?rev=779987&r1=779986&r2=779987&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/TCPMon.java
 (original)
+++ 
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/TCPMon.java
 Fri May 29 14:16:09 2009
@@ -21,6 +21,8 @@
 import javax.swing.UIManager;
 import javax.swing.UnsupportedLookAndFeelException;
 
+import org.apache.ws.commons.tcpmon.core.Configuration;
+
 /**
  * Proxy that sniffs and shows HTTP messages and responses, both SOAP and 
plain HTTP.
  */
@@ -77,27 +79,29 @@
         new AdminPane(notebook, TCPMonBundle.getMessage("admin00", "Admin"));
         if (listenPort != 0) {
             Listener l = null;
-            if (targetHost == null) {
-                l = new Listener(notebook, null, listenPort, targetHost, 
targetPort, true, null);
-            } else {
-                l = new Listener(notebook, null, listenPort, targetHost, 
targetPort, false, null);
-            }
+            Configuration config = new Configuration();
+            config.setListenPort(listenPort);
+            config.setTargetHost(targetHost);
+            config.setTargetPort(targetPort);
+            config.setProxy(targetHost == null);
             notebook.setSelectedIndex(0);
-            l.HTTPProxyHost = System.getProperty("http.proxyHost");
-            if ((l.HTTPProxyHost != null) && l.HTTPProxyHost.equals("")) {
-                l.HTTPProxyHost = null;
+            String HTTPProxyHost = System.getProperty("http.proxyHost");
+            if ((HTTPProxyHost != null) && HTTPProxyHost.equals("")) {
+                HTTPProxyHost = null;
             }
-            if (l.HTTPProxyHost != null) {
+            if (HTTPProxyHost != null) {
+                config.setHttpProxyHost(HTTPProxyHost);
                 String tmp = System.getProperty("http.proxyPort");
                 if ((tmp != null) && tmp.equals("")) {
                     tmp = null;
                 }
                 if (tmp == null) {
-                    l.HTTPProxyPort = 80;
+                    config.setHttpProxyPort(80);
                 } else {
-                    l.HTTPProxyPort = Integer.parseInt(tmp);
+                    config.setHttpProxyPort(Integer.parseInt(tmp));
                 }
             }
+            new Listener(notebook, null, config);
         }
         if (!embedded) {
             this.setDefaultCloseOperation(EXIT_ON_CLOSE);


Reply via email to