KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > utils > SOAPMonitor


1 /*
2  * Copyright 2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache Liusercense, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis.utils;
17
18 import org.apache.axis.client.AdminClient;
19 import org.apache.axis.monitor.SOAPMonitorConstants;
20 import org.w3c.dom.Document JavaDoc;
21 import org.w3c.dom.Element JavaDoc;
22 import org.w3c.dom.NamedNodeMap JavaDoc;
23 import org.w3c.dom.Node JavaDoc;
24 import org.w3c.dom.NodeList JavaDoc;
25
26 import javax.swing.BoxLayout JavaDoc;
27 import javax.swing.ButtonGroup JavaDoc;
28 import javax.swing.DefaultListModel JavaDoc;
29 import javax.swing.JButton JavaDoc;
30 import javax.swing.JCheckBox JavaDoc;
31 import javax.swing.JDialog JavaDoc;
32 import javax.swing.JFrame JavaDoc;
33 import javax.swing.JLabel JavaDoc;
34 import javax.swing.JList JavaDoc;
35 import javax.swing.JOptionPane JavaDoc;
36 import javax.swing.JPanel JavaDoc;
37 import javax.swing.JPasswordField JavaDoc;
38 import javax.swing.JProgressBar JavaDoc;
39 import javax.swing.JRadioButton JavaDoc;
40 import javax.swing.JScrollPane JavaDoc;
41 import javax.swing.JSplitPane JavaDoc;
42 import javax.swing.JTabbedPane JavaDoc;
43 import javax.swing.JTable JavaDoc;
44 import javax.swing.JTextArea JavaDoc;
45 import javax.swing.JTextField JavaDoc;
46 import javax.swing.ListSelectionModel JavaDoc;
47 import javax.swing.SwingConstants JavaDoc;
48 import javax.swing.SwingUtilities JavaDoc;
49 import javax.swing.UIManager JavaDoc;
50 import javax.swing.WindowConstants JavaDoc;
51 import javax.swing.border.BevelBorder JavaDoc;
52 import javax.swing.border.EmptyBorder JavaDoc;
53 import javax.swing.border.EtchedBorder JavaDoc;
54 import javax.swing.event.DocumentEvent JavaDoc;
55 import javax.swing.event.DocumentListener JavaDoc;
56 import javax.swing.event.ListSelectionEvent JavaDoc;
57 import javax.swing.event.ListSelectionListener JavaDoc;
58 import javax.swing.table.AbstractTableModel JavaDoc;
59 import javax.swing.event.ChangeListener JavaDoc;
60 import javax.xml.parsers.ParserConfigurationException JavaDoc;
61 import java.awt.BorderLayout JavaDoc;
62 import java.awt.Color JavaDoc;
63 import java.awt.Dimension JavaDoc;
64 import java.awt.FlowLayout JavaDoc;
65 import java.awt.Font JavaDoc;
66 import java.awt.GridBagConstraints JavaDoc;
67 import java.awt.GridBagLayout JavaDoc;
68 import java.awt.GridLayout JavaDoc;
69 import java.awt.Insets JavaDoc;
70 import java.awt.event.ActionEvent JavaDoc;
71 import java.awt.event.ActionListener JavaDoc;
72 import java.awt.event.WindowAdapter JavaDoc;
73 import java.awt.event.WindowEvent JavaDoc;
74 import java.io.ByteArrayInputStream JavaDoc;
75 import java.io.IOException JavaDoc;
76 import java.io.ObjectInputStream JavaDoc;
77 import java.io.ObjectOutputStream JavaDoc;
78 import java.lang.reflect.InvocationTargetException JavaDoc;
79 import java.net.Socket JavaDoc;
80 import java.net.URL JavaDoc;
81 import java.net.MalformedURLException JavaDoc;
82 import java.text.DateFormat JavaDoc;
83 import java.util.Collection JavaDoc;
84 import java.util.Date JavaDoc;
85 import java.util.Enumeration JavaDoc;
86 import java.util.HashMap JavaDoc;
87 import java.util.Iterator JavaDoc;
88 import java.util.Vector JavaDoc;
89
90 /**
91  * This is a SOAP Monitor Application class. This class provides
92  * the user interface for deploying the SOAP monitor service and
93  * displaying data from the service.
94  *
95  * @author Toshiyuki Kimura (toshi@apache.org)
96  * @author Brian Price (pricebe@us.ibm.com)
97  */

98 public class SOAPMonitor extends JFrame JavaDoc implements ActionListener JavaDoc, ChangeListener JavaDoc {
99
100     /**
101      * Private data
102      */

103     private JPanel JavaDoc main_panel = null;
104
105     /**
106      * Field tabbed_pane
107      */

108     private JTabbedPane JavaDoc tabbed_pane = null;
109
110     /**
111      * Field top_pane
112      */

113     private JTabbedPane JavaDoc top_pane = null;
114
115     /**
116      * Field port
117      */

118     private int port = 5001;
119
120     /**
121      * Field axisHost
122      */

123     private String JavaDoc axisHost = "localhost";
124
125     /**
126      * Field axisPort
127      */

128     private int axisPort = 8080;
129
130     /**
131      * Field axisURL
132      */

133     private String JavaDoc axisURL = null;
134
135     /**
136      * Field pages
137      */

138     private Vector JavaDoc pages = null;
139
140     /**
141      * Field titleStr
142      */

143     private final String JavaDoc titleStr = "SOAP Monitor Administration";
144
145     /**
146      * Field set_panel
147      */

148     private JPanel JavaDoc set_panel = null;
149
150     /**
151      * Field titleLabel
152      */

153     private JLabel JavaDoc titleLabel = null;
154
155     /**
156      * Field add_btn
157      */

158     private JButton JavaDoc add_btn = null;
159
160     /**
161      * Field del_btn
162      */

163     private JButton JavaDoc del_btn = null;
164
165     /**
166      * Field save_btn
167      */

168     private JButton JavaDoc save_btn = null;
169
170     /**
171      * Field login_btn
172      */

173     private JButton JavaDoc login_btn = null;
174
175     /**
176      * Field model1
177      */

178     private DefaultListModel JavaDoc model1 = null;
179
180     /**
181      * Field model2
182      */

183     private DefaultListModel JavaDoc model2 = null;
184
185     /**
186      * Field list1
187      */

188     private JList JavaDoc list1 = null;
189
190     /**
191      * Field list2
192      */

193     private JList JavaDoc list2 = null;
194
195     /**
196      * Field serviceMap
197      */

198     private HashMap JavaDoc serviceMap = null;
199
200     /**
201      * Field originalDoc
202      */

203     private Document JavaDoc originalDoc = null;
204
205     /**
206      * Field axisUser
207      */

208     private static String JavaDoc axisUser = null;
209
210     /**
211      * Field axisPass
212      */

213     private static String JavaDoc axisPass = null;
214
215     /**
216      * Field adminClient
217      */

218     private AdminClient adminClient = new AdminClient();
219
220     /**
221      * Main method for this class
222      *
223      * @param args
224      * @throws Exception
225      */

226     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
227         SOAPMonitor soapMonitor = null;
228         Options opts = new Options(args);
229         if (opts.isFlagSet('?') > 0) {
230             System.out.println(
231                     "Usage: SOAPMonitor [-l<url>] [-u<user>] [-w<password>] [-?]");
232             System.exit(0);
233         }
234
235         // Create an instance
236
soapMonitor = new SOAPMonitor();
237
238         // GET Axis URL.
239
// The default is "http://localhost:8080/axis/servlet/AxisServlet"
240
soapMonitor.axisURL = opts.getURL();
241         URL JavaDoc url = new URL JavaDoc(soapMonitor.axisURL);
242         soapMonitor.axisHost = url.getHost();
243
244         // GET User name & Password
245
axisUser = opts.getUser();
246         axisPass = opts.getPassword();
247
248         // Login and start application
249
soapMonitor.doLogin();
250     }
251
252     /**
253      * Constructor
254      */

255     public SOAPMonitor() {
256         setTitle("SOAP Monitor Application");
257         Dimension JavaDoc d = getToolkit().getScreenSize();
258         setSize(640, 480);
259         setLocation((d.width - getWidth()) / 2, (d.height - getHeight()) / 2);
260         setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
261         addWindowListener(new MyWindowAdapter());
262
263         // Try to use the system look and feel
264
try {
265             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
266         } catch (Exception JavaDoc e) {
267         }
268
269         // Create main panel to hold notebook
270
main_panel = new JPanel JavaDoc();
271         main_panel.setBackground(Color.white);
272         main_panel.setLayout(new BorderLayout JavaDoc());
273         top_pane = new JTabbedPane JavaDoc();
274         set_panel = new JPanel JavaDoc();
275
276         // label for NORTH panel to display the pain title
277
titleLabel = new JLabel JavaDoc(titleStr);
278         titleLabel.setFont(new Font JavaDoc("Serif", Font.BOLD, 18));
279
280         // list control for WEST panel to list NOT monitored services
281
model1 = new DefaultListModel JavaDoc();
282         list1 = new JList JavaDoc(model1);
283         list1.setFixedCellWidth(250);
284         JScrollPane JavaDoc scroll1 = new JScrollPane JavaDoc(list1);
285
286         // list control for EAST panel to list monitored services
287
model2 = new DefaultListModel JavaDoc();
288         list2 = new JList JavaDoc(model2);
289         list2.setFixedCellWidth(250);
290         JScrollPane JavaDoc scroll2 = new JScrollPane JavaDoc(list2);
291
292         // buttons for CENTER panel to chage the monitoring state
293
add_btn = new JButton JavaDoc("Turn On [ >> ]");
294         del_btn = new JButton JavaDoc("[ << ] Turn Off");
295         JPanel JavaDoc center_panel = new JPanel JavaDoc();
296         GridBagLayout JavaDoc layout = new GridBagLayout JavaDoc();
297         center_panel.setLayout(layout);
298         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
299         c.gridx = 0;
300         c.gridy = 0;
301         c.insets = new Insets JavaDoc(10, 10, 10, 10);
302         layout.setConstraints(add_btn, c);
303         center_panel.add(add_btn);
304         c.gridx = 0;
305         c.gridy = 1;
306         c.insets = new Insets JavaDoc(10, 10, 10, 10);
307         layout.setConstraints(del_btn, c);
308         center_panel.add(del_btn);
309
310         // buttons for SOUTH panel
311
save_btn = new JButton JavaDoc("Save changes");
312         login_btn = new JButton JavaDoc("Change server");
313         JPanel JavaDoc south_panel = new JPanel JavaDoc();
314         layout = new GridBagLayout JavaDoc();
315         c.gridx = 0;
316         c.gridy = 0;
317         c.insets = new Insets JavaDoc(10, 10, 10, 10);
318         layout.setConstraints(save_btn, c);
319         south_panel.add(save_btn);
320         c.gridx = 1;
321         c.gridy = 0;
322         c.insets = new Insets JavaDoc(10, 10, 10, 10);
323         layout.setConstraints(login_btn, c);
324         south_panel.add(login_btn);
325
326         // set all controls to the border layout
327
set_panel.setLayout(new BorderLayout JavaDoc(5, 5));
328         set_panel.add(titleLabel, BorderLayout.NORTH);
329         set_panel.add(south_panel, BorderLayout.SOUTH);
330         set_panel.add(scroll1, BorderLayout.WEST);
331         set_panel.add(scroll2, BorderLayout.EAST);
332         set_panel.add(center_panel, BorderLayout.CENTER);
333
334         // register the Action Listener
335
add_btn.addActionListener(this);
336         del_btn.addActionListener(this);
337         save_btn.addActionListener(this);
338         login_btn.addActionListener(this);
339
340         // set default button state as 'false'
341
add_btn.setEnabled(false);
342         del_btn.setEnabled(false);
343         save_btn.setEnabled(false);
344         login_btn.setEnabled(false);
345         top_pane.add("Setting", set_panel);
346         top_pane.add("Monitoring", main_panel);
347         getContentPane().add(top_pane);
348
349         // Create the notebook
350
tabbed_pane = new JTabbedPane JavaDoc(JTabbedPane.TOP);
351         main_panel.add(tabbed_pane, BorderLayout.CENTER);
352         top_pane.addChangeListener(this);
353         top_pane.setEnabled(false);
354         setVisible(true);
355     }
356
357     /**
358      * Do login process
359      *
360      * @return
361      */

362     private boolean doLogin() {
363         Dimension JavaDoc d = null;
364
365         // Login
366
LoginDlg login = new LoginDlg();
367         login.show();
368         if (!login.isLogin()) {
369             login_btn.setEnabled(true);
370             return false;
371         }
372         login.dispose();
373         save_btn.setEnabled(false);
374         login_btn.setEnabled(false);
375
376         // Get the axisHost & axisPort to be used
377
String JavaDoc url_str = login.getURL();
378         try {
379             URL JavaDoc url = new URL JavaDoc(url_str);
380             axisHost = url.getHost();
381             axisPort = url.getPort();
382             if (axisPort == -1) {
383                 axisPort = 8080;
384             }
385             String JavaDoc axisPath = url.getPath();
386             axisURL = "http://" + axisHost + ":" + axisPort + axisPath;
387         } catch (MalformedURLException JavaDoc e) {
388             JOptionPane JavaDoc pane = new JOptionPane JavaDoc();
389             String JavaDoc msg = e.toString();
390             pane.setMessageType(JOptionPane.WARNING_MESSAGE);
391             pane.setMessage(msg);
392             pane.setOptions(new String JavaDoc[]{"OK"});
393             JDialog JavaDoc dlg = pane.createDialog(null, "Login status");
394             dlg.setVisible(true);
395             login_btn.setEnabled(true);
396             return false;
397         }
398         titleLabel.setText(titleStr + " for [" + axisHost + ":" + axisPort
399                 + "]");
400         final JProgressBar JavaDoc progressBar = new JProgressBar JavaDoc(0, 100);
401         BarThread stepper = new BarThread(progressBar);
402         stepper.start();
403         JFrame JavaDoc progress = new JFrame JavaDoc();
404         d = new Dimension JavaDoc(250, 50);
405         progress.setSize(d);
406         d = getToolkit().getScreenSize();
407         progress.getContentPane().add(progressBar);
408         progress.setTitle("Now loading data ...");
409         progress.setLocation((d.width - progress.getWidth()) / 2,
410                 (d.height - progress.getHeight()) / 2);
411         progress.show();
412
413         // Add notebook page for default host connection
414
pages = new Vector JavaDoc();
415         addPage(new SOAPMonitorPage(axisHost));
416         serviceMap = new HashMap JavaDoc();
417         originalDoc = getServerWSDD();
418         model1.clear();
419         model2.clear();
420         if (originalDoc != null) {
421             String JavaDoc ret = null;
422             NodeList JavaDoc nl = originalDoc.getElementsByTagName("service");
423             for (int i = 0; i < nl.getLength(); i++) {
424                 Node JavaDoc node = nl.item(i);
425                 NamedNodeMap JavaDoc map = node.getAttributes();
426                 ret = map.getNamedItem("name").getNodeValue();
427                 serviceMap.put(ret, node);
428                 if (!isMonitored(node)) {
429                     model1.addElement((String JavaDoc) ret);
430                 } else {
431                     model2.addElement((String JavaDoc) ret);
432                 }
433             }
434             if (model1.size() > 0) {
435                 add_btn.setEnabled(true);
436             }
437             if (model2.size() > 0) {
438                 del_btn.setEnabled(true);
439             }
440             progress.dispose();
441             save_btn.setEnabled(true);
442             login_btn.setEnabled(true);
443             top_pane.setEnabled(true);
444             return true;
445         } else {
446             progress.dispose();
447             login_btn.setEnabled(true);
448             return false;
449         }
450     }
451
452     /**
453      * This class is a thred for a JProgressBar.
454      */

455     class BarThread extends Thread JavaDoc {
456
457         /**
458          * Field wait
459          */

460         private int wait = 100;
461
462         /**
463          * Field progressBar
464          */

465         JProgressBar JavaDoc progressBar = null;
466
467         /**
468          * Constructor BarThread
469          *
470          * @param bar
471          */

472         public BarThread(JProgressBar JavaDoc bar) {
473             progressBar = bar;
474         }
475
476         /**
477          * Method run
478          */

479         public void run() {
480             int min = progressBar.getMinimum();
481             int max = progressBar.getMaximum();
482             Runnable JavaDoc runner = new Runnable JavaDoc() {
483                 public void run() {
484                     int val = progressBar.getValue();
485                     progressBar.setValue(val + 1);
486                 }
487             };
488             for (int i = min; i < max; i++) {
489                 try {
490                     SwingUtilities.invokeAndWait(runner);
491                     Thread.sleep(wait);
492                 } catch (InterruptedException JavaDoc ignoredException) {
493                 } catch (InvocationTargetException JavaDoc ignoredException) {
494                 }
495             }
496         }
497     }
498
499     /**
500      * Get the server-config.wsdd as a document to retrieve deployed services
501      *
502      * @return
503      */

504     private Document JavaDoc getServerWSDD() {
505         Document JavaDoc doc = null;
506         try {
507             String JavaDoc[] param = new String JavaDoc[]{"-u" + axisUser, "-w" + axisPass,
508                                           "-l " + axisURL, "list"};
509             String JavaDoc ret = adminClient.process(param);
510             doc = XMLUtils.newDocument(
511                     new ByteArrayInputStream JavaDoc(ret.getBytes()));
512         } catch (Exception JavaDoc e) {
513             JOptionPane JavaDoc pane = new JOptionPane JavaDoc();
514             String JavaDoc msg = e.toString();
515             pane.setMessageType(JOptionPane.WARNING_MESSAGE);
516             pane.setMessage(msg);
517             pane.setOptions(new String JavaDoc[]{"OK"});
518             JDialog JavaDoc dlg = pane.createDialog(null, "Login status");
519             dlg.setVisible(true);
520         }
521         return doc;
522     }
523
524     /**
525      * Deploy the specified wsdd to change the monitoring state
526      *
527      * @param wsdd
528      * @return
529      */

530     private boolean doDeploy(Document JavaDoc wsdd) {
531         String JavaDoc deploy = null;
532         Options opt = null;
533         deploy = XMLUtils.DocumentToString(wsdd);
534         try {
535             String JavaDoc[] param = new String JavaDoc[]{"-u" + axisUser, "-w" + axisPass,
536                                           "-l " + axisURL, ""};
537             opt = new Options(param);
538             adminClient.process(opt,
539                     new ByteArrayInputStream JavaDoc(deploy.getBytes()));
540         } catch (Exception JavaDoc e) {
541             return false;
542         }
543         return true;
544     }
545
546     /**
547      * Get a new document which has the specified node as the document root
548      *
549      * @param target
550      * @return
551      */

552     private Document JavaDoc getNewDocumentAsNode(Node JavaDoc target) {
553         Document JavaDoc doc = null;
554         Node JavaDoc node = null;
555         try {
556             doc = XMLUtils.newDocument();
557         } catch (ParserConfigurationException JavaDoc e) {
558             e.printStackTrace();
559         }
560         node = doc.importNode(target, true);
561         doc.appendChild(node);
562         return doc;
563     }
564
565     /**
566      * Add needed nodes for monitoring to the specified node
567      * <p/>
568      * TODO: support JAX-RPC type definition (i.e. <handlerInfoChain/>)
569      *
570      * @param target
571      * @return
572      */

573     private Node JavaDoc addMonitor(Node JavaDoc target) {
574         Document JavaDoc doc = null;
575         Node JavaDoc node = null;
576         Node JavaDoc newNode = null;
577         String JavaDoc ret = null;
578         NodeList JavaDoc nl = null;
579         final String JavaDoc reqFlow = "requestFlow";
580         final String JavaDoc resFlow = "responseFlow";
581         final String JavaDoc monitor = "soapmonitor";
582         final String JavaDoc handler = "handler";
583         final String JavaDoc type = "type";
584         doc = getNewDocumentAsNode(target);
585
586         // Add "responseFlow node
587
nl = doc.getElementsByTagName(resFlow);
588         if (nl.getLength() == 0) {
589             node = doc.getDocumentElement().getFirstChild();
590             newNode = doc.createElement(resFlow);
591             doc.getDocumentElement().insertBefore(newNode, node);
592         }
593
594         // Add "requestFlow" node
595
nl = doc.getElementsByTagName(reqFlow);
596         if (nl.getLength() == 0) {
597             node = doc.getDocumentElement().getFirstChild();
598             newNode = doc.createElement(reqFlow);
599             doc.getDocumentElement().insertBefore(newNode, node);
600         }
601
602         // Add "handler" node and "soapmonitor" attribute for "requestFlow"
603
nl = doc.getElementsByTagName(reqFlow);
604         node = nl.item(0).getFirstChild();
605         newNode = doc.createElement(handler);
606         ((Element JavaDoc) newNode).setAttribute(type, monitor);
607         nl.item(0).insertBefore(newNode, node);
608
609         // Add "handler" node and "soapmonitor" attribute for "responseFlow"
610
nl = doc.getElementsByTagName(resFlow);
611         node = nl.item(0).getFirstChild();
612         newNode = doc.createElement(handler);
613         ((Element JavaDoc) newNode).setAttribute(type, monitor);
614         nl.item(0).insertBefore(newNode, node);
615         
616         return (Node JavaDoc) doc.getDocumentElement();
617     }
618
619     /**
620      * Remove a few nodes for stoping monitor from the specified node
621      * <p/>
622      * TODO: support JAX-RPC type definition (i.e. <handlerInfoChain/>)
623      *
624      * @param target
625      * @return
626      */

627     private Node JavaDoc delMonitor(Node JavaDoc target) {
628         Document JavaDoc doc = null;
629         Node JavaDoc node = null;
630         Node JavaDoc newNode = null;
631         String JavaDoc ret = null;
632         NodeList JavaDoc nl = null;
633         final String JavaDoc reqFlow = "requestFlow";
634         final String JavaDoc resFlow = "responseFlow";
635         final String JavaDoc monitor = "soapmonitor";
636         final String JavaDoc handler = "handler";
637         final String JavaDoc type = "type";
638         doc = getNewDocumentAsNode(target);
639         nl = doc.getElementsByTagName(handler);
640         int size;
641         size = nl.getLength();
642         Node JavaDoc[] removeNode = new Node JavaDoc[size];
643         if (size > 0) {
644             newNode = nl.item(0).getParentNode();
645         }
646         for (int i = 0; i < size; i++) {
647             node = nl.item(i);
648             NamedNodeMap JavaDoc map = node.getAttributes();
649             ret = map.getNamedItem(type).getNodeValue();
650             if (ret.equals(monitor)) {
651                 removeNode[i] = node;
652             }
653         }
654         for (int i = 0; i < size; i++) {
655             Node JavaDoc child = removeNode[i];
656             if (child != null) {
657                 child.getParentNode().removeChild(child);
658             }
659         }
660
661         return (Node JavaDoc) doc.getDocumentElement();
662     }
663
664     /**
665      * Get a boolean value whether the specified node is monitoring or not
666      *
667      * @param target
668      * @return
669      */

