You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/01/01 02:29:57 UTC
svn commit: r730497 - in
/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon:
./ core/ eclipse/ui/
Author: veithen
Date: Wed Dec 31 17:29:57 2008
New Revision: 730497
URL: http://svn.apache.org/viewvc?rev=730497&view=rev
Log:
Decoupled AbstractSocketRR and its implementations a bit more from the UI by abstracting Swing's JTextArea and SWT's Text widgets behind java.io.Writer implementations.
Added:
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/JTextAreaWriter.java
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TextWidgetWriter.java
Modified:
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Connection.java
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/SocketRR.java
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractSocketRR.java
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketRR.java
Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Connection.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Connection.java?rev=730497&r1=730496&r2=730497&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Connection.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Connection.java Wed Dec 31 17:29:57 2008
@@ -128,15 +128,16 @@
Socket outSocket, OutputStream outputStream, boolean format,
SlowLinkSimulator slowLink) {
return new SocketRR(this, inSocket, inputStream, outSocket, outputStream,
- inputText, format, listener.tableModel,
- listener.connections.indexOf(this) + 1, slowLink);
+ format, listener.tableModel,
+ listener.connections.indexOf(this) + 1, slowLink,
+ new JTextAreaWriter(inputText));
}
protected AbstractSocketRR createOutputSocketRR(Socket outSocket, InputStream inputStream,
Socket inSocket, OutputStream outputStream, boolean format,
SlowLinkSimulator slowLink) {
return new SocketRR(this, outSocket, inputStream, inSocket, outputStream,
- outputText, format, null, 0, slowLink);
+ format, null, 0, slowLink, new JTextAreaWriter(outputText));
}
protected void appendInputText(String data) {
Added: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/JTextAreaWriter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/JTextAreaWriter.java?rev=730497&view=auto
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/JTextAreaWriter.java (added)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/JTextAreaWriter.java Wed Dec 31 17:29:57 2008
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ws.commons.tcpmon;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import javax.swing.JTextArea;
+
+/**
+ * A simple writer that appends the character data to a {@link JTextArea}.
+ */
+public class JTextAreaWriter extends Writer {
+ private final JTextArea textArea;
+
+ public JTextAreaWriter(JTextArea textArea) {
+ this.textArea = textArea;
+ }
+
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ textArea.append(new String(cbuf, off, len));
+ }
+
+ public void close() throws IOException {
+ }
+
+ public void flush() throws IOException {
+ }
+}
Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/SocketRR.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/SocketRR.java?rev=730497&r1=730496&r2=730497&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/SocketRR.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/SocketRR.java Wed Dec 31 17:29:57 2008
@@ -16,13 +16,13 @@
package org.apache.ws.commons.tcpmon;
-import javax.swing.JTextArea;
import javax.swing.table.TableModel;
import org.apache.ws.commons.tcpmon.core.AbstractSocketRR;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.Writer;
import java.net.Socket;
/**
@@ -31,11 +31,6 @@
*/
class SocketRR extends AbstractSocketRR {
/**
- * Field textArea
- */
- JTextArea textArea;
-
- /**
* Field tmodel
*/
TableModel tmodel = null;
@@ -62,11 +57,10 @@
*/
public SocketRR(Connection c, Socket inputSocket,
InputStream inputStream, Socket outputSocket,
- OutputStream outputStream, JTextArea _textArea,
+ OutputStream outputStream,
boolean format, TableModel tModel, int index,
- SlowLinkSimulator slowLink) {
- super(c, inputSocket, inputStream, outputSocket, outputStream, format, slowLink);
- textArea = _textArea;
+ SlowLinkSimulator slowLink, Writer writer) {
+ super(c, inputSocket, inputStream, outputSocket, outputStream, format, slowLink, writer);
tmodel = tModel;
tableIndex = index;
start();
@@ -83,8 +77,4 @@
protected void setSavedFirstLine(String value) {
tmodel.setValueAt(value, tableIndex, TCPMon.REQ_COLUMN);
}
-
- protected void appendData(String data) {
- textArea.append(data);
- }
}
Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractSocketRR.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractSocketRR.java?rev=730497&r1=730496&r2=730497&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractSocketRR.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractSocketRR.java Wed Dec 31 17:29:57 2008
@@ -20,6 +20,7 @@
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.Writer;
import java.net.Socket;
/**
@@ -69,6 +70,8 @@
*/
SlowLinkSimulator slowLink;
+ private final Writer writer;
+
/**
* Constructor SocketRR
*
@@ -87,7 +90,7 @@
public AbstractSocketRR(AbstractConnection connection, Socket inputSocket,
InputStream inputStream, Socket outputSocket,
OutputStream outputStream, boolean format,
- SlowLinkSimulator slowLink) {
+ SlowLinkSimulator slowLink, Writer writer) {
this.connection = connection;
inSocket = inputSocket;
in = inputStream;
@@ -95,6 +98,7 @@
out = outputStream;
xmlFormat = format;
this.slowLink = slowLink;
+ this.writer = writer;
}
/**
@@ -250,14 +254,14 @@
}
}
- appendData(new String(tmpbuffer, 0, i2));
+ writer.write(new String(tmpbuffer, 0, i2));
// Shift saved bytes to the beginning
for (i = 0; i < saved; i++) {
buffer[i] = buffer[bufferLen - saved + i];
}
} else {
- appendData(new String(buffer, 0, len));
+ writer.write(new String(buffer, 0, len));
}
}
@@ -322,5 +326,4 @@
protected abstract boolean isSaveFirstLine();
protected abstract String getSavedFirstLine();
protected abstract void setSavedFirstLine(String value);
- protected abstract void appendData(String data);
}
Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java?rev=730497&r1=730496&r2=730497&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java Wed Dec 31 17:29:57 2008
@@ -111,15 +111,16 @@
Socket outSocket, OutputStream outputStream, boolean format,
SlowLinkSimulator slowLink) {
return new SocketRR(this, inSocket, inputStream, outSocket, outputStream,
- inputText, format, listener.connectionTable,
- listener.connections.indexOf(this) + 1, slowLink);
+ format, listener.connectionTable,
+ listener.connections.indexOf(this) + 1, slowLink,
+ new TextWidgetWriter(inputText));
}
protected AbstractSocketRR createOutputSocketRR(Socket outSocket, InputStream inputStream,
Socket inSocket, OutputStream outputStream, boolean format,
SlowLinkSimulator slowLink) {
return new SocketRR(this, outSocket, inputStream, inSocket, outputStream,
- outputText, format, null, 0, slowLink);
+ format, null, 0, slowLink, new TextWidgetWriter(outputText));
}
protected void appendInputText(final String data) {
Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketRR.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketRR.java?rev=730497&r1=730496&r2=730497&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketRR.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketRR.java Wed Dec 31 17:29:57 2008
@@ -18,10 +18,10 @@
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.Writer;
import java.net.Socket;
import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.Text;
import org.apache.ws.commons.tcpmon.SlowLinkSimulator;
import org.apache.ws.commons.tcpmon.core.AbstractSocketRR;
@@ -31,11 +31,6 @@
*/
class SocketRR extends AbstractSocketRR {
/**
- * Field textArea
- */
- Text textArea;
-
- /**
* Field tmodel
*/
Table tmodel = null;
@@ -62,11 +57,10 @@
*/
public SocketRR(Connection c, Socket inputSocket,
InputStream inputStream, Socket outputSocket,
- OutputStream outputStream, Text _textArea,
+ OutputStream outputStream,
boolean format, Table tModel, int index,
- SlowLinkSimulator slowLink) {
- super(c, inputSocket, inputStream, outputSocket, outputStream, format, slowLink);
- textArea = _textArea;
+ SlowLinkSimulator slowLink, Writer writer) {
+ super(c, inputSocket, inputStream, outputSocket, outputStream, format, slowLink, writer);
tmodel = tModel;
tableIndex = index;
start();
@@ -93,12 +87,4 @@
}
});
}
-
- protected void appendData(final String data) {
- MainView.display.syncExec(new Runnable() {
- public void run() {
- textArea.append(data);
- }
- });
- }
}
Added: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TextWidgetWriter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TextWidgetWriter.java?rev=730497&view=auto
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TextWidgetWriter.java (added)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TextWidgetWriter.java Wed Dec 31 17:29:57 2008
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ws.commons.tcpmon.eclipse.ui;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * A simple writer that appends the character data to a {@link Text} widget.
+ */
+public class TextWidgetWriter extends Writer {
+ private final Text textArea;
+
+ public TextWidgetWriter(Text textArea) {
+ this.textArea = textArea;
+ }
+
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ final String s = new String(cbuf, off, len);
+ MainView.display.syncExec(new Runnable() {
+ public void run() {
+ textArea.append(s);
+ }
+ });
+ }
+
+ public void close() throws IOException {
+ }
+
+ public void flush() throws IOException {
+ }
+}