/** * Returns a printable representation of this header. * * @param filter FormatProperties object for filtering this header. * @return Returns a string representation of this header. */ public String toString(FormatProperties filter) { // Check for Port filtering if (filter != null) { // If filter is enabled boolean print = false; String port = filter.getPort(); if (port == null) { print = true; // The filtering doesn't apply to this header } else if (port.equals(sourceport.toString()) || port.equals(destport.toString())) { print = true; } if (!print) { // Don't print the packet if (Trace.isTraceOn() && Trace.isTraceInformationOn()) { Trace.log(Trace.INFORMATION, CLASS + ".toString() " + "Not printing record"); } return ""; // Return empty record because it didn't pass the filter } } String portname = (String) Port.get(this.sourceport.toString()); String portname2 = (String) Port.get(this.destport.toString()); // Make sure we have enough data to parse a full header if (rawheader.getBitSize() < getHeaderLen()) { return (new Data(rawheader)).toString(); } if (portname == null) { portname = UNASSIGNED; } if (portname2 == null) { portname2 = UNASSIGNED; } String sourceport = this.sourceport.toString() + ", " + portname; String destport = this.destport.toString() + ", " + portname2; Object[] args = {sourceport, destport, length, checksum}; return Formatter.jsprintf( "\t " + UDPSTR + " . . . . : " + SRC + ": {0,18,L} " + DST + ": {1,18,L}\n" + "\t\t\t " + LEN + ": {2,5,L} " + CHKSUM + ": {3}\n", args) + printHexHeader() + printnext(filter) + (new Data(rawpayload)).toString(); }
/** * Removes a row from the table. * * @param rowIndex The row index. Indices start at 0. */ public void removeRow(int rowIndex) { synchronized (this) { Trace.log(Trace.DIAGNOSTIC, "Removing row ", rowIndex); // array to hold new data String[][] newData = new String[data_.length - 1][NUM_COLUMNS_]; int[] newTypes = new int[types_.length - 1]; // copy table data to new table less row being removed if (rowIndex == 0) { // remove first row System.arraycopy(data_, 1, newData, 0, newData.length); System.arraycopy(types_, 1, newTypes, 0, newTypes.length); } else if (rowIndex == data_.length - 1) { // remove last row System.arraycopy(data_, 0, newData, 0, newData.length); System.arraycopy(types_, 0, newTypes, 0, newTypes.length); } else { // remove row in middle System.arraycopy(data_, 0, newData, 0, rowIndex); System.arraycopy(data_, rowIndex + 1, newData, rowIndex, newData.length - rowIndex); System.arraycopy(types_, 0, newTypes, 0, rowIndex); System.arraycopy(types_, rowIndex + 1, newTypes, rowIndex, newTypes.length - rowIndex); } data_ = newData; numRows_--; } // notify listeners that we've changed fireTableRowsDeleted(rowIndex, rowIndex); }
/** Starts the Output Thread to recieve debug info from the remotely running Java program. */ public void run() { Thread myThread = Thread.currentThread(); while (outThread_ == myThread) { String s = jaCall_.getStandardOutString(); if (s != null) Trace.log(Trace.INFORMATION, s); try { Thread.sleep(1000); } catch (InterruptedException e) { // the VM doesn't want us to sleep anymore, // so get back to work } } }
/** Loads the table based on the state of the system. */ public void load() { synchronized (this) { // Set back fields in case there is an error. data_ = new String[0][0]; types_ = new int[0]; numRows_ = 0; } // notify listeners that we've changed number of rows. TableModelEvent event = new TableModelEvent(this, -1); fireTableChanged(event); Trace.log(Trace.DIAGNOSTIC, "Starting load, changed number of rows to:", numRows_); if (tables_ == null || tables_.length == 0 || connection_ == null) { // If no tables, the panel will be disabled, don't throw // error, just leave table empty. return; } synchronized (this) { workingListeners_.fireStartWorking(); // Number of rows we create our table with and number of // rows we bump our capacity by each time we run out of room. int ROW_INCREMENT = 50; ResultSet resultSet = null; try { // Get database meta data DatabaseMetaData metaData = connection_.getMetaData(); // Create new array to hold table values. data_ = new String[ROW_INCREMENT][NUM_COLUMNS_]; types_ = new int[ROW_INCREMENT]; // Loop through each database file. String library, table, tprefix; int sepIndex; int curRow; for (int i = 0; i < tables_.length; ++i) { // Get meta data. sepIndex = tables_[i].indexOf("."); if (sepIndex == -1) { // Incorrect table specification, send error // and continue to next table. // Create generic exception to hold error message Exception e = new Exception(ResourceLoader.getText("EXC_TABLE_SPEC_NOT_VALID")); errorListeners_.fireError(e); } else { library = tables_[i].substring(0, sepIndex); table = tables_[i].substring(sepIndex + 1); if (tables_.length > 1) tprefix = table + "."; // need to qualify field names else tprefix = ""; // only 1 table, can just use field names resultSet = metaData.getColumns(null, library, table, null); // Loop through fields for this database file. while (resultSet.next()) { curRow = numRows_; // current row in table // make sure we have room in table for this row. if (curRow >= data_.length) // @D1C { String[][] newData = new String[data_.length + ROW_INCREMENT][NUM_COLUMNS_]; System.arraycopy(data_, 0, newData, 0, data_.length); data_ = newData; int[] newTypes = new int[types_.length + ROW_INCREMENT]; System.arraycopy(types_, 0, newTypes, 0, types_.length); types_ = newTypes; } // Store SQL type for use by getSQLType, // although this is not externalized in the table. types_[curRow] = resultSet.getInt(5); // Add field info to table data_[curRow][FIELD_NAME_] = tprefix + resultSet.getString(4).trim(); data_[curRow][FIELD_TYPE_] = resultSet.getString(6); // The following code should not be necessary when using // most drivers, but makes the length values correct // when using the i5/OS JDBC driver. // These values came from the ODBC description of precision // (in 2.0 ref, Appendix D page 624). switch (types_[curRow]) { case Types.SMALLINT: data_[curRow][FIELD_LENGTH_] = "5"; break; case Types.INTEGER: data_[curRow][FIELD_LENGTH_] = "10"; break; case Types.TIME: data_[curRow][FIELD_LENGTH_] = "8"; break; case Types.TIMESTAMP: // We always give length = 23, even though // we should give 19 if there is no decimals. // In order to not mess up 'correct' values, // only change it if we know the value is bad. if (resultSet.getInt(7) == 10) data_[curRow][FIELD_LENGTH_] = "23"; break; case Types.DATE: data_[curRow][FIELD_LENGTH_] = "10"; break; case Types.DOUBLE: if (resultSet.getInt(7) == 4) // single precision (type REAL) data_[curRow][FIELD_LENGTH_] = "7"; else // double precison (type FLOAT) data_[curRow][FIELD_LENGTH_] = "15"; break; default: // Other types are correct. data_[curRow][FIELD_LENGTH_] = resultSet.getString(7); } data_[curRow][FIELD_DECIMALS_] = resultSet.getString(9); data_[curRow][FIELD_NULLS_] = resultSet.getString(18); data_[curRow][FIELD_DESC_] = resultSet.getString(12); numRows_++; } } } } catch (SQLException e) { // In case of error, set fields to init state data_ = new String[0][0]; types_ = new int[0]; numRows_ = 0; errorListeners_.fireError(e); error_ = true; } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { errorListeners_.fireError(e); } } } } // end of synchronized block // notify listeners that we've changed event = new TableModelEvent(this, -1); fireTableChanged(event); Trace.log(Trace.DIAGNOSTIC, "Did load, changed number of rows to:", numRows_); workingListeners_.fireStopWorking(); }
/** * Returns the HTML tag that represents the resource link with the specified <i>text</i> and * <i>properties</i>. The original ServletHyperlink object <i>text</i> and <i>properties</i> are * not changed/updated. * * @param text The text. * @param properties The Properties. * @return The HTML tag. */ public String getTag(String text, Properties properties) { // Verify that the link has been set. if (getLink() == null) { Trace.log(Trace.ERROR, "Attempting to get tag before setting the link."); throw new ExtendedIllegalStateException( "link", ExtendedIllegalStateException.PROPERTY_NOT_SET); } // Validate the text parameter. if (text == null) throw new NullPointerException("text"); // create the tag. StringBuffer link = new StringBuffer(getLink()); // path info for servlet ex.- http://myServer/myPathInfo if (pathInfo_ != null) { // if the link ends with a "/", the path does not need a leading "/" if (getLink().endsWith("/")) { if (pathInfo_.startsWith("/")) { pathInfo_ = pathInfo_.substring(1); } else { // pathInfo_ = pathInfo_; } } else // link does not end with a "/", so the path needs to start with "/" { if (pathInfo_.startsWith("/")) { // pathInfo_ = pathInfo_; } else { pathInfo_ = "/" + pathInfo_; } } // place holder for real implementation... link.append(URLEncoder.encode(pathInfo_, false)); } if (properties != null) { String name; String parmStart = "?"; Enumeration propertyList = properties.propertyNames(); while (propertyList.hasMoreElements()) { name = (String) propertyList.nextElement(); link.append(parmStart); link.append(URLEncoder.encode(name)); link.append("="); link.append(URLEncoder.encode(properties.getProperty(name))); parmStart = "&"; } } StringBuffer url = new StringBuffer(); if (response_ != null) url.append(response_.encodeURL(link.toString())); else url.append(link.toString()); // create the tag. StringBuffer buffer = new StringBuffer(); buffer.append("<a href=\""); buffer.append(url.toString()); String location = getLocation(); // $A3A if (location != null) // $A3A { buffer.append("#"); // $A3A buffer.append(location); // $A3A } buffer.append("\""); String name = getName(); if (name != null) { buffer.append(" name=\""); buffer.append(name); buffer.append("\""); } String title = getTitle(); if (title != null) { buffer.append(" title=\""); buffer.append(title); buffer.append("\""); } String target = getTarget(); if (target != null) { buffer.append(" target=\""); buffer.append(target); buffer.append("\""); } buffer.append(getLanguageTag()); buffer.append(getDirectionTag()); buffer.append(getAttributeString()); // @Z1A buffer.append(">"); buffer.append(text); buffer.append("</a>"); return buffer.toString(); }