670     private boolean isMonitored(Node JavaDoc target) {
671         Document JavaDoc doc = null;
672         Node JavaDoc node = null;
673         String JavaDoc ret = null;
674         NodeList JavaDoc nl = null;
675         final String JavaDoc monitor = "soapmonitor";
676         final String JavaDoc handler = "handler";
677         final String JavaDoc type = "type";
678         doc = getNewDocumentAsNode(target);
679         nl = doc.getElementsByTagName(handler);
680         for (int i = 0; i < nl.getLength(); i++) {
681             node = nl.item(i);
682             NamedNodeMap JavaDoc map = node.getAttributes();
683             ret = map.getNamedItem(type).getNodeValue();
684             if (ret.equals(monitor)) {
685                 return true;
686             } else {
687                 return false;
688             }
689         }
690         return false;
691     }
692
693     /**
694      * Add a few nodes for authentification
695      * <p/>
696      * TODO: support JAX-RPC type definition (i.e. <handlerInfoChain/>)
697      *
698      * @param target
699      * @return
700      */

701     private Node JavaDoc addAuthenticate(Node JavaDoc target) {
702         Document JavaDoc doc = null;
703         Node JavaDoc node = null;
704         Node JavaDoc newNode = null;
705         String JavaDoc ret = null;
706         NodeList JavaDoc nl = null;
707         final String JavaDoc reqFlow = "requestFlow";
708         final String JavaDoc handler = "handler";
709         final String JavaDoc type = "type";
710         final String JavaDoc authentication =
711                 "java:org.apache.axis.handlers.SimpleAuthenticationHandler";
712         final String JavaDoc authorization =
713                 "java:org.apache.axis.handlers.SimpleAuthorizationHandler";
714         final String JavaDoc param = "parameter";
715         final String JavaDoc name = "name";
716         final String JavaDoc role = "allowedRoles";
717         final String JavaDoc value = "value";
718         final String JavaDoc admin = "admin";
719         boolean authNode = false;
720         boolean roleNode = false;
721         doc = getNewDocumentAsNode(target);
722
723         // Add "requestFlow" node
724
nl = doc.getElementsByTagName(reqFlow);
725         if (nl.getLength() == 0) {
726             node = doc.getDocumentElement().getFirstChild();
727             newNode = doc.createElement(reqFlow);
728             doc.getDocumentElement().insertBefore(newNode, node);
729         }
730
731         // Add "SimpleAuthorizationHandler"
732
// (i.e. <handler type="java:org.apache.axis.handlers.SimpleAuthorizationHandler"/>)
733
nl = doc.getElementsByTagName(handler);
734         for (int i = 0; i < nl.getLength(); i++) {
735             node = nl.item(i);
736             NamedNodeMap JavaDoc map = node.getAttributes();
737             ret = map.getNamedItem(type).getNodeValue();
738             if (ret.equals(authorization)) {
739                 authNode = true;
740                 break;
741             }
742         }
743         if (!authNode) {
744             nl = doc.getElementsByTagName(reqFlow);
745             node = nl.item(0).getFirstChild();
746             newNode = doc.createElement(handler);
747             ((Element JavaDoc) newNode).setAttribute(type, authorization);
748             nl.item(0).insertBefore(newNode, node);
749         }
750
751         // Add "SimpleAuthenticationHandler"
752
// (i.e. <handler type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>)
753
authNode = false;
754         nl = doc.getElementsByTagName(handler);
755         for (int i = 0; i < nl.getLength(); i++) {
756             node = nl.item(i);
757             NamedNodeMap JavaDoc map = node.getAttributes();
758             ret = map.getNamedItem(type).getNodeValue();
759             if (ret.equals(authentication)) {
760                 authNode = true;
761                 break;
762             }
763         }
764         if (!authNode) {
765             nl = doc.getElementsByTagName(reqFlow);
766             node = nl.item(0).getFirstChild();
767             newNode = doc.createElement(handler);
768             ((Element JavaDoc) newNode).setAttribute(type, authentication);
769             nl.item(0).insertBefore(newNode, node);
770         }
771
772         // Add "allowedRoles" (i.e. <parameter name="allowedRoles" value="admin"/> )
773
nl = doc.getElementsByTagName(param);
774         for (int i = 0; i < nl.getLength(); i++) {
775             node = nl.item(i);
776             NamedNodeMap JavaDoc map = node.getAttributes();
777             node = map.getNamedItem(name);
778             if (node != null) {
779                 ret = node.getNodeValue();
780                 if (ret.equals(role)) {
781                     roleNode = true;
782                     break;
783                 }
784             }
785         }
786         if (!roleNode) {
787             nl = doc.getElementsByTagName(param);
788             newNode = doc.createElement(param);
789             ((Element JavaDoc) newNode).setAttribute(name, role);
790             ((Element JavaDoc) newNode).setAttribute(value, admin);
791             doc.getDocumentElement().insertBefore(newNode, nl.item(0));
792         }
793         return (Node JavaDoc) doc.getDocumentElement();
794     }
795
796     /**
797      * Handle the window close event
798      */

799     class MyWindowAdapter extends WindowAdapter JavaDoc {
800
801         /**
802          * Method windowClosing
803          *
804          * @param e
805          */

806         public void windowClosing(WindowEvent JavaDoc e) {
807             System.exit(0);
808         }
809     }
810
811     /**
812      * Add a page to the notebook
813      *
814      * @param pg
815      */

816     private void addPage(SOAPMonitorPage pg) {
817         tabbed_pane.addTab(" " + pg.getHost() + " ", pg);
818         pages.addElement(pg);
819     }
820
821     /**
822      * Del all pages to the notebook
823      */

824     private void delPage() {
825         tabbed_pane.removeAll();
826         pages.removeAllElements();
827     }
828
829     /**
830      * Frame is being displayed
831      */

832     public void start() {
833         // Tell all pages to start talking to the server
834
Enumeration JavaDoc e = pages.elements();
835         while (e.hasMoreElements()) {
836             SOAPMonitorPage pg = (SOAPMonitorPage) e.nextElement();
837             if (pg != null) {
838                 pg.start();
839             }
840         }
841     }
842
843     /*
844      * Frame is no longer displayed
845      */

846
847     /**
848      * Method stop
849      */

850     public void stop() {
851         // Tell all pages to stop talking to the server
852
Enumeration JavaDoc e = pages.elements();
853         while (e.hasMoreElements()) {
854             SOAPMonitorPage pg = (SOAPMonitorPage) e.nextElement();
855             if (pg != null) {
856                 pg.stop();
857             }
858         }
859     }
860
861     /**
862      * This class is for the Login Dialog
863      */

864     class LoginDlg extends JDialog JavaDoc implements ActionListener JavaDoc {
865
866         /**
867          * Field ok_button
868          */

869         private JButton JavaDoc ok_button = null;
870
871         /**
872          * Field cancel_button
873          */

874         private JButton JavaDoc cancel_button = null;
875
876         /**
877          * Field user
878          */

879         private JTextField JavaDoc user = new JTextField JavaDoc(20);
880
881         /**
882          * Field pass
883          */

884         private JPasswordField JavaDoc pass = new JPasswordField JavaDoc(20);
885
886         /**
887          * Field url
888          */

889         private JTextField JavaDoc url = new JTextField JavaDoc(20);
890
891         /**
892          * Field loginState
893          */

894         private boolean loginState = false;
895
896         /**
897          * Constructor (create and layout page)
898          */

899         public LoginDlg() {
900             setTitle("SOAP Monitor Login");
901             UIManager.put("Label.font", new Font JavaDoc("Dialog", Font.BOLD, 12));
902             JPanel JavaDoc panel = new JPanel JavaDoc();
903             ok_button = new JButton JavaDoc("OK");
904             ok_button.addActionListener(this);
905             cancel_button = new JButton JavaDoc("Cancel");
906             cancel_button.addActionListener(this);
907
908             // default URL for AxisServlet
909
url.setText(axisURL);
910             JLabel JavaDoc userLabel = new JLabel JavaDoc("User:");
911             JLabel JavaDoc passLabel = new JLabel JavaDoc("Password:");
912             JLabel JavaDoc urlLabel = new JLabel JavaDoc("Axis URL:");
913             userLabel.setHorizontalAlignment(JTextField.RIGHT);
914             passLabel.setHorizontalAlignment(JTextField.RIGHT);
915             urlLabel.setHorizontalAlignment(JTextField.RIGHT);
916             panel.add(userLabel);
917             panel.add(user);
918             panel.add(passLabel);
919             panel.add(pass);
920             panel.add(urlLabel);
921             panel.add(url);
922             panel.add(ok_button);
923             panel.add(cancel_button);
924             setContentPane(panel);
925             user.setText(SOAPMonitor.axisUser);
926             pass.setText(SOAPMonitor.axisPass);
927             GridLayout JavaDoc layout = new GridLayout JavaDoc(4, 2);
928             layout.setHgap(15);
929             layout.setVgap(5);
930             panel.setLayout(layout);
931             setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
932             setModal(true);
933             pack();
934             Dimension JavaDoc d = getToolkit().getScreenSize();
935             setLocation((d.width - getWidth()) / 2,
936                     (d.height - getHeight()) / 2);
937         }
938
939         /**
940          * Listener to handle button actions
941          *
942          * @param e
943          */

944         public void actionPerformed(ActionEvent JavaDoc e) {
945             // Check if the user pressed the OK button
946
if (e.getSource() == ok_button) {
947                 loginState = true;
948                 SOAPMonitor.axisUser = user.getText();
949                 SOAPMonitor.axisPass = new String JavaDoc(pass.getPassword());
950                 this.hide();
951             } else if (e.getSource() == cancel_button) {
952                 this.dispose();
953             }
954         }
955
956         /**
957          * Get the URL of the AxisServlet we are using
958          *
959          * @return
960          */

961         public String JavaDoc getURL() {
962             return url.getText();
963         }
964
965         /**
966          * Get the login status as a boolean
967          *
968          * @return
969          */

970         public boolean isLogin() {
971             return loginState;
972         }
973     }
974
975     /**
976      * This class provides the contents of a notebook page
977      * representing a server connection.
978      */

