📄 soapmonitor.java
字号:
*/ private Long id; /** * Field time */ private String time; /** * Field target */ private String target; /** * Field soap_request */ private String soap_request; /** * Field soap_response */ private String soap_response; /** * Constructor * * @param id * @param target * @param soap_request */ public SOAPMonitorData(Long id, String target, String soap_request) { this.id = id; // A null id is used to signal that the "most recent" entry // is being created. if (id == null) { this.time = "Most Recent"; this.target = "---"; this.soap_request = null; this.soap_response = null; } else { this.time = DateFormat.getTimeInstance().format(new Date()); this.target = target; this.soap_request = soap_request; this.soap_response = null; } } /** * Get the id for the SOAP message * * @return */ public Long getId() { return id; } /** * Get the time the SOAP request was received by the application * * @return */ public String getTime() { return time; } /** * Get the SOAP request target service name * * @return */ public String getTargetService() { return target; } /** * Get the status of the request * * @return */ public String getStatus() { String status = "---"; if (id != null) { status = "Complete"; if (soap_response == null) { status = "Active"; } } return status; } /** * Get the request SOAP contents * * @return */ public String getSOAPRequest() { return soap_request; } /** * Set the resposne SOAP contents * * @param response */ public void setSOAPResponse(String response) { soap_response = response; } /** * Get the response SOAP contents * * @return */ public String getSOAPResponse() { return soap_response; } } /** * This table model is used to manage the table displayed * at the top of the page to show all the SOAP messages * we have received and to control which message details are * to be displayed on the bottom of the page. */ class SOAPMonitorTableModel extends AbstractTableModel { /** * Column titles */ private final String[] column_names = {"Time", "Target Service", "Status"}; /** * Private data */ private Vector data; /** * Field filter_include */ private Vector filter_include; /** * Field filter_exclude */ private Vector filter_exclude; /** * Field filter_active */ private boolean filter_active; /** * Field filter_complete */ private boolean filter_complete; /** * Field filter_data */ private Vector filter_data; /** * Constructor */ public SOAPMonitorTableModel() { data = new Vector(); // Add "most recent" entry to top of table SOAPMonitorData soap = new SOAPMonitorData(null, null, null); data.addElement(soap); filter_include = null; filter_exclude = null; filter_active = false; filter_complete = false; filter_data = null; // By default, exclude NotificationService and // EventViewerService messages filter_exclude = new Vector(); filter_exclude.addElement("NotificationService"); filter_exclude.addElement("EventViewerService"); filter_data = new Vector(); filter_data.addElement(soap); } /** * Get column count (part of table model interface) * * @return */ public int getColumnCount() { return column_names.length; } /** * Get row count (part of table model interface) * * @return */ public int getRowCount() { int count = data.size(); if (filter_data != null) { count = filter_data.size(); } return count; } /** * Get column name (part of table model interface) * * @param col * @return */ public String getColumnName(int col) { return column_names[col]; } /** * Get value at (part of table model interface) * * @param row * @param col * @return */ public Object getValueAt(int row, int col) { SOAPMonitorData soap; String value = null; soap = (SOAPMonitorData) data.elementAt(row); if (filter_data != null) { soap = (SOAPMonitorData) filter_data.elementAt(row); } switch (col) { case 0: value = soap.getTime(); break; case 1: value = soap.getTargetService(); break; case 2: value = soap.getStatus(); break; } return value; } /** * Check if soap data matches filter * * @param soap * @return */ public boolean filterMatch(SOAPMonitorData soap) { boolean match = true; if (filter_include != null) { // Check for service match Enumeration e = filter_include.elements(); match = false; while (e.hasMoreElements() && !match) { String service = (String) e.nextElement(); if (service.equals(soap.getTargetService())) { match = true; } } } if (filter_exclude != null) { // Check for service match Enumeration e = filter_exclude.elements(); while (e.hasMoreElements() && match) { String service = (String) e.nextElement(); if (service.equals(soap.getTargetService())) { match = false; } } } if (filter_active) { // Check for active status match if (soap.getSOAPResponse() != null) { match = false; } } if (filter_complete) { // Check for complete status match if (soap.getSOAPResponse() == null) { match = false; } } // The "most recent" is always a match if (soap.getId() == null) { match = true; } return match; } /** * Add data to the table as a new row * * @param soap */ public void addData(SOAPMonitorData soap) { int row = data.size(); data.addElement(soap); if (filter_data != null) { if (filterMatch(soap)) { row = filter_data.size(); filter_data.addElement(soap); fireTableRowsInserted(row, row); } } else { fireTableRowsInserted(row, row); } } /** * Find the data for a given id * * @param id * @return */ public SOAPMonitorData findData(Long id) { SOAPMonitorData soap = null; for (int row = data.size(); (row > 0) && (soap == null); row--) { soap = (SOAPMonitorData) data.elementAt(row - 1); if (soap.getId().longValue() != id.longValue()) { soap = null; } } return soap; } /** * Find the row in the table for a given message id * * @param soap * @return */ public int findRow(SOAPMonitorData soap) { int row = -1; if (filter_data != null) { row = filter_data.indexOf(soap); } else { row = data.indexOf(soap); } return row; } /** * Remove all messages from the table (but leave "most recent") */ public void clearAll() { int last_row = data.size() - 1; if (last_row > 0) { data.removeAllElements(); SOAPMonitorData soap = new SOAPMonitorData(null, null, null); data.addElement(soap); if (filter_data != null) { filter_data.removeAllElements(); filter_data.addElement(soap); } fireTableDataChanged(); } } /** * Remove a message from the table * * @param row */ public void removeRow(int row) { SOAPMonitorData soap = null; if (filter_data == null) { soap = (SOAPMonitorData) data.elementAt(row); data.remove(soap); } else { soap = (SOAPMonitorData) filter_data.elementAt(row); filter_data.remove(soap); data.remove(soap); } fireTableRowsDeleted(row, row); } /** * Set a new filter * * @param filter */ public void setFilter(SOAPMonitorFilter filter) { // Save new filter criteria filter_include = filter.getFilterIncludeList(); filter_exclude = filter.getFilterExcludeList(); filter_active = filter.getFilterActive(); filter_complete = filter.getFilterComplete(); applyFilter(); } /** * Refilter the list of messages */ public void applyFilter() { // Re-filter using new criteria filter_data = null; if ((filter_include != null) || (filter_exclude != null) || filter_active || filter_complete) { filter_data = new Vector(); Enumeration e = data.elements(); SOAPMonitorData soap; while (e.hasMoreElements()) { soap = (SOAPMonitorData) e.nextElement(); if (filterMatch(soap)) { filter_data.addElement(soap); } } } fireTableDataChanged(); } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -