1 16 17 import java.awt.*; 18 import java.awt.event.*; 19 import java.io.*; 20 import java.net.*; 21 import java.text.*; 22 import java.util.*; 23 import javax.swing.*; 24 import javax.swing.border.*; 25 import javax.swing.event.*; 26 import javax.swing.table.*; 27 28 import org.apache.axis.monitor.SOAPMonitorConstants; 29 30 38 public class SOAPMonitorApplet extends JApplet { 39 40 43 private JPanel main_panel = null; 44 private JTabbedPane tabbed_pane = null; 45 private int port = 0; 46 private Vector pages = null; 47 48 51 public SOAPMonitorApplet() { 52 } 53 54 57 public void init() { 58 String port_str = getParameter("port"); 60 if (port_str != null) { 61 port = Integer.parseInt(port_str); 62 } 63 try { 65 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 66 } catch (Exception e){ 67 } 68 main_panel = new JPanel(); 70 main_panel.setBackground(Color.white); 71 main_panel.setLayout(new BorderLayout()); 72 setContentPane(main_panel); 73 tabbed_pane = new JTabbedPane(JTabbedPane.TOP); 75 main_panel.add(tabbed_pane,BorderLayout.CENTER); 76 pages = new Vector(); 78 addPage(new SOAPMonitorPage(getCodeBase().getHost())); 79 } 80 81 84 private void addPage(SOAPMonitorPage pg) { 85 tabbed_pane.addTab(" "+pg.getHost()+" ", pg); 86 pages.addElement(pg); 87 } 88 89 92 public void start() { 93 Enumeration e = pages.elements(); 95 while (e.hasMoreElements()) { 96 SOAPMonitorPage pg = (SOAPMonitorPage) e.nextElement(); 97 if (pg != null) { 98 pg.start(); 99 } 100 } 101 } 102 103 106 public void stop() { 107 Enumeration e = pages.elements(); 109 while (e.hasMoreElements()) { 110 SOAPMonitorPage pg = (SOAPMonitorPage) e.nextElement(); 111 if (pg != null) { 112 pg.stop(); 113 } 114 } 115 } 116 117 120 public void destroy() { 121 tabbed_pane = null; 122 main_panel = null; 123 } 124 125 129 class SOAPMonitorPage extends JPanel 130 implements Runnable , 131 ListSelectionListener, 132 ActionListener { 133 134 137 private final String STATUS_ACTIVE = "The SOAP Monitor is started."; 138 private final String STATUS_STOPPED = "The SOAP Monitor is stopped."; 139 private final String STATUS_CLOSED = "The server communication has been terminated."; 140 private final String STATUS_NOCONNECT = "The SOAP Monitor is unable to communcate with the server."; 141 142 145 private String host = null; 146 private Socket socket = null; 147 private ObjectInputStream in = null; 148 private ObjectOutputStream out = null; 149 private SOAPMonitorTableModel model = null; 150 private JTable table = null; 151 private JScrollPane scroll = null; 152 private JPanel list_panel = null; 153 private JPanel list_buttons = null; 154 private JButton remove_button = null; 155 private JButton remove_all_button = null; 156 private JButton filter_button = null; 157 private JPanel details_panel = null; 158 private JPanel details_header = null; 159 private JSplitPane details_soap = null; 160 private JPanel details_buttons = null; 161 private JLabel details_time = null; 162 private JLabel details_target = null; 163 private JLabel details_status = null; 164 private JLabel details_time_value = null; 165 private JLabel details_target_value = null; 166 private JLabel details_status_value = null; 167 private EmptyBorder empty_border = null; 168 private EtchedBorder etched_border = null; 169 private JPanel request_panel = null; 170 private JPanel response_panel = null; 171 private JLabel request_label = null; 172 private JLabel response_label = null; 173 private SOAPMonitorTextArea request_text = null; 174 private SOAPMonitorTextArea response_text = null; 175 private JScrollPane request_scroll = null; 176 private JScrollPane response_scroll = null; 177 private JButton layout_button = null; 178 private JSplitPane split = null; 179 private JPanel status_area = null; 180 private JPanel status_buttons = null; 181 private JButton start_button = null; 182 private JButton stop_button = null; 183 private JLabel status_text = null; 184 private JPanel status_text_panel = null; 185 private SOAPMonitorFilter filter = null; 186 private GridBagLayout details_header_layout = null; 187 private GridBagConstraints details_header_constraints = null; 188 private JCheckBox reflow_xml = null; 189 190 193 public SOAPMonitorPage(String host_name) { 194 host = host_name; 195 filter = new SOAPMonitorFilter(); 197 etched_border = new EtchedBorder(); 199 model = new SOAPMonitorTableModel(); 201 table = new JTable(model); 202 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 203 table.setRowSelectionInterval(0,0); 204 table.setPreferredScrollableViewportSize(new Dimension(600, 96)); 205 table.getSelectionModel().addListSelectionListener(this); 206 scroll = new JScrollPane(table); 207 remove_button = new JButton("Remove"); 208 remove_button.addActionListener(this); 209 remove_button.setEnabled(false); 210 remove_all_button = new JButton("Remove All"); 211 remove_all_button.addActionListener(this); 212 filter_button = new JButton("Filter ..."); 213 filter_button.addActionListener(this); 214 list_buttons = new JPanel(); 215 list_buttons.setLayout(new FlowLayout()); 216 list_buttons.add(remove_button); 217 list_buttons.add(remove_all_button); 218 list_buttons.add(filter_button); 219 list_panel = new JPanel(); 220 list_panel.setLayout(new BorderLayout()); 221 list_panel.add(scroll,BorderLayout.CENTER); 222 list_panel.add(list_buttons, BorderLayout.SOUTH); 223 list_panel.setBorder(empty_border); 224 details_time = new JLabel("Time: ", SwingConstants.RIGHT); 226 details_target = new JLabel("Target Service: ", SwingConstants.RIGHT); 227 details_status = new JLabel("Status: ", SwingConstants.RIGHT); 228 details_time_value = new JLabel(); 229 details_target_value = new JLabel(); 230 details_status_value = new JLabel(); 231 Dimension preferred_size = details_time.getPreferredSize(); 232 preferred_size.width = 1; 233 details_time.setPreferredSize(preferred_size); 234 details_target.setPreferredSize(preferred_size); 235 details_status.setPreferredSize(preferred_size); 236 details_time_value.setPreferredSize(preferred_size); 237 details_target_value.setPreferredSize(preferred_size); 238 details_status_value.setPreferredSize(preferred_size); 239 details_header = new JPanel(); 240 details_header_layout = new GridBagLayout(); 241 details_header.setLayout(details_header_layout); 242 details_header_constraints = new GridBagConstraints(); 243 details_header_constraints.fill=GridBagConstraints.BOTH; 244 details_header_constraints.weightx=0.5; 245 details_header_layout.setConstraints(details_time,details_header_constraints); 246 details_header.add(details_time); 247 details_header_layout.setConstraints(details_time_value,details_header_constraints); 248 details_header.add(details_time_value); 249 details_header_layout.setConstraints(details_target,details_header_constraints); 250 details_header.add(details_target); 251 details_header_constraints.weightx=1.0; 252 details_header_layout.setConstraints(details_target_value,details_header_constraints); 253 details_header.add(details_target_value); 254 details_header_constraints.weightx=.5; 255 details_header_layout.setConstraints(details_status,details_header_constraints); 256 details_header.add(details_status); 257 details_header_layout.setConstraints(details_status_value,details_header_constraints); 258 details_header.add(details_status_value); 259 details_header.setBorder(etched_border); 260 request_label = new JLabel("SOAP Request", SwingConstants.CENTER); 261 request_text = new SOAPMonitorTextArea(); 262 request_text.setEditable(false); 263 request_scroll = new JScrollPane(request_text); 264 request_panel = new JPanel(); 265 request_panel.setLayout(new BorderLayout()); 266 request_panel.add(request_label, BorderLayout.NORTH); 267 request_panel.add(request_scroll, BorderLayout.CENTER); 268 response_label = new JLabel("SOAP Response", SwingConstants.CENTER); 269 response_text = new SOAPMonitorTextArea(); 270 response_text.setEditable(false); 271 response_scroll = new JScrollPane(response_text); 272 response_panel = new JPanel(); 273 response_panel.setLayout(new BorderLayout()); 274 response_panel.add(response_label, BorderLayout.NORTH); 275 response_panel.add(response_scroll, BorderLayout.CENTER); 276 details_soap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); 277 details_soap.setTopComponent(request_panel); 278 details_soap.setRightComponent(response_panel); 279 details_soap.setResizeWeight(.5); 280 details_panel = new JPanel(); 281 layout_button = new JButton("Switch Layout"); 282 layout_button.addActionListener(this); 283 reflow_xml = new JCheckBox("Reflow XML text"); 284 reflow_xml.addActionListener(this); 285 details_buttons = new JPanel(); 286 details_buttons.setLayout(new FlowLayout()); 287 details_buttons.add(reflow_xml); 288 details_buttons.add(layout_button); 289 details_panel.setLayout(new BorderLayout()); 290 details_panel.add(details_header,BorderLayout.NORTH); 291 details_panel.add(details_soap,BorderLayout.CENTER); 292 details_panel.add(details_buttons,BorderLayout.SOUTH); 293 details_panel.setBorder(empty_border); 294 split = new JSplitPane(JSplitPane.VERTICAL_SPLIT); 296 split.setTopComponent(list_panel); 297 split.setRightComponent(details_panel); 298 start_button = new JButton("Start"); 300 start_button.addActionListener(this); 301 stop_button = new JButton("Stop"); 302 stop_button.addActionListener(this); 303 status_buttons = new JPanel(); 304 status_buttons.setLayout(new FlowLayout()); 305 status_buttons.add(start_button); 306 status_buttons.add(stop_button); 307 status_text = new JLabel(); 308 status_text.setBorder(new BevelBorder(BevelBorder.LOWERED)); 309 status_text_panel = new JPanel(); 310 status_text_panel.setLayout(new BorderLayout()); 311 status_text_panel.add(status_text, BorderLayout.CENTER); 312 status_text_panel.setBorder(empty_border); 313 status_area = new JPanel(); 314 status_area.setLayout(new BorderLayout()); 315 status_area.add(status_buttons, BorderLayout.WEST); 316 status_area.add(status_text_panel, BorderLayout.CENTER); 317 status_area.setBorder(etched_border); 318 setLayout(new BorderLayout()); 320 add(split, BorderLayout.CENTER); 321 add(status_area, BorderLayout.SOUTH); 322 } 323 324 327 public String getHost() { 328 return host; 329 } 330 331 334 public void setStatus(String txt) { 335 status_text.setForeground(Color.black); 336 status_text.setText(" "+txt); 337 } 338 339 342 public void setErrorStatus(String txt) { 343 status_text.setForeground(Color.red); 344 status_text.setText(" "+txt); 345 } 346 347 350 public void start() { 351 String codehost = getCodeBase().getHost(); 352 if (socket == null) { 353 try { 354 socket = new Socket(codehost, port); 356 out = new ObjectOutputStream(socket.getOutputStream()); 358 out.flush(); 359 in = new ObjectInputStream(socket.getInputStream()); 362 new Thread (this).start(); 363 } catch (Exception e) { 364 System.out.println("Exception! "+e.toString()); 368 e.printStackTrace(); 369 setErrorStatus(STATUS_NOCONNECT); 370 socket = null; 371 } 372 } else { 373 } 375 if (socket != null) { 376 start_button.setEnabled(false); 378 stop_button.setEnabled(true); 379 setStatus(STATUS_ACTIVE); 380 } 381 } 382 383 386 public void stop() { 387 if (socket != null) { 388 if (out != null) { 390 try { 391 out.close(); 392 } catch (IOException ioe) { 393 } 394 out = null; 395 } 396 if (in != null) { 397 try { 398 in.close(); 399 } catch (IOException ioe) { 400 } 401 in = null; 402 } 403 if (socket != null) { 404 try { 405 socket.close(); 406 } catch (IOException ioe) { 407 } 408 socket = null; 409 } 410 } else { 411 } 413 start_button.setEnabled(true); 415 stop_button.setEnabled(false); 416 setStatus(STATUS_STOPPED); 417 } 418 419 423 public void run() { 424 Long id; 425 Integer message_type; 426 String target; 427 String soap; 428 SOAPMonitorData data; 429 int selected; 430 int row; 431 boolean update_needed; 432 while (socket != null) { 433 try { 434 message_type = (Integer ) in.readObject(); 436 switch (message_type.intValue()) { 438 case SOAPMonitorConstants.SOAP_MONITOR_REQUEST: 439 id = (Long ) in.readObject(); 441 target = (String ) in.readObject(); 442 soap = (String ) in.readObject(); 443 data = new SOAPMonitorData(id,target,soap); 445 model.addData(data); 446 selected = table.getSelectedRow(); 449 if ((selected == 0) && model.filterMatch(data)) { 450 valueChanged(null); 451 } 452 break; 453 case SOAPMonitorConstants.SOAP_MONITOR_RESPONSE: 454 id = (Long ) in.readObject(); 456 soap = (String ) in.readObject(); 457 data = model.findData(id); 458 if (data != null) { 459 update_needed = false; 460 selected = table.getSelectedRow(); 462 if (selected == 0) { 465 update_needed = true; 466 } 467 row = model.findRow(data); 470 if ((row != -1) && (row == selected)) { 471 update_needed = true; 472 } 473 data.setSOAPResponse(soap); 475 model.updateData(data); 476 if (update_needed) { 478 valueChanged(null); 479 } 480 } 481 break; 482 } 483 484 } catch (Exception e) { 485 if (stop_button.isEnabled()) { 488 stop(); 489 setErrorStatus(STATUS_CLOSED); 490 } 491 } 492 } 493 } 494 495 498 public void valueChanged(ListSelectionEvent e) { 499 int row = table.getSelectedRow(); 500 if (row > 0) { 502 remove_button.setEnabled(true); 503 } else { 504 remove_button.setEnabled(false); 505 } 506 if (row == 0) { 508 row = model.getRowCount() - 1; 509 if (row == 0) { 510 row = -1; 511 } 512 } 513 if (row == -1) { 514 details_time_value.setText(""); 516 details_target_value.setText(""); 517 details_status_value.setText(""); 518 request_text.setText(""); 519 response_text.setText(""); 520 } else { 521 SOAPMonitorData soap = model.getData(row); 523 details_time_value.setText(soap.getTime()); 524 details_target_value.setText(soap.getTargetService()); 525 details_status_value.setText(soap.getStatus()); 526 if (soap.getSOAPRequest() == null) { 527 request_text.setText(""); 528 } else { 529 request_text.setText(soap.getSOAPRequest()); 530 request_text.setCaretPosition(0); 531 } 532 if (soap.getSOAPResponse() == null) { 533 response_text.setText(""); 534 } else { 535 response_text.setText(soap.getSOAPResponse()); 536 response_text.setCaretPosition(0); 537 } 538 } 539 } 540 541 544 public void actionPerformed(ActionEvent e) { 545 if (e.getSource() == remove_button) { 547 int row = table.getSelectedRow(); 548 model.removeRow(row); 549 table.clearSelection(); 550 table.repaint(); 551 valueChanged(null); 552 } 553 if (e.getSource() == remove_all_button) { 555 model.clearAll(); 556 table.setRowSelectionInterval(0,0); 557 table.repaint(); 558 valueChanged(null); 559 } 560 if (e.getSource() == filter_button) { 562 filter.showDialog(); 563 if (filter.okPressed()) { 564 model.setFilter(filter); 566 table.repaint(); 567 } 568 } 569 if (e.getSource() == start_button) { 571 start(); 572 } 573 if (e.getSource() == stop_button) { 575 stop(); 576 } 577 if (e.getSource() == layout_button) { 579 details_panel.remove(details_soap); 580 details_soap.removeAll(); 581 if (details_soap.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) { 582 details_soap = new JSplitPane(JSplitPane.VERTICAL_SPLIT); 583 } else { 584 details_soap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); 585 } 586 details_soap.setTopComponent(request_panel); 587 details_soap.setRightComponent(response_panel); 588 details_soap.setResizeWeight(.5); 589 details_panel.add(details_soap, BorderLayout.CENTER); 590 details_panel.validate(); 591 details_panel.repaint(); 592 } 593 if (e.getSource() == reflow_xml) { 595 request_text.setReflowXML(reflow_xml.isSelected()); 596 response_text.setReflowXML(reflow_xml.isSelected()); 597 } 598 } 599 } 600 601 604 class SOAPMonitorData { 605 606 609 private Long id; 610 private String time; 611 private String target; 612 private String soap_request; 613 private String soap_response; 614 615 618 public SOAPMonitorData(Long id, String target, String soap_request) { 619 this.id = id; 620 if (id == null) { 623 this.time = "Most Recent"; 624 this.target = "---"; 625 this.soap_request = null; 626 this.soap_response = null; 627 } else { 628 this.time = DateFormat.getTimeInstance().format(new Date()); 629 this.target = target; 630 this.soap_request = soap_request; 631 this.soap_response = null; 632 } 633 } 634 635 638 public Long getId() { 639 return id; 640 } 641 642 645 public String getTime() { 646 return time; 647 } 648 649 652 public String getTargetService() { 653 return target; 654 } 655 656 659 public String getStatus() { 660 String status = "---"; 661 if (id != null) { 662 status = "Complete"; 663 if (soap_response == null) { 664 status = "Active"; 665 } 666 } 667 return status; 668 } 669 670 673 public String getSOAPRequest() { 674 return soap_request; 675 } 676 677 680 public void setSOAPResponse(String response) { 681 soap_response = response; 682 } 683 684 687 public String getSOAPResponse() { 688 return soap_response; 689 } 690 } 691 692 698 class SOAPMonitorTableModel extends AbstractTableModel { 699 700 703 private final String [] column_names = { "Time", 704 "Target Service", 705 "Status" }; 706 709 private Vector data; 710 private Vector filter_include; 711 private Vector filter_exclude; 712 private boolean filter_active; 713 private boolean filter_complete; 714 private Vector filter_data; 715 716 719 public SOAPMonitorTableModel() { 720 data = new Vector(); 721 SOAPMonitorData soap = new SOAPMonitorData(null,null,null); 723 data.addElement(soap); 724 filter_include = null; 725 filter_exclude = null; 726 filter_active = false; 727 filter_complete = false; 728 filter_data = null; 729 filter_exclude = new Vector(); 732 filter_exclude.addElement("NotificationService"); 733 filter_exclude.addElement("EventViewerService"); 734 filter_data = new Vector(); 735 filter_data.addElement(soap); 736 } 737 738 741 public int getColumnCount() { 742 return column_names.length; 743 } 744 745 748 public int getRowCount() { 749 int count = data.size(); 750 if (filter_data != null) { 751 count = filter_data.size(); 752 } 753 return count; 754 } 755 756 759 public String getColumnName(int col) { 760 return column_names[col]; 761 } 762 763 766 public Object getValueAt(int row, int col) { 767 SOAPMonitorData soap; 768 String value = null; 769 soap = (SOAPMonitorData) data.elementAt(row); 770 if (filter_data != null) { 771 soap = (SOAPMonitorData) filter_data.elementAt(row); 772 } 773 switch (col) { 774 case 0: 775 value = soap.getTime(); 776 break; 777 case 1: 778 value = soap.getTargetService(); 779 break; 780 case 2: 781 value = soap.getStatus(); 782 break; 783 } 784 return value; 785 } 786 787 790 public boolean filterMatch(SOAPMonitorData soap) { 791 boolean match = true; 792 if (filter_include != null) { 793 Enumeration e = filter_include.elements(); 795 match = false; 796 while (e.hasMoreElements() && !match) { 797 String service = (String ) e.nextElement(); 798 if (service.equals(soap.getTargetService())) { 799 match = true; 800 } 801 } 802 } 803 if (filter_exclude != null) { 804 Enumeration e = filter_exclude.elements(); 806 while (e.hasMoreElements() && match) { 807 String service = (String ) e.nextElement(); 808 if (service.equals(soap.getTargetService())) { 809 match = false; 810 } 811 } 812 } 813 if (filter_active) { 814 if (soap.getSOAPResponse() != null) { 816 match = false; 817 } 818 } 819 if (filter_complete) { 820 if (soap.getSOAPResponse() == null) { 822 match = false; 823 } 824 } 825 if (soap.getId() == null) { 827 match = true; 828 } 829 return match; 830 } 831 832 835 public void addData(SOAPMonitorData soap) { 836 int row = data.size(); 837 data.addElement(soap); 838 if (filter_data != null) { 839 if (filterMatch(soap)) { 840 row = filter_data.size(); 841 filter_data.addElement(soap); 842 fireTableRowsInserted(row,row); 843 } 844 } else { 845 fireTableRowsInserted(row,row); 846 } 847 } 848 849 852 public SOAPMonitorData findData(Long id) { 853 SOAPMonitorData soap = null; 854 for (int row=data.size(); (row > 0) && (soap == null); row--) { 855 soap = (SOAPMonitorData) data.elementAt(row-1); 856 if (soap.getId().longValue() != id.longValue()) { 857 soap = null; 858 } 859 } 860 return soap; 861 } 862 863 866 public int findRow(SOAPMonitorData soap) { 867 int row = -1; 868 if (filter_data != null) { 869 row = filter_data.indexOf(soap); 870 } else { 871 row = data.indexOf(soap); 872 } 873 return row; 874 } 875 876 879 public void clearAll() { 880 int last_row = data.size() - 1; 881 if (last_row > 0) { 882 data.removeAllElements(); 883 SOAPMonitorData soap = new SOAPMonitorData(null,null,null); 884 data.addElement(soap); 885 if (filter_data != null) { 886 filter_data.removeAllElements(); 887 filter_data.addElement(soap); 888 } 889 fireTableDataChanged(); 890 } 891 } 892 893 896 public void removeRow(int row) { 897 SOAPMonitorData soap = null; 898 if (filter_data == null) { 899 soap = (SOAPMonitorData) data.elementAt(row); 900 data.remove(soap); 901 } else { 902 soap = (SOAPMonitorData) filter_data.elementAt(row); 903 filter_data.remove(soap); 904 data.remove(soap); 905 } 906 fireTableRowsDeleted(row,row); 907 } 908 909 912 public void setFilter(SOAPMonitorFilter filter) { 913 filter_include = filter.getFilterIncludeList(); 915 filter_exclude = filter.getFilterExcludeList(); 916 filter_active = filter.getFilterActive(); 917 filter_complete = filter.getFilterComplete(); 918 applyFilter(); 919 } 920 921 924 public void applyFilter() { 925 filter_data = null; 927 if ((filter_include != null) || 928 (filter_exclude != null) || 929 filter_active || filter_complete ) { 930 filter_data = new Vector(); 931 Enumeration e = data.elements(); 932 SOAPMonitorData soap; 933 while (e.hasMoreElements()) { 934 soap = (SOAPMonitorData) e.nextElement(); 935 if (filterMatch(soap)) { 936 filter_data.addElement(soap); 937 } 938 } 939 } 940 fireTableDataChanged(); 941 } 942 943 946 public SOAPMonitorData getData(int row) { 947 SOAPMonitorData soap = null; 948 if (filter_data == null) { 949 soap = (SOAPMonitorData) data.elementAt(row); 950 } else { 951 soap = (SOAPMonitorData) filter_data.elementAt(row); 952 } 953 return soap; 954 } 955 956 959 public void updateData (SOAPMonitorData soap) { 960 int row; 961 if (filter_data == null) { 962 row = data.indexOf(soap); 964 if (row != -1) { 965 fireTableRowsUpdated(row,row); 966 } 967 } else { 968 row = filter_data.indexOf(soap); 970 if (row == -1) { 971 if (filterMatch(soap)) { 974 int index = -1; 975 row = data.indexOf(soap) + 1; 976 while ((row < data.size()) && (index == -1)) { 977 index = filter_data.indexOf(data.elementAt(row)); 978 if (index != -1) { 979 filter_data.add(index,soap); 981 } 982 row++; 983 } 984 if (index == -1) { 985 index = filter_data.size(); 987 filter_data.addElement(soap); 988 } 989 fireTableRowsInserted(index,index); 990 } 991 } else { 992 if (filterMatch(soap)) { 995 fireTableRowsUpdated(row,row); 996 } else { 997 filter_data.remove(soap); 998 fireTableRowsDeleted(row,row); 999 } 1000 } 1001 } 1002 } 1003 1004 } 1005 1006 1009 class ServiceFilterPanel extends JPanel 1010 implements ActionListener, 1011 ListSelectionListener, 1012 DocumentListener { 1013 1014 private JCheckBox service_box = null; 1015 private Vector filter_list = null; 1016 private Vector service_data = null; 1017 private JList service_list = null; 1018 private JScrollPane service_scroll = null; 1019 private JButton remove_service_button = null; 1020 private JPanel remove_service_panel = null; 1021 private EmptyBorder indent_border = null; 1022 private EmptyBorder empty_border = null; 1023 private JPanel service_area = null; 1024 private JPanel add_service_area = null; 1025 private JTextField add_service_field = null; 1026 private JButton add_service_button = null; 1027 private JPanel add_service_panel = null; 1028 1029 1032 public ServiceFilterPanel(String text, Vector list) { 1033 empty_border = new EmptyBorder(5,5,0,5); 1034 indent_border = new EmptyBorder(5,25,5,5); 1035 service_box = new JCheckBox(text); 1036 service_box.addActionListener(this); 1037 service_data = new Vector(); 1038 if (list != null) { 1039 service_box.setSelected(true); 1040 service_data = (Vector) list.clone(); 1041 } 1042 service_list = new JList(service_data); 1043 service_list.setBorder(new EtchedBorder()); 1044 service_list.setVisibleRowCount(5); 1045 service_list.addListSelectionListener(this); 1046 service_list.setEnabled(service_box.isSelected()); 1047 service_scroll = new JScrollPane(service_list); 1048 service_scroll.setBorder(new EtchedBorder()); 1049 remove_service_button = new JButton("Remove"); 1050 remove_service_button.addActionListener(this); 1051 remove_service_button.setEnabled(false); 1052 remove_service_panel = new JPanel(); 1053 remove_service_panel.setLayout(new FlowLayout()); 1054 remove_service_panel.add(remove_service_button); 1055 service_area = new JPanel(); 1056 service_area.setLayout(new BorderLayout()); 1057 service_area.add(service_scroll, BorderLayout.CENTER); 1058 service_area.add(remove_service_panel, BorderLayout.EAST); 1059 service_area.setBorder(indent_border); 1060 add_service_field = new JTextField(); 1061 add_service_field.addActionListener(this); 1062 add_service_field.getDocument().addDocumentListener(this); 1063 add_service_field.setEnabled(service_box.isSelected()); 1064 add_service_button = new JButton("Add"); 1065 add_service_button.addActionListener(this); 1066 add_service_button.setEnabled(false); 1067 add_service_panel = new JPanel(); 1068 add_service_panel.setLayout(new BorderLayout()); 1069 JPanel dummy = new JPanel(); 1070 dummy.setBorder(empty_border); 1071 add_service_panel.add(dummy, BorderLayout.WEST); 1072 add_service_panel.add(add_service_button, BorderLayout.EAST); 1073 add_service_area = new JPanel(); 1074 add_service_area.setLayout(new BorderLayout()); 1075 add_service_area.add(add_service_field, BorderLayout.CENTER); 1076 add_service_area.add(add_service_panel, BorderLayout.EAST); 1077 add_service_area.setBorder(indent_border); 1078 setLayout(new BorderLayout()); 1079 add(service_box, BorderLayout.NORTH); 1080 add(service_area, BorderLayout.CENTER); 1081 add(add_service_area, BorderLayout.SOUTH); 1082 setBorder(empty_border); 1083 } 1084 1085 1088 public Vector getServiceList() { 1089 Vector list = null; 1090 if (service_box.isSelected()) { 1091 list = service_data; 1092 } 1093 return list; 1094 } 1095 1096 1099 public void actionPerformed(ActionEvent e) { 1100 if (e.getSource() == service_box) { 1102 service_list.setEnabled(service_box.isSelected()); 1103 service_list.clearSelection(); 1104 remove_service_button.setEnabled(false); 1105 add_service_field.setEnabled(service_box.isSelected()); 1106 add_service_field.setText(""); 1107 add_service_button.setEnabled(false); 1108 } 1109 if ((e.getSource() == add_service_button) || 1111 (e.getSource() == add_service_field)) { 1112 String text = add_service_field.getText(); 1113 if ((text != null) && (text.length() > 0)) { 1114 service_data.addElement(text); 1115 service_list.setListData(service_data); 1116 } 1117 add_service_field.setText(""); 1118 add_service_field.requestFocus(); 1119 } 1120 if (e.getSource() == remove_service_button) { 1122 Object [] sels = service_list.getSelectedValues(); 1123 for (int i=0; i<sels.length; i++) { 1124 service_data.removeElement(sels[i]); 1125 } 1126 service_list.setListData(service_data); 1127 service_list.clearSelection(); 1128 } 1129 } 1130 1131 1134 public void changedUpdate(DocumentEvent e) { 1135 String text = add_service_field.getText(); 1136 if ((text != null) && (text.length() > 0)) { 1137 add_service_button.setEnabled(true); 1138 } else { 1139 add_service_button.setEnabled(false); 1140 } 1141 } 1142 1143 1146 public void insertUpdate(DocumentEvent e) { 1147 changedUpdate(e); 1148 } 1149 1150 1153 public void removeUpdate(DocumentEvent e) { 1154 changedUpdate(e); 1155 } 1156 1157 1160 public void valueChanged(ListSelectionEvent e) { 1161 if (service_list.getSelectedIndex() == -1) { 1162 remove_service_button.setEnabled(false); 1163 } else { 1164 remove_service_button.setEnabled(true); 1165 } 1166 } 1167 } 1168 1169 1172 class SOAPMonitorFilter implements ActionListener { 1173 1174 1177 private JDialog dialog = null; 1178 private JPanel panel = null; 1179 private JPanel buttons = null; 1180 private JButton ok_button = null; 1181 private JButton cancel_button = null; 1182 private ServiceFilterPanel include_panel = null; 1183 private ServiceFilterPanel exclude_panel = null; 1184 private JPanel status_panel = null; 1185 private JCheckBox status_box = null; 1186 private EmptyBorder empty_border = null; 1187 private EmptyBorder indent_border = null; 1188 private JPanel status_options = null; 1189 private ButtonGroup status_group = null; 1190 private JRadioButton status_active = null; 1191 private JRadioButton status_complete = null; 1192 private Vector filter_include_list = null; 1193 private Vector filter_exclude_list = null; 1194 private boolean filter_active = false; 1195 private boolean filter_complete = false; 1196 private boolean ok_pressed = false; 1197 1198 1201 public SOAPMonitorFilter() { 1202 filter_exclude_list = new Vector(); 1205 filter_exclude_list.addElement("NotificationService"); 1206 filter_exclude_list.addElement("EventViewerService"); 1207 } 1208 1209 1212 public Vector getFilterIncludeList() { 1213 return filter_include_list; 1214 } 1215 1216 1219 public Vector getFilterExcludeList() { 1220 return filter_exclude_list; 1221 } 1222 1223 1226 public boolean getFilterActive() { 1227 return filter_active; 1228 } 1229 1230 1233 public boolean getFilterComplete() { 1234 return filter_complete; 1235 } 1236 1237 1240 public void showDialog() { 1241 empty_border = new EmptyBorder(5,5,0,5); 1242 indent_border = new EmptyBorder(5,25,5,5); 1243 include_panel = new ServiceFilterPanel("Include messages based on target service:", 1244 filter_include_list); 1245 exclude_panel = new ServiceFilterPanel("Exclude messages based on target service:", 1246 filter_exclude_list); 1247 status_box = new JCheckBox("Filter messages based on status:"); 1248 status_box.addActionListener(this); 1249 status_active = new JRadioButton("Active messages only"); 1250 status_active.setSelected(true); 1251 status_active.setEnabled(false); 1252 status_complete = new JRadioButton("Complete messages only"); 1253 status_complete.setEnabled(false); 1254 status_group = new ButtonGroup(); 1255 status_group.add(status_active); 1256 status_group.add(status_complete); 1257 if (filter_active || filter_complete) { 1258 status_box.setSelected(true); 1259 status_active.setEnabled(true); 1260 status_complete.setEnabled(true); 1261 if (filter_complete) { 1262 status_complete.setSelected(true); 1263 } 1264 } 1265 status_options = new JPanel(); 1266 status_options.setLayout(new BoxLayout(status_options, BoxLayout.Y_AXIS)); 1267 status_options.add(status_active); 1268 status_options.add(status_complete); 1269 status_options.setBorder(indent_border); 1270 status_panel = new JPanel(); 1271 status_panel.setLayout(new BorderLayout()); 1272 status_panel.add(status_box, BorderLayout.NORTH); 1273 status_panel.add(status_options, BorderLayout.CENTER); 1274 status_panel.setBorder(empty_border); 1275 ok_button = new JButton("Ok"); 1276 ok_button.addActionListener(this); 1277 cancel_button = new JButton("Cancel"); 1278 cancel_button.addActionListener(this); 1279 buttons = new JPanel(); 1280 buttons.setLayout(new FlowLayout()); 1281 buttons.add(ok_button); 1282 buttons.add(cancel_button); 1283 panel = new JPanel(); 1284 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); 1285 panel.add(include_panel); 1286 panel.add(exclude_panel); 1287 panel.add(status_panel); 1288 panel.add(buttons); 1289 dialog = new JDialog(); 1290 dialog.setTitle("SOAP Monitor Filter"); 1291 dialog.setContentPane(panel); 1292 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 1293 dialog.setModal(true); 1294 dialog.pack(); 1295 Dimension d = dialog.getToolkit().getScreenSize(); 1296 dialog.setLocation((d.width-dialog.getWidth())/2, 1297 (d.height-dialog.getHeight())/2); 1298 ok_pressed = false; 1299 dialog.show(); 1300 } 1301 1302 1305 public void actionPerformed(ActionEvent e) { 1306 if (e.getSource() == ok_button) { 1308 filter_include_list = include_panel.getServiceList(); 1309 filter_exclude_list = exclude_panel.getServiceList(); 1310 if (status_box.isSelected()) { 1311 filter_active = status_active.isSelected(); 1312 filter_complete = status_complete.isSelected(); 1313 } else { 1314 filter_active = false; 1315 filter_complete = false; 1316 } 1317 ok_pressed = true; 1318 dialog.dispose(); 1319 } 1320 if (e.getSource() == cancel_button) { 1322 dialog.dispose(); 1323 } 1324 if (e.getSource() == status_box) { 1326 status_active.setEnabled(status_box.isSelected()); 1327 status_complete.setEnabled(status_box.isSelected()); 1328 } 1329 } 1330 1331 1334 public boolean okPressed() { 1335 return ok_pressed; 1336 } 1337 } 1338 1339 1342 class SOAPMonitorTextArea extends JTextArea { 1343 1344 1347 private boolean format = false; 1348 private String original = ""; 1349 private String formatted = null; 1350 1351 1354 public SOAPMonitorTextArea() { 1355 } 1356 1357 1360 public void setText(String text) { 1361 original = text; 1362 formatted = null; 1363 if (format) { 1364 doFormat(); 1365 super.setText(formatted); 1366 } else { 1367 super.setText(original); 1368 } 1369 } 1370 1371 1374 public void setReflowXML(boolean reflow) { 1375 format = reflow; 1376 if (format) { 1377 if (formatted == null) { 1378 doFormat(); 1379 } 1380 super.setText(formatted); 1381 } else { 1382 super.setText(original); 1383 } 1384 } 1385 1386 1389 public void doFormat() { 1390 Vector parts = new Vector(); 1391 char[] chars = original.toCharArray(); 1392 int index = 0; 1393 int first = 0; 1394 String part = null; 1395 while (index < chars.length) { 1396 if (chars[index] == '<') { 1398 if (first < index) { 1400 part = new String (chars,first,index-first); 1401 part = part.trim(); 1402 if (part.length() > 0) { 1404 parts.addElement(part); 1405 } 1406 } 1407 first = index; 1409 } 1410 if (chars[index] == '>') { 1412 part = new String (chars,first,index-first+1); 1414 parts.addElement(part); 1415 first = index+1; 1416 } 1417 if ((chars[index] == '\n') || (chars[index] == '\r')) { 1419 if (first < index) { 1421 part = new String (chars,first,index-first); 1422 part = part.trim(); 1423 if (part.length() > 0) { 1425 parts.addElement(part); 1426 } 1427 } 1428 first = index+1; 1429 } 1430 index++; 1431 } 1432 StringBuffer buf = new StringBuffer (); 1434 Object [] list = parts.toArray(); 1435 int indent = 0; 1436 int pad = 0; 1437 index = 0; 1438 while (index < list.length) { 1439 part = (String ) list[index]; 1440 if (buf.length() == 0) { 1441 buf.append(part); 1443 } else { 1444 buf.append('\n'); 1446 if (part.startsWith("</")) { 1448 indent--; 1449 } 1450 for (pad = 0; pad < indent; pad++) { 1452 buf.append(" "); 1453 } 1454 buf.append(part); 1456 if (part.startsWith("<") && 1458 !part.startsWith("</") && 1459 !part.endsWith("/>")) { 1460 indent++; 1461 if ((index + 2) < list.length) { 1463 part = (String ) list[index+2]; 1464 if (part.startsWith("</")) { 1465 part = (String ) list[index+1]; 1466 if (!part.startsWith("<")) { 1467 buf.append(part); 1468 part = (String ) list[index+2]; 1469 buf.append(part); 1470 index = index + 2; 1471 indent--; 1472 } 1473 } 1474 } 1475 } 1476 } 1477 index++; 1478 } 1479 formatted = new String (buf); 1480 } 1481 } 1482} 1483 | Popular Tags |