979     class SOAPMonitorPage extends JPanel JavaDoc
980             implements Runnable JavaDoc, ListSelectionListener JavaDoc, ActionListener JavaDoc {
981
982         /**
983          * Status Strings
984          */

985         private final String JavaDoc STATUS_ACTIVE = "The SOAP Monitor is started.";
986
987         /**
988          * Field STATUS_STOPPED
989          */

990         private final String JavaDoc STATUS_STOPPED = "The SOAP Monitor is stopped.";
991
992         /**
993          * Field STATUS_CLOSED
994          */

995         private final String JavaDoc STATUS_CLOSED =
996                 "The server communication has been terminated.";
997
998         /**
999          * Field STATUS_NOCONNECT
1000         */

1001        private final String JavaDoc STATUS_NOCONNECT =
1002                "The SOAP Monitor is unable to communcate with the server.";
1003
1004        /**
1005         * Private data
1006         */

1007        private String JavaDoc host = null;
1008
1009        /**
1010         * Field socket
1011         */

1012        private Socket JavaDoc socket = null;
1013
1014        /**
1015         * Field in
1016         */

1017        private ObjectInputStream JavaDoc in = null;
1018
1019        /**
1020         * Field out
1021         */

1022        private ObjectOutputStream JavaDoc out = null;
1023
1024        /**
1025         * Field model
1026         */

1027        private SOAPMonitorTableModel model = null;
1028
1029        /**
1030         * Field table
1031         */

1032        private JTable JavaDoc table = null;
1033
1034        /**
1035         * Field scroll
1036         */

1037        private JScrollPane JavaDoc scroll = null;
1038
1039        /**
1040         * Field list_panel
1041         */

1042        private JPanel JavaDoc list_panel = null;
1043
1044        /**
1045         * Field list_buttons
1046         */

1047        private JPanel JavaDoc list_buttons = null;
1048
1049        /**
1050         * Field remove_button
1051         */

1052        private JButton JavaDoc remove_button = null;
1053
1054        /**
1055         * Field remove_all_button
1056         */

1057        private JButton JavaDoc remove_all_button = null;
1058
1059        /**
1060         * Field filter_button
1061         */

1062        private JButton JavaDoc filter_button = null;
1063
1064        /**
1065         * Field details_panel
1066         */

1067        private JPanel JavaDoc details_panel = null;
1068
1069        /**
1070         * Field details_header
1071         */

1072        private JPanel JavaDoc details_header = null;
1073
1074        /**
1075         * Field details_soap
1076         */

1077        private JSplitPane JavaDoc details_soap = null;
1078
1079        /**
1080         * Field details_buttons
1081         */

1082        private JPanel JavaDoc details_buttons = null;
1083
1084        /**
1085         * Field details_time
1086         */

1087        private JLabel JavaDoc details_time = null;
1088
1089        /**
1090         * Field details_target
1091         */

1092        private JLabel JavaDoc details_target = null;
1093
1094        /**
1095         * Field details_status
1096         */

1097        private JLabel JavaDoc details_status = null;
1098
1099        /**
1100         * Field details_time_value
1101         */

1102        private JLabel JavaDoc details_time_value = null;
1103
1104        /**
1105         * Field details_target_value
1106         */

1107        private JLabel JavaDoc details_target_value = null;
1108
1109        /**
1110         * Field details_status_value
1111         */

1112        private JLabel JavaDoc details_status_value = null;
1113
1114        /**
1115         * Field empty_border
1116         */

1117        private EmptyBorder JavaDoc empty_border = null;
1118
1119        /**
1120         * Field etched_border
1121         */

1122        private EtchedBorder JavaDoc etched_border = null;
1123
1124        /**
1125         * Field request_panel
1126         */

1127        private JPanel JavaDoc request_panel = null;
1128
1129        /**
1130         * Field response_panel
1131         */

1132        private JPanel JavaDoc response_panel = null;
1133
1134        /**
1135         * Field request_label
1136         */

1137        private JLabel JavaDoc request_label = null;
1138
1139        /**
1140         * Field response_label
1141         */

1142        private JLabel JavaDoc response_label = null;
1143
1144        /**
1145         * Field request_text
1146         */

1147        private SOAPMonitorTextArea request_text = null;
1148
1149        /**
1150         * Field response_text
1151         */

1152        private SOAPMonitorTextArea response_text = null;
1153
1154        /**
1155         * Field request_scroll
1156         */

1157        private JScrollPane JavaDoc request_scroll = null;
1158
1159        /**
1160         * Field response_scroll
1161         */

1162        private JScrollPane JavaDoc response_scroll = null;
1163
1164        /**
1165         * Field layout_button
1166         */

1167        private JButton JavaDoc layout_button = null;
1168
1169        /**
1170         * Field split
1171         */

1172        private JSplitPane JavaDoc split = null;
1173
1174        /**
1175         * Field status_area
1176         */

1177        private JPanel JavaDoc status_area = null;
1178
1179        /**
1180         * Field status_buttons
1181         */

1182        private JPanel JavaDoc status_buttons = null;
1183
1184        /**
1185         * Field start_button
1186         */

1187        private JButton JavaDoc start_button = null;
1188
1189        /**
1190         * Field stop_button
1191         */

1192        private JButton JavaDoc stop_button = null;
1193
1194        /**
1195         * Field status_text
1196         */

1197        private JLabel JavaDoc status_text = null;
1198
1199        /**
1200         * Field status_text_panel
1201         */

1202        private JPanel JavaDoc status_text_panel = null;
1203
1204        /**
1205         * Field filter
1206         */

1207        private SOAPMonitorFilter filter = null;
1208
1209        /**
1210         * Field details_header_layout
1211         */

1212        private GridBagLayout JavaDoc details_header_layout = null;
1213
1214        /**
1215         * Field details_header_constraints
1216         */

1217        private GridBagConstraints JavaDoc details_header_constraints = null;
1218
1219        /**
1220         * Field reflow_xml
1221         */

1222        private JCheckBox JavaDoc reflow_xml = null;
1223
1224        /**
1225         * Constructor (create and layout page)
1226         *
1227         * @param host_name
1228         */

1229        public SOAPMonitorPage(String JavaDoc host_name) {
1230            host = host_name;
1231
1232            // Set up default filter (show all messages)
1233
filter = new SOAPMonitorFilter();
1234
1235            // Use borders to help improve appearance
1236
etched_border = new EtchedBorder JavaDoc();
1237
1238            // Build top portion of split (list panel)
1239
model = new SOAPMonitorTableModel();
1240            table = new JTable JavaDoc(model);
1241            table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
1242            table.setRowSelectionInterval(0, 0);
1243            table.setPreferredScrollableViewportSize(new Dimension JavaDoc(600, 96));
1244            table.getSelectionModel().addListSelectionListener(this);
1245            scroll = new JScrollPane JavaDoc(table);
1246            remove_button = new JButton JavaDoc("Remove");
1247            remove_button.addActionListener(this);
1248            remove_button.setEnabled(false);
1249            remove_all_button = new JButton JavaDoc("Remove All");
1250            remove_all_button.addActionListener(this);
1251            filter_button = new JButton JavaDoc("Filter ...");
1252            filter_button.addActionListener(this);
1253            list_buttons = new JPanel JavaDoc();
1254            list_buttons.setLayout(new FlowLayout JavaDoc());
1255            list_buttons.add(remove_button);
1256            list_buttons.add(remove_all_button);
1257            list_buttons.add(filter_button);
1258            list_panel = new JPanel JavaDoc();
1259            list_panel.setLayout(new BorderLayout JavaDoc());
1260            list_panel.add(scroll, BorderLayout.CENTER);
1261            list_panel.add(list_buttons, BorderLayout.SOUTH);
1262            list_panel.setBorder(empty_border);
1263
1264            // Build bottom portion of split (message details)
1265
details_time = new JLabel JavaDoc("Time: ", SwingConstants.RIGHT);
1266            details_target = new JLabel JavaDoc("Target Service: ",
1267                    SwingConstants.RIGHT);
1268            details_status = new JLabel JavaDoc("Status: ", SwingConstants.RIGHT);
1269            details_time_value = new JLabel JavaDoc();
1270            details_target_value = new JLabel JavaDoc();
1271            details_status_value = new JLabel JavaDoc();
1272            Dimension JavaDoc preferred_size = details_time.getPreferredSize();
1273            preferred_size.width = 1;
1274            details_time.setPreferredSize(preferred_size);
1275            details_target.setPreferredSize(preferred_size);
1276            details_status.setPreferredSize(preferred_size);
1277            details_time_value.setPreferredSize(preferred_size);
1278            details_target_value.setPreferredSize(preferred_size);
1279            details_status_value.setPreferredSize(preferred_size);
1280            details_header = new JPanel JavaDoc();
1281            details_header_layout = new GridBagLayout JavaDoc();
1282            details_header.setLayout(details_header_layout);
1283            details_header_constraints = new GridBagConstraints JavaDoc();
1284            details_header_constraints.fill = GridBagConstraints.BOTH;
1285            details_header_constraints.weightx = 0.5;
1286            details_header_layout.setConstraints(details_time,
1287                    details_header_constraints);
1288            details_header.add(details_time);
1289            details_header_layout.setConstraints(details_time_value,
1290                    details_header_constraints);
1291            details_header.add(details_time_value);
1292            details_header_layout.setConstraints(details_target,
1293                    details_header_constraints);
1294            details_header.add(details_target);
1295            details_header_constraints.weightx = 1.0;
1296            details_header_layout.setConstraints(details_target_value,
1297                    details_header_constraints);
1298            details_header.add(details_target_value);
1299            details_header_constraints.weightx = .5;
1300            details_header_layout.setConstraints(details_status,
1301                    details_header_constraints);
1302            details_header.add(details_status);
1303            details_header_layout.setConstraints(details_status_value,
1304                    details_header_constraints);
1305            details_header.add(details_status_value);
1306            details_header.setBorder(etched_border);
1307            request_label = new JLabel JavaDoc("SOAP Request", SwingConstants.CENTER);
1308            request_text = new SOAPMonitorTextArea();
1309            request_text.setEditable(false);
1310            request_scroll = new JScrollPane JavaDoc(request_text);
1311            request_panel = new JPanel JavaDoc();
1312            request_panel.setLayout(new BorderLayout JavaDoc());
1313            request_panel.add(request_label, BorderLayout.NORTH);
1314            request_panel.add(request_scroll, BorderLayout.CENTER);
1315            response_label =
1316                    new JLabel JavaDoc("SOAP Response", SwingConstants.CENTER);
1317            response_text = new SOAPMonitorTextArea();
1318            response_text.setEditable(false);
1319            response_scroll = new JScrollPane JavaDoc(response_text);
1320            response_panel = new JPanel JavaDoc();
1321            response_panel.setLayout(new BorderLayout JavaDoc());
1322            response_panel.add(response_label, BorderLayout.NORTH);
1323            response_panel.add(response_scroll, BorderLayout.CENTER);
1324            details_soap = new JSplitPane JavaDoc(JSplitPane.HORIZONTAL_SPLIT);
1325            details_soap.setTopComponent(request_panel);
1326            details_soap.setRightComponent(response_panel);
1327            details_soap.setResizeWeight(.5);
1328            details_panel = new JPanel JavaDoc();
1329            layout_button = new JButton JavaDoc("Switch Layout");
1330            layout_button.addActionListener(this);
1331            reflow_xml = new JCheckBox JavaDoc("Reflow XML text");
1332            reflow_xml.addActionListener(this);
1333            details_buttons = new JPanel JavaDoc();
1334            details_buttons.setLayout(new FlowLayout JavaDoc());
1335            details_buttons.add(reflow_xml);
1336            details_buttons.add(layout_button);
1337            details_panel.setLayout(new BorderLayout JavaDoc());
1338            details_panel.add(details_header, BorderLayout.NORTH);
1339            details_panel.add(details_soap, BorderLayout.CENTER);
1340            details_panel.add(details_buttons, BorderLayout.SOUTH);
1341            details_panel.setBorder(empty_border);
1342
1343            // Add the two parts to the age split pane
1344
split = new JSplitPane JavaDoc(JSplitPane.VERTICAL_SPLIT);
1345            split.setTopComponent(list_panel);
1346            split.setRightComponent(details_panel);
1347
1348            // Build status area
1349
start_button = new JButton JavaDoc("Start");
1350            start_button.addActionListener(this);
1351            stop_button = new JButton JavaDoc("Stop");
1352            stop_button.addActionListener(this);
1353            status_buttons = new JPanel JavaDoc();
1354            status_buttons.setLayout(new FlowLayout JavaDoc());
1355            status_buttons.add(start_button);
1356            status_buttons.add(stop_button);
1357            status_text = new JLabel JavaDoc();
1358            status_text.setBorder(new BevelBorder JavaDoc(BevelBorder.LOWERED));
1359            status_text_panel = new JPanel JavaDoc();
1360            status_text_panel.setLayout(new BorderLayout JavaDoc());
1361            status_text_panel.add(status_text, BorderLayout.CENTER);
1362            status_text_panel.setBorder(empty_border);
1363            status_area = new JPanel JavaDoc();
1364            status_area.setLayout(new BorderLayout JavaDoc());
1365            status_area.add(status_buttons, BorderLayout.WEST);
1366            status_area.add(status_text_panel, BorderLayout.CENTER);
1367            status_area.setBorder(etched_border);
1368
1369            // Add the split and status area to page
1370
setLayout(new BorderLayout JavaDoc());
1371            add(split, BorderLayout.CENTER);
1372            add(status_area, BorderLayout.SOUTH);
1373        }
1374
1375        /**
1376         * Get the name of the host we are displaying
1377         *
1378         * @return
1379         */

1380        public String JavaDoc getHost() {
1381            return host;
1382        }
1383
1384        /**
1385         * Set the status text
1386         *
1387         * @param txt
1388         */

1389        public void setStatus(String JavaDoc txt) {
1390            status_text.setForeground(Color.black);
1391            status_text.setText(" " + txt);
1392        }
1393
1394        /**
1395         * Set the status text to an error
1396         *
1397         * @param txt
1398         */

1399        public void setErrorStatus(String JavaDoc txt) {
1400            status_text.setForeground(Color.red);
1401            status_text.setText(" " + txt);
1402        }
1403
1404        /**
1405         * Start talking to the server
1406         */

1407        public void start() {
1408            String JavaDoc codehost = axisHost;
1409            if (socket == null) {
1410                try {
1411                    // Open the socket to the server
1412
socket = new Socket JavaDoc(codehost, port);
1413
1414                    // Create output stream
1415
out = new ObjectOutputStream JavaDoc(socket.getOutputStream());
1416                    out.flush();
1417
1418                    // Create input stream and start background
1419
// thread to read data from the server
1420
in = new ObjectInputStream JavaDoc(socket.getInputStream());
1421                    new Thread JavaDoc(this).start();
1422                } catch (Exception JavaDoc e) {
1423                    // Exceptions here are unexpected, but we can't
1424
// really do anything (so just write it to stdout
1425
// in case someone cares and then ignore it)
1426
e.printStackTrace();
1427                    setErrorStatus(STATUS_NOCONNECT);
1428                    socket = null;
1429                }
1430            } else {
1431                // Already started
1432
}
1433            if (socket != null) {
1434                // Make sure the right buttons are enabled
1435
start_button.setEnabled(false);
1436                stop_button.setEnabled(true);
1437                setStatus(STATUS_ACTIVE);
1438            }
1439        }
1440
1441        /**
1442         * Stop talking to the server
1443         */

1444        public void stop() {
1445            if (socket != null) {
1446                // Close all the streams and socket
1447
if (out != null) {
1448                    try {
1449                        out.close();
1450                    } catch (IOException JavaDoc ioe) {
1451                    }
1452                    out = null;
1453                }
1454                if (in != null) {
1455                    try {
1456                        in.close();
1457                    } catch (IOException JavaDoc ioe) {
1458                    }
1459                    in = null;
1460                }
1461                if (socket != null) {
1462                    try {
1463                        socket.close();
1464                    } catch (IOException JavaDoc ioe) {
1465                    }
1466                    socket = null;
1467                }
1468            } else {
1469                // Already stopped
1470
}
1471
1472            // Make sure the right buttons are enabled
1473
start_button.setEnabled(true);
1474            stop_button.setEnabled(false);
1475            setStatus(STATUS_STOPPED);
1476        }
1477
1478        /**
1479         * Background thread used to receive data from
1480         * the server.
1481         */

1482        public void run() {
1483            Long JavaDoc id;
1484            Integer JavaDoc message_type;
1485            String JavaDoc target;
1486            String JavaDoc soap;
1487            SOAPMonitorData data;
1488            int selected;
1489            int row;
1490            boolean update_needed;
1491            while (socket != null) {
1492                try {
1493                    // Get the data from the server
1494
message_type = (Integer JavaDoc) in.readObject();
1495
1496                    // Process the data depending on its type
1497
switch (message_type.intValue()) {
1498                        case SOAPMonitorConstants.SOAP_MONITOR_REQUEST:
1499
1500                            // Get the id, target and soap info
1501
id = (Long JavaDoc) in.readObject();
1502                            target = (String JavaDoc) in.readObject();
1503                            soap = (String JavaDoc) in.readObject();
1504
1505                            // Add new request data to the table
1506
data = new SOAPMonitorData(id, target, soap);
1507                            model.addData(data);
1508
1509                            // If "most recent" selected then update
1510
// the details area if needed
1511
selected = table.getSelectedRow();
1512                            if ((selected == 0) && model.filterMatch(data)) {
1513                                valueChanged(null);
1514                            }
1515                            break;
1516                        case SOAPMonitorConstants.SOAP_MONITOR_RESPONSE:
1517
1518                            // Get the id and soap info
1519
id = (Long JavaDoc) in.readObject();
1520                            soap = (String JavaDoc) in.readObject();
1521                            data = model.findData(id);
1522                            if (data != null) {
1523                                update_needed = false;
1524
1525                                // Get the selected row
1526
selected = table.getSelectedRow();
1527
1528                                // If "most recent", then always
1529
// update details area
1530
if (selected == 0) {
1531                                    update_needed = true;
1532                                }
1533
1534                                // If the data being updated is
1535
// selected then update details
1536
row = model.findRow(data);
1537                                if ((row != -1) && (row == selected)) {
1538                                    update_needed = true;
1539                                }
1540
1541                                // Set the response and update table
1542
data.setSOAPResponse(soap);
1543                                model.updateData(data);
1544
1545                                // Refresh details area (if needed)
1546
if (update_needed) {
1547                                    valueChanged(null);
1548                                }
1549                            }
1550                            break;
1551                    }
1552                } catch (Exception JavaDoc e) {
1553                    // Exceptions are expected here when the
1554
// server communication has been terminated.
1555
if (stop_button.isEnabled()) {
1556                        stop();
1557                        setErrorStatus(STATUS_CLOSED);
1558                    }
1559                }
1560            }
1561        }
1562
1563        /**
1564         * Listener to handle table selection changes
1565         *
1566         * @param e
1567         */

1568        public void valueChanged(ListSelectionEvent JavaDoc e) {
1569            int row = table.getSelectedRow();
1570
1571            // Check if they selected a specific row
1572
if (row > 0) {
1573                remove_button.setEnabled(true);
1574            } else {
1575                remove_button.setEnabled(false);
1576            }
1577
1578            // Check for "most recent" selection
1579
if (row == 0) {
1580                row = model.getRowCount() - 1;
1581                if (row == 0) {
1582                    row = -1;
1583                }
1584            }
1585            if (row == -1) {
1586                // Clear the details panel
1587
details_time_value.setText("");
1588                details_target_value.setText("");
1589                details_status_value.setText("");
1590                request_text.setText("");
1591                response_text.setText("");
1592            } else {
1593                // Show the details for the row
1594
SOAPMonitorData soap = model.getData(row);
1595                details_time_value.setText(soap.getTime());
1596                details_target_value.setText(soap.getTargetService());
1597                details_status_value.setText(soap.getStatus());
1598                if (soap.getSOAPRequest() == null) {
1599                    request_text.setText("");
1600                } else {
1601                    request_text.setText(soap.getSOAPRequest());
1602                    request_text.setCaretPosition(0);
1603                }
1604                if (soap.getSOAPResponse() == null) {
1605                    response_text.setText("");
1606                } else {
1607                    response_text.setText(soap.getSOAPResponse());
1608                    response_text.setCaretPosition(0);
1609                }
1610            }
1611        }
1612
1613        /**
1614         * Listener to handle button actions
1615         *
1616         * @param e
1617         */

1618        public void actionPerformed(ActionEvent JavaDoc e) {
1619            // Check if the user pressed the remove button
1620
if (e.getSource() == remove_button) {
1621                int row = table.getSelectedRow();
1622                model.removeRow(row);
1623                table.clearSelection();
1624                table.repaint();
1625                valueChanged(null);
1626            }
1627
1628            // Check if the user pressed the remove all button
1629
if (e.getSource() == remove_all_button) {
1630                model.clearAll();
1631                table.setRowSelectionInterval(0, 0);
1632                table.repaint();
1633                valueChanged(null);
1634            }
1635
1636            // Check if the user pressed the filter button
1637
if (e.getSource() == filter_button) {
1638                filter.showDialog();
1639                if (filter.okPressed()) {
1640                    // Update the display with new filter
1641
model.setFilter(filter);
1642                    table.repaint();
1643                }
1644            }
1645
1646            // Check if the user pressed the start button
1647
if (e.getSource() == start_button) {
1648                start();
1649            }
1650
1651            // Check if the user pressed the stop button
1652
if (e.getSource() == stop_button) {
1653                stop();
1654            }
1655
1656            // Check if the user wants to switch layout
1657
if (e.getSource() == layout_button) {
1658                details_panel.remove(details_soap);
1659                details_soap.removeAll();
1660                if (details_soap.getOrientation()
1661                        == JSplitPane.HORIZONTAL_SPLIT) {
1662                    details_soap = new JSplitPane JavaDoc(JSplitPane.VERTICAL_SPLIT);
1663                } else {
1664                    details_soap = new JSplitPane JavaDoc(JSplitPane.HORIZONTAL_SPLIT);
1665                }
1666                details_soap.setTopComponent(request_panel);
1667                details_soap.setRightComponent(response_panel);
1668                details_soap.setResizeWeight(.5);
1669                details_panel.add(details_soap, BorderLayout.CENTER);
1670                details_panel.validate();
1671                details_panel.repaint();
1672            }
1673
1674            // Check if the user is changing the reflow option
1675
if (e.getSource() == reflow_xml) {
1676                request_text.setReflowXML(reflow_xml.isSelected());
1677                response_text.setReflowXML(reflow_xml.isSelected());
1678            }
1679        }
1680    }
1681
1682    /**
1683     * This class represend the data for a SOAP request/response pair
1684     */

1685    class SOAPMonitorData {
1686
1687        /**
1688         * Private data
1689         */

1690        private Long JavaDoc id;
1691
1692        /**
1693         * Field time
1694         */

1695        private String JavaDoc time;
1696
1697        /**
1698         * Field target
1699         */

1700        private String JavaDoc target;
1701
1702        /**
1703         * Field soap_request
1704         */

1705        private String JavaDoc soap_request;
1706
1707        /**
1708         * Field soap_response
1709         */

1710        private String JavaDoc soap_response;
1711
1712        /**
1713         * Constructor
1714         *
1715         * @param id
1716         * @param target
1717         * @param soap_request
1718         */

1719        public SOAPMonitorData(Long JavaDoc id, String JavaDoc target, String JavaDoc soap_request) {
1720            this.id = id;
1721
1722            // A null id is used to signal that the "most recent" entry
1723
// is being created.
1724
if (id == null) {
1725                this.time = "Most Recent";
1726                this.target = "---";
1727                this.soap_request = null;
1728                this.soap_response = null;
1729            } else {
1730                this.time =
1731                        DateFormat.getTimeInstance().format(new Date JavaDoc());
1732                this.target = target;
1733                this.soap_request = soap_request;
1734                this.soap_response = null;
1735            }
1736        }
1737
1738        /**
1739         * Get the id for the SOAP message
1740         *
1741         * @return
1742         */

1743        public Long JavaDoc getId() {
1744            return id;
1745        }
1746
1747        /**
1748         * Get the time the SOAP request was received by the application
1749         *
1750         * @return
1751         */

1752        public String JavaDoc getTime() {
1753            return time;
1754        }
1755
1756        /**
1757         * Get the SOAP request target service name
1758         *
1759         * @return
1760         */

1761        public String JavaDoc getTargetService() {
1762            return target;
1763        }
1764
1765        /**
1766         * Get the status of the request
1767         *
1768         * @return
1769         */

1770        public String JavaDoc getStatus() {
1771            String JavaDoc status = "---";
1772            if (id != null) {
1773                status = "Complete";
1774                if (soap_response == null) {
1775                    status = "Active";
1776                }
1777            }
1778            return status;
1779        }
1780
1781        /**
1782         * Get the request SOAP contents
1783         *
1784         * @return
1785         */

1786        public String JavaDoc getSOAPRequest() {
1787            return soap_request;
1788        }
1789
1790        /**
1791         * Set the resposne SOAP contents
1792         *
1793         * @param response
1794         */

1795        public void setSOAPResponse(String JavaDoc response) {
1796            soap_response = response;
1797        }
1798
1799        /**
1800         * Get the response SOAP contents
1801         *
1802         * @return
1803         */

1804        public String JavaDoc getSOAPResponse() {
1805            return soap_response;
1806        }
1807    }
1808
1809    /**
1810     * This table model is used to manage the table displayed
1811     * at the top of the page to show all the SOAP messages
1812     * we have received and to control which message details are
1813     * to be displayed on the bottom of the page.
1814     */

1815    class SOAPMonitorTableModel extends AbstractTableModel JavaDoc {
1816
1817        /**
1818         * Column titles
1819         */

1820        private final String JavaDoc[] column_names = {"Time", "Target Service",
1821                                               "Status"};
1822
1823        /**
1824         * Private data
1825         */

1826        private Vector JavaDoc data;
1827
1828        /**
1829         * Field filter_include
1830         */

1831        private Vector JavaDoc filter_include;
1832
1833        /**
1834         * Field filter_exclude
1835         */

1836        private Vector JavaDoc filter_exclude;
1837
1838        /**
1839         * Field filter_active
1840         */

1841        private boolean filter_active;
1842
1843        /**
1844         * Field filter_complete
1845         */

1846        private boolean filter_complete;
1847
1848        /**
1849         * Field filter_data
1850         */

1851        private Vector JavaDoc filter_data;
1852
1853        /**
1854         * Constructor
1855         */

1856        public SOAPMonitorTableModel() {
1857            data = new Vector JavaDoc();
1858
1859            // Add "most recent" entry to top of table
1860
SOAPMonitorData soap = new SOAPMonitorData(null, null, null);
1861            data.addElement(soap);
1862            filter_include = null;
1863            filter_exclude = null;
1864            filter_active = false;
1865            filter_complete = false;
1866            filter_data = null;
1867
1868            // By default, exclude NotificationService and
1869
// EventViewerService messages
1870
filter_exclude = new Vector JavaDoc();
1871            filter_exclude.addElement("NotificationService");
1872            filter_exclude.addElement("EventViewerService");
1873            filter_data = new Vector JavaDoc();
1874            filter_data.addElement(soap);
1875        }
1876
1877        /**
1878         * Get column count (part of table model interface)
1879         *
1880         * @return
1881         */

1882        public int getColumnCount() {
1883            return column_names.length;
1884        }
1885
1886        /**
1887         * Get row count (part of table model interface)
1888         *
1889         * @return
1890         */

1891        public int getRowCount() {
1892            int count = data.size();
1893            if (filter_data != null) {
1894                count = filter_data.size();
1895            }
1896            return count;
1897        }
1898
1899        /**
1900         * Get column name (part of table model interface)
1901         *
1902         * @param col
1903         * @return
1904         */

1905        public String JavaDoc getColumnName(int col) {
1906            return column_names[col];
1907        }
1908
1909        /**
1910         * Get value at (part of table model interface)
1911         *
1912         * @param row
1913         * @param col
1914         * @return
1915         */

1916        public Object JavaDoc getValueAt(int row, int col) {
1917            SOAPMonitorData soap;
1918            String JavaDoc value = null;
1919            soap = (SOAPMonitorData) data.elementAt(row);
1920            if (filter_data != null) {
1921                soap = (SOAPMonitorData) filter_data.elementAt(row);
1922            }
1923            switch (col) {
1924                case 0:
1925                    value = soap.getTime();
1926                    break;
1927                case 1:
1928                    value = soap.getTargetService();
1929                    break;
1930                case 2:
1931                    value = soap.getStatus();
1932                    break;
1933            }
1934            return value;
1935        }
1936
1937        /**
1938         * Check if soap data matches filter
1939         *
1940         * @param soap
1941         * @return
1942         */

1943        public boolean filterMatch(SOAPMonitorData soap) {
1944            boolean match = true;
1945            if (filter_include != null) {
1946                // Check for service match
1947
Enumeration JavaDoc e = filter_include.elements();
1948                match = false;
1949                while (e.hasMoreElements() && !match) {
1950                    String JavaDoc service = (String JavaDoc) e.nextElement();
1951                    if (service.equals(soap.getTargetService())) {
1952                        match = true;
1953                    }
1954                }
1955            }
1956            if (filter_exclude != null) {
1957                // Check for service match
1958
Enumeration JavaDoc e = filter_exclude.elements();
1959                while (e.hasMoreElements() && match) {
1960                    String JavaDoc service = (String JavaDoc) e.nextElement();
1961                    if (service.equals(soap.getTargetService())) {
1962                        match = false;
1963                    }
1964                }
1965            }
1966            if (filter_active) {
1967                // Check for active status match
1968
if (soap.getSOAPResponse() != null) {
1969                    match = false;
1970                }
1971            }
1972            if (filter_complete) {
1973                // Check for complete status match
1974
if (soap.getSOAPResponse() == null) {
1975                    match = false;
1976                }
1977            }
1978
1979            // The "most recent" is always a match
1980
if (soap.getId() == null) {
1981                match = true;
1982            }
1983            return match;
1984        }
1985
1986        /**
1987         * Add data to the table as a new row
1988         *
1989         * @param soap
1990         */

1991        public void addData(SOAPMonitorData soap) {
1992            int row = data.size();
1993            data.addElement(soap);
1994            if (filter_data != null) {
1995                if (filterMatch(soap)) {
1996                    row = filter_data.size();
1997                    filter_data.addElement(soap);
1998                    fireTableRowsInserted(row, row);
1999                }
2000            } else {
2001                fireTableRowsInserted(row, row);
2002            }
2003        }
2004
2005        /**
2006         * Find the data for a given id
2007         *
2008         * @param id
2009         * @return
2010         */

2011        public SOAPMonitorData findData(Long JavaDoc id) {
2012            SOAPMonitorData soap = null;
2013            for (int row = data.size(); (row > 0) && (soap == null); row--) {
2014                soap = (SOAPMonitorData) data.elementAt(row - 1);
2015                if (soap.getId().longValue() != id.longValue()) {
2016                    soap = null;
2017                }
2018            }
2019            return soap;
2020        }
2021
2022        /**
2023         * Find the row in the table for a given message id
2024         *
2025         * @param soap
2026         * @return
2027         */

2028        public int findRow(SOAPMonitorData soap) {
2029            int row = -1;
2030            if (filter_data != null) {
2031                row = filter_data.indexOf(soap);
2032            } else {
2033                row = data.indexOf(soap);
2034            }
2035            return row;
2036        }
2037
2038        /**
2039         * Remove all messages from the table (but leave "most recent")
2040         */

2041        public void clearAll() {
2042            int last_row = data.size() - 1;
2043            if (last_row > 0) {
2044                data.removeAllElements();
2045                SOAPMonitorData soap = new SOAPMonitorData(null, null, null);
2046                data.addElement(soap);
2047                if (filter_data != null) {
2048                    filter_data.removeAllElements();
2049                    filter_data.addElement(soap);
2050                }
2051                fireTableDataChanged();
2052            }
2053        }
2054
2055        /**
2056         * Remove a message from the table
2057         *
2058         * @param row
2059         */

2060        public void removeRow(int row) {
2061            SOAPMonitorData soap = null;
2062            if (filter_data == null) {
2063                soap = (SOAPMonitorData) data.elementAt(row);
2064                data.remove(soap);
2065            } else {
2066                soap = (SOAPMonitorData) filter_data.elementAt(row);
2067                filter_data.remove(soap);
2068                data.remove(soap);
2069            }
2070            fireTableRowsDeleted(row, row);
2071        }
2072
2073        /**
2074         * Set a new filter
2075         *
2076         * @param filter
2077         */

2078        public void setFilter(SOAPMonitorFilter filter) {
2079            // Save new filter criteria
2080
filter_include = filter.getFilterIncludeList();
2081            filter_exclude = filter.getFilterExcludeList();
2082            filter_active = filter.getFilterActive();
2083            filter_complete = filter.getFilterComplete();
2084            applyFilter();
2085        }
2086
2087        /**
2088         * Refilter the list of messages
2089         */

2090        public void applyFilter() {
2091            // Re-filter using new criteria
2092
filter_data = null;
2093            if ((filter_include != null) || (filter_exclude != null)
2094                    || filter_active || filter_complete) {
2095                filter_data = new Vector JavaDoc();
2096                Enumeration JavaDoc e = data.elements();
2097                SOAPMonitorData soap;
2098                while (e.hasMoreElements()) {
2099                    soap = (SOAPMonitorData) e.nextElement();
2100                    if (filterMatch(soap)) {
2101                        filter_data.addElement(soap);
2102                    }
2103                }
2104            }
2105            fireTableDataChanged();
2106        }
2107
2108        /**
2109         * Get the data for a row
2110         *
2111         * @param row
2112         * @return
2113         */

2114        public SOAPMonitorData getData(int row) {
2115            SOAPMonitorData soap = null;
2116            if (filter_data == null) {
2117                soap = (SOAPMonitorData) data.elementAt(row);
2118            } else {
2119                soap = (SOAPMonitorData) filter_data.elementAt(row);
2120            }
2121            return soap;
2122        }
2123
2124        /**
2125         * Update a message
2126         *
2127         * @param soap
2128         */

2129        public void updateData(SOAPMonitorData soap) {
2130            int row;
2131            if (filter_data == null) {
2132                // No filter, so just fire table updated
2133
row = data.indexOf(soap);
2134                if (row != -1) {
2135                    fireTableRowsUpdated(row, row);
2136                }
2137            } else {
2138                // Check if the row was being displayed
2139
row = filter_data.indexOf(soap);
2140                if (row == -1) {
2141                    // Row was not displayed, so check for if it
2142
// now needs to be displayed
2143
if (filterMatch(soap)) {
2144                        int index = -1;
2145                        row = data.indexOf(soap) + 1;
2146                        while ((row < data.size()) && (index == -1)) {
2147                            index = filter_data.indexOf(data.elementAt(row));
2148                            if (index != -1) {
2149                                // Insert at this location
2150
filter_data.add(index, soap);
2151                            }
2152                            row++;
2153                        }
2154                        if (index == -1) {
2155                            // Insert at end
2156
index = filter_data.size();
2157                            filter_data.addElement(soap);
2158                        }
2159                        fireTableRowsInserted(index, index);
2160                    }
2161                } else {
2162                    // Row was displayed, so check if it needs to
2163
// be updated or removed
2164
if (filterMatch(soap)) {
2165                        fireTableRowsUpdated(row, row);
2166                    } else {
2167                        filter_data.remove(soap);
2168                        fireTableRowsDeleted(row, row);
2169                    }
2170                }
2171            }
2172        }
2173    }
2174
2175    /**
2176     * Panel with checkbox and list
2177     */

2178    class ServiceFilterPanel extends JPanel JavaDoc
2179            implements ActionListener JavaDoc, ListSelectionListener JavaDoc, DocumentListener JavaDoc {
2180
2181        /**
2182         * Field service_box
2183         */

2184        private JCheckBox JavaDoc service_box = null;
2185
2186        /**
2187         * Field filter_list
2188         */

2189        private Vector JavaDoc filter_list = null;
2190
2191        /**
2192         * Field service_data
2193         */

2194        private Vector JavaDoc service_data = null;
2195
2196        /**
2197         * Field service_list
2198         */

2199        private JList JavaDoc service_list = null;
2200
2201        /**
2202         * Field service_scroll
2203         */

2204        private JScrollPane JavaDoc service_scroll = null;
2205
2206        /**
2207         * Field remove_service_button
2208         */

2209        private JButton JavaDoc remove_service_button = null;
2210
2211        /**
2212         * Field remove_service_panel
2213         */

2214        private JPanel JavaDoc remove_service_panel = null;
2215
2216        /**
2217         * Field indent_border
2218         */

2219        private EmptyBorder JavaDoc indent_border = null;
2220
2221        /**
2222         * Field empty_border
2223         */

2224        private EmptyBorder JavaDoc empty_border = null;
2225
2226        /**
2227         * Field service_area
2228         */

2229        private JPanel JavaDoc service_area = null;
2230
2231        /**
2232         * Field add_service_area
2233         */

2234        private JPanel JavaDoc add_service_area = null;
2235
2236        /**
2237         * Field add_service_field
2238         */

2239        private JTextField JavaDoc add_service_field = null;
2240
2241        /**
2242         * Field add_service_button
2243         */

2244        private JButton JavaDoc add_service_button = null;
2245
2246        /**
2247         * Field add_service_panel
2248         */

2249        private JPanel JavaDoc add_service_panel = null;
2250
2251        /**
2252         * Constructor
2253         *
2254         * @param text
2255         * @param list
2256         */

2257        public ServiceFilterPanel(String JavaDoc text, Vector JavaDoc list) {
2258            empty_border = new EmptyBorder JavaDoc(5, 5, 0, 5);
2259            indent_border = new EmptyBorder JavaDoc(5, 25, 5, 5);
2260            service_box = new JCheckBox JavaDoc(text);
2261            service_box.addActionListener(this);
2262            service_data = new Vector JavaDoc();
2263            if (list != null) {
2264                service_box.setSelected(true);
2265                service_data = (Vector JavaDoc) list.clone();
2266            }
2267            service_list = new JList JavaDoc(service_data);
2268            service_list.setBorder(new EtchedBorder JavaDoc());
2269            service_list.setVisibleRowCount(5);
2270            service_list.addListSelectionListener(this);
2271            service_list.setEnabled(service_box.isSelected());
2272            service_scroll = new JScrollPane JavaDoc(service_list);
2273            service_scroll.setBorder(new EtchedBorder JavaDoc());
2274            remove_service_button = new JButton JavaDoc("Remove");
2275            remove_service_button.addActionListener(this);
2276            remove_service_button.setEnabled(false);
2277            remove_service_panel = new JPanel JavaDoc();
2278            remove_service_panel.setLayout(new FlowLayout JavaDoc());
2279            remove_service_panel.add(remove_service_button);
2280            service_area = new JPanel JavaDoc();
2281            service_area.setLayout(new BorderLayout JavaDoc());
2282            service_area.add(service_scroll, BorderLayout.CENTER);
2283            service_area.add(remove_service_panel, BorderLayout.EAST);
2284            service_area.setBorder(indent_border);
2285            add_service_field = new JTextField JavaDoc();
2286            add_service_field.addActionListener(this);
2287            add_service_field.getDocument().addDocumentListener(this);
2288            add_service_field.setEnabled(service_box.isSelected());
2289            add_service_button = new JButton JavaDoc("Add");
2290            add_service_button.addActionListener(this);
2291            add_service_button.setEnabled(false);
2292            add_service_panel = new JPanel JavaDoc();
2293            add_service_panel.setLayout(new BorderLayout JavaDoc());
2294            JPanel JavaDoc dummy = new JPanel JavaDoc();
2295            dummy.setBorder(empty_border);
2296            add_service_panel.add(dummy, BorderLayout.WEST);
2297            add_service_panel.add(add_service_button, BorderLayout.EAST);
2298            add_service_area = new JPanel JavaDoc();
2299            add_service_area.setLayout(new BorderLayout JavaDoc());
2300            add_service_area.add(add_service_field, BorderLayout.CENTER);
2301            add_service_area.add(add_service_panel, BorderLayout.EAST);
2302            add_service_area.setBorder(indent_border);
2303            setLayout(new BorderLayout JavaDoc());
2304            add(service_box, BorderLayout.NORTH);
2305            add(service_area, BorderLayout.CENTER);
2306            add(add_service_area, BorderLayout.SOUTH);
2307            setBorder(empty_border);
2308        }
2309
2310        /**
2311         * Get the current list of services
2312         *
2313         * @return
2314         */

2315        public Vector JavaDoc getServiceList() {
2316            Vector JavaDoc list = null;
2317            if (service_box.isSelected()) {
2318                list = service_data;
2319            }
2320            return list;
2321        }
2322
2323        /**
2324         * Listener to handle button actions
2325         *
2326         * @param e
2327         */

2328        public void actionPerformed(ActionEvent JavaDoc e) {
2329            // Check if the user changed the service filter option
2330
if (e.getSource() == service_box) {
2331                service_list.setEnabled(service_box.isSelected());
2332                service_list.clearSelection();
2333                remove_service_button.setEnabled(false);
2334                add_service_field.setEnabled(service_box.isSelected());
2335                add_service_field.setText("");
2336                add_service_button.setEnabled(false);
2337            }
2338
2339            // Check if the user pressed the add service button
2340
if ((e.getSource() == add_service_button)
2341                    || (e.getSource() == add_service_field)) {
2342                String JavaDoc text = add_service_field.getText();
2343                if ((text != null) && (text.length() > 0)) {
2344                    service_data.addElement(text);
2345                    service_list.setListData(service_data);
2346                }
2347                add_service_field.setText("");
2348                add_service_field.requestFocus();
2349            }
2350
2351            // Check if the user pressed the remove service button
2352
if (e.getSource() == remove_service_button) {
2353                Object JavaDoc[] sels = service_list.getSelectedValues();
2354                for (int i = 0; i < sels.length; i++) {
2355                    service_data.removeElement(sels[i]);
2356                }
2357                service_list.setListData(service_data);
2358                service_list.clearSelection();
2359            }
2360        }
2361
2362        /**
2363         * Handle changes to the text field
2364         *
2365         * @param e
2366         */

2367        public void changedUpdate(DocumentEvent JavaDoc e) {
2368            String JavaDoc text = add_service_field.getText();
2369            if ((text != null) && (text.length() > 0)) {
2370                add_service_button.setEnabled(true);
2371            } else {
2372                add_service_button.setEnabled(false);
2373            }
2374        }
2375
2376        /**
2377         * Handle changes to the text field
2378         *
2379         * @param e
2380         */

2381        public void insertUpdate(DocumentEvent JavaDoc e) {
2382            changedUpdate(e);
2383        }
2384
2385        /**
2386         * Handle changes to the text field
2387         *
2388         * @param e
2389         */

2390        public void removeUpdate(DocumentEvent JavaDoc e) {
2391            changedUpdate(e);
2392        }
2393
2394        /**
2395         * Listener to handle service list selection changes
2396         *
2397         * @param e
2398         */

2399        public void valueChanged(ListSelectionEvent JavaDoc e) {
2400            if (service_list.getSelectedIndex() == -1) {
2401                remove_service_button.setEnabled(false);
2402            } else {
2403                remove_service_button.setEnabled(true);
2404            }
2405        }
2406    }
2407
2408    /**
2409     * Class for showing the filter dialog
2410     */

2411    class SOAPMonitorFilter implements ActionListener JavaDoc {
2412
2413        /**
2414         * Private data
2415         */

2416        private JDialog JavaDoc dialog = null;
2417
2418        /**
2419         * Field panel
2420         */

2421        private JPanel JavaDoc panel = null;
2422
2423        /**
2424         * Field buttons
2425         */

2426        private JPanel JavaDoc buttons = null;
2427
2428        /**
2429         * Field ok_button
2430         */

2431        private JButton JavaDoc ok_button = null;
2432
2433        /**
2434         * Field cancel_button
2435         */

2436        private JButton JavaDoc cancel_button = null;
2437
2438        /**
2439         * Field include_panel
2440         */

2441        private ServiceFilterPanel include_panel = null;
2442
2443        /**
2444         * Field exclude_panel
2445         */

2446        private ServiceFilterPanel exclude_panel = null;
2447
2448        /**
2449         * Field status_panel
2450         */

2451        private JPanel JavaDoc status_panel = null;
2452
2453        /**
2454         * Field status_box
2455         */

2456        private JCheckBox JavaDoc status_box = null;
2457
2458        /**
2459         * Field empty_border
2460         */

2461        private EmptyBorder JavaDoc empty_border = null;
2462
2463        /**
2464         * Field indent_border
2465         */

2466        private EmptyBorder JavaDoc indent_border = null;
2467
2468        /**
2469         * Field status_options
2470         */

2471        private JPanel JavaDoc status_options = null;
2472
2473        /**
2474         * Field status_group
2475         */

2476        private ButtonGroup JavaDoc status_group = null;
2477
2478        /**
2479         * Field status_active
2480         */

2481        private JRadioButton JavaDoc status_active = null;
2482
2483        /**
2484         * Field status_complete
2485         */

2486        private JRadioButton JavaDoc status_complete = null;
2487
2488        /**
2489         * Field filter_include_list
2490         */

2491        private Vector JavaDoc filter_include_list = null;
2492
2493        /**
2494         * Field filter_exclude_list
2495         */

2496        private Vector JavaDoc filter_exclude_list = null;
2497
2498        /**
2499         * Field filter_active
2500         */

2501        private boolean filter_active = false;
2502
2503        /**
2504         * Field filter_complete
2505         */

2506        private boolean filter_complete = false;
2507
2508        /**
2509         * Field ok_pressed
2510         */

2511        private boolean ok_pressed = false;
2512
2513        /**
2514         * Constructor
2515         */

2516        public SOAPMonitorFilter() {
2517            // By default, exclude NotificationService and
2518
// EventViewerService messages
2519
filter_exclude_list = new Vector JavaDoc();
2520            filter_exclude_list.addElement("NotificationService");
2521            filter_exclude_list.addElement("EventViewerService");
2522        }
2523
2524        /**
2525         * Get list of services to be included
2526         *
2527         * @return
2528         */

2529        public Vector JavaDoc getFilterIncludeList() {
2530            return filter_include_list;
2531        }
2532
2533        /**
2534         * Get list of services to be excluded
2535         *
2536         * @return
2537         */

2538        public Vector JavaDoc getFilterExcludeList() {
2539            return filter_exclude_list;
2540        }
2541
2542        /**
2543         * Check if filter active messages
2544         *
2545         * @return
2546         */

2547        public boolean getFilterActive() {
2548            return filter_active;
2549        }
2550
2551        /**
2552         * Check if filter complete messages
2553         *
2554         * @return
2555         */

2556        public boolean getFilterComplete() {
2557            return filter_complete;
2558        }
2559
2560        /**
2561         * Show the filter dialog
2562         */

2563        public void showDialog() {
2564            empty_border = new EmptyBorder JavaDoc(5, 5, 0, 5);
2565            indent_border = new EmptyBorder JavaDoc(5, 25, 5, 5);
2566            include_panel = new ServiceFilterPanel(
2567                    "Include messages based on target service:",
2568                    filter_include_list);
2569            exclude_panel = new ServiceFilterPanel(
2570                    "Exclude messages based on target service:",
2571                    filter_exclude_list);
2572            status_box = new JCheckBox JavaDoc("Filter messages based on status:");
2573            status_box.addActionListener(this);
2574            status_active = new JRadioButton JavaDoc("Active messages only");
2575            status_active.setSelected(true);
2576            status_active.setEnabled(false);
2577            status_complete = new JRadioButton JavaDoc("Complete messages only");
2578            status_complete.setEnabled(false);
2579            status_group = new ButtonGroup JavaDoc();
2580            status_group.add(status_active);
2581            status_group.add(status_complete);
2582            if (filter_active || filter_complete) {
2583                status_box.setSelected(true);
2584                status_active.setEnabled(true);
2585                status_complete.setEnabled(true);
2586                if (filter_complete) {
2587                    status_complete.setSelected(true);
2588                }
2589            }
2590            status_options = new JPanel JavaDoc();
2591            status_options.setLayout(new BoxLayout JavaDoc(status_options,
2592                    BoxLayout.Y_AXIS));
2593            status_options.add(status_active);
2594            status_options.add(status_complete);
2595            status_options.setBorder(indent_border);
2596            status_panel = new JPanel JavaDoc();
2597            status_panel.setLayout(new BorderLayout JavaDoc());
2598            status_panel.add(status_box, BorderLayout.NORTH);
2599            status_panel.add(status_options, BorderLayout.CENTER);
2600            status_panel.setBorder(empty_border);
2601            ok_button = new JButton JavaDoc("Ok");
2602            ok_button.addActionListener(this);
2603            cancel_button = new JButton JavaDoc("Cancel");
2604            cancel_button.addActionListener(this);
2605            buttons = new JPanel JavaDoc();
2606            buttons.setLayout(new FlowLayout JavaDoc());
2607            buttons.add(ok_button);
2608            buttons.add(cancel_button);
2609            panel = new JPanel JavaDoc();
2610            panel.setLayout(new BoxLayout JavaDoc(panel, BoxLayout.Y_AXIS));
2611            panel.add(include_panel);
2612            panel.add(exclude_panel);
2613            panel.add(status_panel);
2614            panel.add(buttons);
2615            dialog = new JDialog JavaDoc();
2616            dialog.setTitle("SOAP Monitor Filter");
2617            dialog.setContentPane(panel);
2618            dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
2619            dialog.setModal(true);
2620            dialog.pack();
2621            Dimension JavaDoc d = dialog.getToolkit().getScreenSize();
2622            dialog.setLocation((d.width - dialog.getWidth()) / 2,
2623                    (d.height - dialog.getHeight()) / 2);
2624            ok_pressed = false;
2625            dialog.show();
2626        }
2627
2628        /**
2629         * Listener to handle button actions
2630         *
2631         * @param e
2632         */

2633        public void actionPerformed(ActionEvent JavaDoc e) {
2634            // Check if the user pressed the ok button
2635
if (e.getSource() == ok_button) {
2636                filter_include_list = include_panel.getServiceList();
2637                filter_exclude_list = exclude_panel.getServiceList();
2638                if (status_box.isSelected()) {
2639                    filter_active = status_active.isSelected();
2640                    filter_complete = status_complete.isSelected();
2641                } else {
2642                    filter_active = false;
2643                    filter_complete = false;
2644                }
2645                ok_pressed = true;
2646                dialog.dispose();
2647            }
2648
2649            // Check if the user pressed the cancel button
2650
if (e.getSource() == cancel_button) {
2651                dialog.dispose();
2652            }
2653
2654            // Check if the user changed the status filter option
2655
if (e.getSource() == status_box) {
2656                status_active.setEnabled(status_box.isSelected());
2657                status_complete.setEnabled(status_box.isSelected());
2658            }
2659        }
2660
2661        /**
2662         * Check if the user pressed the ok button
2663         *
2664         * @return
2665         */

2666        public boolean okPressed() {
2667            return ok_pressed;
2668        }
2669    }
2670
2671    /**
2672     * Text panel class that supports XML reflow
2673     */

2674    class SOAPMonitorTextArea extends JTextArea JavaDoc {
2675
2676        /**
2677         * Private data
2678         */

2679        private boolean format = false;
2680
2681        /**
2682         * Field original
2683         */

2684        private String JavaDoc original = "";
2685
2686        /**
2687         * Field formatted
2688         */

2689        private String JavaDoc formatted = null;
2690
2691        /**
2692         * Constructor
2693         */

2694        public SOAPMonitorTextArea() {
2695        }
2696
2697        /**
2698         * Override setText to do formatting
2699         *
2700         * @param text
2701         */

2702        public void setText(String JavaDoc text) {
2703            original = text;
2704            formatted = null;
2705            if (format) {
2706                doFormat();
2707                super.setText(formatted);
2708            } else {
2709                super.setText(original);
2710            }
2711        }
2712
2713        /**
2714         * Turn reflow on or off
2715         *
2716         * @param reflow
2717         */

2718        public void setReflowXML(boolean reflow) {
2719            format = reflow;
2720            if (format) {
2721                if (formatted == null) {
2722                    doFormat();
2723                }
2724                super.setText(formatted);
2725            } else {
2726                super.setText(original);
2727            }
2728        }
2729
2730        /**
2731         * Reflow XML
2732         */

2733        public void doFormat() {
2734            Vector JavaDoc parts = new Vector JavaDoc();
2735            char[] chars = original.toCharArray();
2736            int index = 0;
2737            int first = 0;
2738            String JavaDoc part = null;
2739            while (index < chars.length) {
2740                // Check for start of tag
2741
if (chars[index] == '<') {
2742                    // Did we have data before this tag?
2743
if (first < index) {
2744                        part = new String JavaDoc(chars, first, index - first);
2745                        part = part.trim();
2746
2747                        // Save non-whitespace data
2748
if (part.length() > 0) {
2749                            parts.addElement(part);
2750                        }
2751                    }
2752
2753                    // Save the start of tag
2754
first = index;
2755                }
2756
2757                // Check for end of tag
2758
if (chars[index] == '>') {
2759                    // Save the tag
2760
part = new String JavaDoc(chars, first, index - first + 1);
2761                    parts.addElement(part);
2762                    first = index + 1;
2763                }
2764
2765                // Check for end of line
2766
if ((chars[index] == '\n') || (chars[index] == '\r')) {
2767                    // Was there data on this line?
2768
if (first < index) {
2769                        part = new String JavaDoc(chars, first, index - first);
2770                        part = part.trim();
2771
2772                        // Save non-whitespace data
2773
if (part.length() > 0) {
2774                            parts.addElement(part);
2775                        }
2776                    }
2777                    first = index + 1;
2778                }
2779                index++;
2780            }
2781
2782            // Reflow as XML
2783
StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
2784            Object JavaDoc[] list = parts.toArray();
2785            int indent = 0;
2786            int pad = 0;
2787            index = 0;
2788            while (index < list.length) {
2789                part = (String JavaDoc) list[index];
2790                if (buf.length() == 0) {
2791                    // Just add first tag (should be XML header)
2792
buf.append(part);
2793                } else {
2794                    // All other parts need to start on a new line
2795
buf.append('\n');
2796
2797                    // If we're at an end tag then decrease indent
2798
if (part.startsWith("</")) {
2799                        indent--;
2800                    }
2801
2802                    // Add any indent
2803
for (pad = 0; pad < indent; pad++) {
2804                        buf.append(" ");
2805                    }
2806
2807                    // Add the tag or data
2808
buf.append(part);
2809
2810                    // If this is a start tag then increase indent
2811
if (part.startsWith("<") && !part.startsWith("</")
2812                            && !part.endsWith("/>")) {
2813                        indent++;
2814
2815                        // Check for special <tag>data</tag> case
2816
if ((index + 2) < list.length) {
2817                            part = (String JavaDoc) list[index + 2];
2818                            if (part.startsWith("</")) {
2819                                part = (String JavaDoc) list[index + 1];
2820                                if (!part.startsWith("<")) {
2821                                    buf.append(part);
2822                                    part = (String JavaDoc) list[index + 2];
2823                                    buf.append(part);
2824                                    index = index + 2;
2825                                    indent--;
2826                                }
2827                            }
2828                        }
2829                    }
2830                }
2831                index++;
2832            }
2833            formatted = new String JavaDoc(buf);
2834        }
2835    }
2836
2837    /**
2838     * Listener to handle button actions
2839     *
2840     * @param e
2841     */

2842    public void actionPerformed(ActionEvent JavaDoc e) {
2843        Object JavaDoc obj = e.getSource();
2844        if (obj == add_btn) {
2845            int selected[] = list1.getSelectedIndices();
2846            int len = selected.length - 1;
2847            for (int i = len; i >= 0; i--) {
2848                model2.addElement(model1.getElementAt(selected[i]));
2849                model1.remove(selected[i]);
2850            }
2851            if (model1.size() == 0) {
2852                add_btn.setEnabled(false);
2853            }
2854            if (model2.size() > 0) {
2855                del_btn.setEnabled(true);
2856            }
2857        } else if (obj == del_btn) {
2858            int selected[] = list2.getSelectedIndices();
2859            int len = selected.length - 1;
2860            for (int i = len; i >= 0; i--) {
2861                model1.addElement(model2.getElementAt(selected[i]));
2862                model2.remove(selected[i]);
2863            }
2864            if (model2.size() == 0) {
2865                del_btn.setEnabled(false);
2866            }
2867            if (model1.size() > 0) {
2868                add_btn.setEnabled(true);
2869            }
2870        } else if (obj == login_btn) {
2871            if (doLogin()) {
2872                delPage();
2873                addPage(new SOAPMonitorPage(axisHost));
2874                start();
2875            } else {
2876                add_btn.setEnabled(false);
2877                del_btn.setEnabled(false);
2878            }
2879        } else if (obj == save_btn) {
2880            String JavaDoc service = null;
2881            Node JavaDoc node = null;
2882            Node JavaDoc impNode = null;
2883            Document JavaDoc wsdd = null;
2884            JOptionPane JavaDoc pane = null;
2885            JDialog JavaDoc dlg = null;
2886            String JavaDoc msg = null;
2887            final String JavaDoc title = "Deployment status";
2888            final String JavaDoc deploy = "<deployment name=\"SOAPMonitor\""
2889              + " xmlns=\"http://xml.apache.org/axis/wsdd/\""
2890              + " xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\">\n"
2891              + " <handler name=\"soapmonitor\""
2892              + " type=\"java:org.apache.axis.handlers.SOAPMonitorHandler\" />\n"
2893              + " </deployment>";
2894
2895            // Create a new wsdd document
2896
try {
2897                wsdd = XMLUtils.newDocument(
2898                        new ByteArrayInputStream JavaDoc(deploy.getBytes()));
2899            } catch (Exception JavaDoc ex) {
2900                ex.printStackTrace();
2901            }
2902            Collection JavaDoc col = serviceMap.keySet();
2903            Iterator JavaDoc ite = col.iterator();
2904
2905            // Add all of service nodes to the new wsdd
2906
while (ite.hasNext()) {
2907                service = (String JavaDoc) ite.next();
2908                node = (Node JavaDoc) serviceMap.get(service);
2909                if (model2.contains(service)) {
2910                    if (isMonitored(node)) { // It's already been monitored
2911
impNode = wsdd.importNode(node, true);
2912                    } else { // It's to be monitored
2913
impNode = wsdd.importNode(addMonitor(node), true);
2914                    }
2915                } else {
2916                    if (isMonitored(node)) { // It's not to be monitored
2917
impNode = wsdd.importNode(delMonitor(node), true);
2918                    } else { // It's not already been monitored
2919
impNode = wsdd.importNode(node, true);
2920                    }
2921                }
2922                if (service.equals("AdminService")) {
2923                    // Add "SimpleAuthenticationHandler" and "allowedRoles" parameter
2924
// with "admin" as a user account
2925
impNode = wsdd.importNode(addAuthenticate(impNode), true);
2926                }
2927                wsdd.getDocumentElement().appendChild(impNode);
2928            }
2929
2930            // Show the result of deployment
2931
pane = new JOptionPane JavaDoc();
2932            if (doDeploy(wsdd)) {
2933                msg = "The deploy was successful.";
2934                pane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
2935            } else {
2936                msg = "The deploy was NOT successful.";
2937                pane.setMessageType(JOptionPane.WARNING_MESSAGE);
2938            }
2939            pane.setOptions(new String JavaDoc[]{"OK"});
2940            pane.setMessage(msg);
2941            dlg = pane.createDialog(null, title);
2942            dlg.setVisible(true);
2943        }
2944    }
2945
2946    /**
2947     * ChangeListener to handle tab actions
2948     *
2949     * @param e
2950     */

2951    public void stateChanged( javax.swing.event.ChangeEvent JavaDoc e ){
2952        JTabbedPane JavaDoc tab = (JTabbedPane JavaDoc)e.getSource();
2953        int item = tab.getSelectedIndex();
2954        if (item==1) { // "Monitoring" tab is selected.
2955
start();
2956        } else { // "Setting" tab is selected.
2957
stop();
2958        }
2959    }
2960}
2961
Popular Tags