public void testMoreElementHashtableKeyEnumerator() { java.util.Hashtable <String, String> nameWert = new java.util.Hashtable <String, String>(); nameWert.put("1", "one"); nameWert.put("2", "one"); java.util.Enumeration <String> names = nameWert.keys(); Assert.True(names.hasMoreElements()); names.nextElement(); Assert.True(names.hasMoreElements()); names.nextElement(); Assert.False(names.hasMoreElements()); }
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { lock (this){ if ((listener != null) && (propertyName != null)) { PropertyChangeSupport listeners = children.get(propertyName); if (listeners == null) { listeners = new PropertyChangeSupport(source); children.put(propertyName, listeners); } // RI compatibility if (listener is PropertyChangeListenerProxy) { PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy)listener; listeners .addPropertyChangeListener(new PropertyChangeListenerProxy( proxy.getPropertyName(), (PropertyChangeListener)proxy.getListener())); } else { listeners.addPropertyChangeListener(listener); } } } }
/* * Delete rows which match a where clause. */ private void DeleteStatement(String tableName, TinySQLWhere wc) //throws TinySQLException { TinySQLTable jtbl; java.util.Hashtable <Object, Object> tables; String columnName, columnString, whereStatus; java.util.Enumeration <Object> cols; /* * Create a table object and put it in the Hashtable. */ jtbl = getTable(tableName); tables = new java.util.Hashtable <Object, Object>(); tables.put(tableName, jtbl); /* * Process each row in the table ignoring deleted rows. */ jtbl.GoTop(); while (jtbl.NextRecord()) { if (!jtbl.isDeleted()) { cols = jtbl.column_info.keys(); whereStatus = "TRUE"; while (cols.hasMoreElements()) { columnName = jtbl.table + "->" + jtbl.tableAlias + "." + (String)cols.nextElement(); columnString = jtbl.GetCol(columnName); /* * Check the status of the where clause for each column value. */ if (wc != (TinySQLWhere)null) { whereStatus = wc.evaluate(columnName, columnString); } if (whereStatus.equals("FALSE")) { break; } } if (whereStatus.equals("TRUE")) { jtbl.DeleteRow(); } if (wc != (TinySQLWhere)null) { wc.clearValues(jtbl.table + "->" + jtbl.tableAlias); } } } jtbl.close(); }
public Font(String name, int style, int size) { this.name = (name != null) ? name : "Default"; //$NON-NLS-1$ this.size = (size >= 0) ? size : 0; this.style = (style & ~0x03) == 0 ? style : Font.PLAIN; this.pointSize = this.size; fRequestedAttributes = new java.util.Hashtable<java.text.AttributedCharacterIteratorNS.Attribute, Object>();//5); fRequestedAttributes.put(java.awt.font.TextAttribute.TRANSFORM, IDENTITY_TRANSFORM); this.transformed = false; fRequestedAttributes.put(java.awt.font.TextAttribute.FAMILY, this.name); fRequestedAttributes.put(java.awt.font.TextAttribute.SIZE, new java.lang.Float(this.size)); if ((this.style & Font.BOLD) != 0) { fRequestedAttributes.put(java.awt.font.TextAttribute.WEIGHT, java.awt.font.TextAttribute.WEIGHT_BOLD); } else { fRequestedAttributes.put(java.awt.font.TextAttribute.WEIGHT, java.awt.font.TextAttribute.WEIGHT_REGULAR); } if ((this.style & Font.ITALIC) != 0) { fRequestedAttributes.put(java.awt.font.TextAttribute.POSTURE, java.awt.font.TextAttribute.POSTURE_OBLIQUE); } else { fRequestedAttributes.put(java.awt.font.TextAttribute.POSTURE, java.awt.font.TextAttribute.POSTURE_REGULAR); } }
public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte charSet, bool isVertical) { if (family == null) { throw new ArgumentNullException("family"); } _gUnit = unit; _fontFamily = family; _charset = charSet; java.util.Hashtable attribs = new java.util.Hashtable(); attribs.put(TextAttribute.FAMILY, family.Name /*TODO: family doungrade possibility*/); //init defaults attribs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR); float newSize = emSize * Graphics.UnitConversion[(int)_gUnit]; attribs.put(TextAttribute.SIZE, new java.lang.Float(newSize)); DeriveStyle(attribs, style, false); _jFont = family.FamilyFont.deriveFont(attribs); }
public Font(String name, int style, int size) { this.name = (name != null) ? name : "Default"; //$NON-NLS-1$ this.size = (size >= 0) ? size : 0; this.style = (style & ~0x03) == 0 ? style : Font.PLAIN; this.pointSize = this.size; fRequestedAttributes = new java.util.Hashtable <java.text.AttributedCharacterIteratorNS.Attribute, Object>();//5); fRequestedAttributes.put(java.awt.font.TextAttribute.TRANSFORM, IDENTITY_TRANSFORM); this.transformed = false; fRequestedAttributes.put(java.awt.font.TextAttribute.FAMILY, this.name); fRequestedAttributes.put(java.awt.font.TextAttribute.SIZE, new java.lang.Float(this.size)); if ((this.style & Font.BOLD) != 0) { fRequestedAttributes.put(java.awt.font.TextAttribute.WEIGHT, java.awt.font.TextAttribute.WEIGHT_BOLD); } else { fRequestedAttributes.put(java.awt.font.TextAttribute.WEIGHT, java.awt.font.TextAttribute.WEIGHT_REGULAR); } if ((this.style & Font.ITALIC) != 0) { fRequestedAttributes.put(java.awt.font.TextAttribute.POSTURE, java.awt.font.TextAttribute.POSTURE_OBLIQUE); } else { fRequestedAttributes.put(java.awt.font.TextAttribute.POSTURE, java.awt.font.TextAttribute.POSTURE_REGULAR); } }
/* * Add an action java.util.Hashtable<Object,Object> to the list of actions */ public void addAction() //throws TinySQLException, CloneNotSupportedException { int i, columnCount; TsColumn orderColumn; java.util.Hashtable <Object, Object> newAction = new java.util.Hashtable <Object, Object>(); newAction.put("TYPE", statementType); if (statementType.equals("SELECT")) { newAction.put("TABLES", tables); if (whereClause != (TinySQLWhere)null) { newAction.put("WHERE", whereClause); } /* * Validate the column specifications and expand * if present */ validateColumns(); /* * If no ORDER BY clause was specified, default to the list of * SELECT columns. */ if (defaultOrderBy) { columnCount = columns.size(); for (i = 0; i < columnCount; i++) { orderColumn = (TsColumn)(columns.elementAt(i)); if (orderColumn.getContext("SELECT")) { orderColumn.addContext("ORDER"); } } } newAction.put("COLUMNS", columns); if (orderType != (String)null) { newAction.put("ORDER_TYPE", orderType); } if (distinct) { newAction.put("DISTINCT", "TRUE"); } } else if (statementType.equals("DROP_TABLE")) { newAction.put("TABLE", tableName); } else if (statementType.equals("CREATE_TABLE")) { newAction.put("TABLE", tableName); newAction.put("COLUMN_DEF", columnList); } else if (statementType.equals("ALTER_RENAME")) { newAction.put("TABLE", tableName); newAction.put("OLD_COLUMN", oldColumnName); newAction.put("NEW_COLUMN", newColumnName); } else if (statementType.equals("ALTER_ADD")) { newAction.put("TABLE", tableName); newAction.put("COLUMN_DEF", columnList); } else if (statementType.equals("ALTER_DROP")) { newAction.put("TABLE", tableName); newAction.put("COLUMNS", columnList); } else if (statementType.equals("DELETE")) { newAction.put("TABLE", tableName); if (whereClause != (TinySQLWhere)null) { newAction.put("WHERE", whereClause); } } else if (statementType.equals("INSERT") | statementType.equals("UPDATE")) { newAction.put("TABLE", tableName); if (columnList.size() != valueList.size()) { throwException(5); } newAction.put("COLUMNS", columnList); newAction.put("VALUES", valueList); if (whereClause != (TinySQLWhere)null) { newAction.put("WHERE", whereClause); } } actionList.addElement(newAction); }
public TinySQLParser(java.io.InputStream sqlInput, TinySQL inputEngine) //throws TinySQLException { java.io.StreamTokenizer st; FieldTokenizer ft; java.io.Reader r; String nextToken, upperField, nextField, keyWord = (String)null; java.lang.StringBuffer cmdBuffer, inputSQLBuffer; int lastIndex, keyIndex; r = new java.io.BufferedReader(new java.io.InputStreamReader(sqlInput)); dbEngine = inputEngine; actionList = new java.util.Vector <Object>(); columnList = new java.util.Vector <Object>(); columns = new java.util.Vector <Object>(); columnAliasList = new java.util.Vector <Object>(); contextList = new java.util.Vector <Object>(); valueList = new java.util.Vector <Object>(); tableName = (String)null; whereClause = (TinySQLWhere)null; /* * The tableList is a list of table names, in the optimal order * in which they should be scanned for the SELECT phrase. * The java.util.Hashtable<Object,Object> tables contains table objects keyed by table * alias and name. */ tableList = new java.util.Vector <Object>(); tables = new java.util.Hashtable <Object, Object>(); tables.put("TABLE_SELECT_ORDER", tableList); try { st = new java.io.StreamTokenizer(r); st.eolIsSignificant(false); st.wordChars('\'', '}'); st.wordChars('?', '?'); st.wordChars('"', '.'); st.ordinaryChars('0', '9'); st.wordChars('0', '9'); cmdBuffer = new java.lang.StringBuffer(); inputSQLBuffer = new java.lang.StringBuffer(); while (st.nextToken() != java.io.StreamTokenizer.TT_EOF) { if (st.ttype == java.io.StreamTokenizer.TT_WORD) { nextToken = st.sval.trim(); } else { continue; } if (inputSQLBuffer.length() > 0) { inputSQLBuffer.append(" "); } inputSQLBuffer.append(nextToken); } ft = new FieldTokenizer(inputSQLBuffer.toString(), ' ', false); while (ft.hasMoreFields()) { nextField = ft.nextField(); upperField = nextField.toUpperCase(); if (statementType == (String)null) { statementType = upperField; lastIndex = getKeywordIndex(statementType, statementType); if (lastIndex != 0) { throwException(9); } keyWord = statementType; } else { keyIndex = getKeywordIndex(statementType, upperField); if (keyIndex < 0) { if (cmdBuffer.length() > 0) { cmdBuffer.append(" "); } cmdBuffer.append(nextField); } else { setPhrase(keyWord, cmdBuffer.toString()); cmdBuffer = new java.lang.StringBuffer(); keyWord = upperField; if (TinySQLGlobals.PARSER_DEBUG) { java.lang.SystemJ.outJ.println("Found keyword " + keyWord); } } } } if (keyWord != (String)null) { setPhrase(keyWord, cmdBuffer.toString()); } addAction(); if (TinySQLGlobals.PARSER_DEBUG) { java.lang.SystemJ.outJ.println("SQL:" + inputSQLBuffer.toString()); } } catch (Exception ex) { if (TinySQLGlobals.DEBUG) { java.lang.SystemJ.outJ.println(ex.StackTrace); //ex.printStackTrace(java.lang.SystemJ.outJ); } throw new TinySQLException(ex.getMessage()); } }
public void validateTable(String tableSpec, bool closeTable) //throws TinySQLException { /* * Create a table object for each table used in the SELECT statement * and store these objects in the tables Hashtable. Save the original * list of table names to set the default selection order. * * If closeTable is true the table object will be closed after it is * validated (for DROP TABLE and ALTER TABLE commands). */ String tableName, tableAlias, tableNameAndAlias, sortName; TinySQLTable addTable, sortTable; bool tableAdded; FieldTokenizer ftTable; int i, addRowCount, sortRowCount; ftTable = new FieldTokenizer(tableSpec, ' ', false); tableName = ftTable.getField(0); tableAlias = (ftTable.getField(1, tableName)).toUpperCase(); tableNameAndAlias = tableName + "->" + tableAlias; addTable = dbEngine.getTable(tableNameAndAlias); addTable.GoTop(); addRowCount = addTable.GetRowCount(); if (closeTable) { addTable.close(); } if (TinySQLGlobals.PARSER_DEBUG) { java.lang.SystemJ.outJ.println("Add table " + tableNameAndAlias + " to tables"); } tables.put(tableNameAndAlias, addTable); tableAdded = false; for (i = 0; i < tableList.size(); i++) { sortName = (String)tableList.elementAt(i); sortTable = (TinySQLTable)tables.get(sortName); sortRowCount = sortTable.GetRowCount(); /* * Sort the table selections from smallest to largest table to * enhance the query performance. */ if (addRowCount > sortRowCount) { continue; } tableList.insertElementAt(tableNameAndAlias, i); tableAdded = true; break; } if (!tableAdded) { tableList.addElement(tableNameAndAlias); } if (TinySQLGlobals.PARSER_DEBUG) { java.lang.SystemJ.outJ.println("Table selection order"); for (i = 0; i < tableList.size(); i++) { sortName = (String)tableList.elementAt(i); sortTable = (TinySQLTable)tables.get(sortName); sortRowCount = sortTable.GetRowCount(); java.lang.SystemJ.outJ.println(sortName + " " + sortRowCount); } } }
/* * Support function for restartable queries. Continue to * read the query result. The current state is taken from * tsResultSet. Proceed until maxFetchSize has reached. */ protected internal virtual void contSelectStatement(TsResultSet jrs) //throws TinySQLException { /* * The table scan here is an iterative tree expansion, similar to * the algorithm shown in the outline example in Chapter 5. */ String columnName, columnString, whereStatus, tableAndAlias; bool addOK; int i; int level = jrs.getLevel(); TinySQLTable jtbl; TsColumn updateColumn; java.util.Hashtable <Object, Object> tables = jrs.getTableState(); TinySQLWhere wc = jrs.getWhereClause(); /* * Create a hashtable to enumerate the tables to be scanned and initialize * with the first table name. */ java.util.Hashtable <Object, Object> tbl_list = new java.util.Hashtable <Object, Object>(); java.util.Vector <Object> t = (java.util.Vector <Object>)tables.get("TABLE_SELECT_ORDER"); String current = (String)t.elementAt(0); tbl_list.put(current, new java.lang.Integer(1)); /* * Create a row object; this is added to the ResultSet. */ TsRow record = new TsRow(); java.util.Vector <Object> resultSet = new java.util.Vector <Object>(); /* * Keep retrieving rows until we run out of rows to process. */ while (level > 0) { bool levelFound = false; /* * Find an item within the tbl_list which has the same level as the * one we're on. */ java.util.Enumeration <Object> keys = tbl_list.keys(); while (keys.hasMoreElements()) { /* * Get the next element in the "to be processed" * Hashtable, and find out its level, storing this * value in currLevel. */ String hashkey = (String)keys.nextElement(); int currLevel = ((java.lang.Integer)tbl_list.get(hashkey)).intValue(); /* * As soon as an element is found whose level is equal to the * one currently being processed, grab it's primary key (the hashkey), * flag levelfound, and break! */ if (currLevel == level) { current = hashkey; levelFound = true; break; } } bool haveRecord = false; // did we get a record or not? /* * If a table was found at the current level, then we should * try to get another row from it. */ if (levelFound) { /* * Get the current table */ jtbl = (TinySQLTable)tables.get(current); tableAndAlias = jtbl.table + "->" + jtbl.tableAlias; if (TinySQLGlobals.WHERE_DEBUG) { java.lang.SystemJ.outJ.println("Processing level " + level + " table " + tableAndAlias + "\n"); } /* * The following code is the start of setting up simple indexes * for tinySQL. The concept involves creating a new tinySQLCondition * class, instances of which will be created by tinySQLWhere. At least * initially only conditions that are equal to a constant will be * considered. One of these conditions will be stored inside the * dbfFileTable object. Calls to NextRecord would then have to add * logic to check to see if an index exists. The presence of a * complete index would be indicated by a counter that was equal * to the number of rows in the table. In that case a single get * would deliver the record numbers required for the where condition. * The NextRecord function would return these record numbers in * sequence. If the index did not exist then new values in the * index Hashtable would be created. None of this code has been * developed or implemented, let alone tested. * * * if ( wc != (tinySQLWhere)null ) * jtbl.setIndexCondition(wc.getIndexCondition(tableAndAlias)); */ if (performDebug) { java.lang.SystemJ.outJ.println("Selecting records from " + jtbl.table); } /* * Skip to the next undeleted record; at some point, * this will run out of records, and found will be false. */ bool found = false; while (jtbl.NextRecord()) { /* * Clear the column values for this table before starting * to process the next row. */ for (i = 0; i < jrs.numcols(); i++) { updateColumn = jrs.columnAtIndex(i, true); updateColumn.clear(tableAndAlias); } if (wc != (TinySQLWhere)null) { wc.clearValues(tableAndAlias); } if (!jtbl.isDeleted()) { /* * Evaluate the where clause for each column in the table. If * it is false, skip to the next row. Otherwise, add the * column value to the output record. */ java.util.Enumeration <Object> cols = jtbl.column_info.keys(); found = true; whereStatus = "TRUE"; while (cols.hasMoreElements()) { columnName = tableAndAlias + "." + (String)cols.nextElement(); columnString = jtbl.GetCol(columnName); if (wc != (TinySQLWhere)null) { whereStatus = wc.evaluate(columnName, columnString); if (whereStatus.equals("FALSE")) { /* * This column value caused the where clause to * be FALSE. Go to the next row in the table. */ found = false; break; } } /* * Update the ResultSet tsColumn values */ jrs.updateColumns(columnName, columnString); } /* * If no where condition has evaluated to false then this * record is a candidate for output. Break to the next table * in this case for further WHERE processing. */ if (found) { break; } } } if (found) { if (TinySQLGlobals.DEBUG) { java.lang.SystemJ.outJ.println("Build candidate record."); } for (i = 0; i < jrs.numcols(); i++) { updateColumn = jrs.columnAtIndex(i, true); /* * Evaluate all functions before adding the * column to the output record. */ updateColumn.updateFunctions(); columnString = updateColumn.getString(); if (updateColumn.isNotNull()) { record.put(updateColumn.name, columnString); } else { record.remove(updateColumn.name); } } if (performDebug) { java.lang.SystemJ.outJ.println("Record is " + record.toString()); } /* * If the table we are processing is not the last in * the list, then we should increment level and loop to the top. */ if (level < t.size()) { /* * Increment level */ level++; /* * Add the next table in the list of tables to * the tbl_list, the Hashtable of "to be processed" tables. */ String next_tbl = (String)t.elementAt(level - 1); tbl_list.put(next_tbl, new java.lang.Integer(level)); } else { /* * If the table that was just processed is the last in * the list, then we have drilled down to the bottom; * all columns have values, and we can add it to the * result set. The next time through, the program * will try to read another row at this level; if it's * found, only columns for the table being read will * be overwritten in the tsRow. * * Columns for the other table will be left alone, and * another row will be added to the result set. Here * is the essence of the Cartesian Product which is * being built here. */ haveRecord = true; } } else { /* * We didn't find any more records at this level. * Reset the record pointer to the top of the table, * and decrement level. We have hit end of file here. */ if (wc != (TinySQLWhere)null) { wc.clearValues(tableAndAlias); } level--; jtbl.GoTop(); } } else { /* * No tables were found at this level; back up a level * and see if there's any up there. */ level--; } /* * If we got a record, then add it to the result set. */ if (haveRecord) { /* * If group functions are involved, add records only after a break, * which is defined as a change in all of the group columns. * Otherwise, update the current record. */ if (jrs.isGrouped()) { if (groupBreak) { addOK = jrs.addRow((TsRow)record.clone()); if (addOK == false) { jrs.setLevel(level); return; } groupBreak = false; } else { jrs.updateRow((TsRow)record.clone()); } } else { /* * No group functions are involved. Just add the record. */ addOK = jrs.addRow((TsRow)record.clone()); if (addOK == false) { jrs.setLevel(level); return; } } } } /* * Close all the tables */ for (i = 0; i < t.size(); i++) { jtbl = (TinySQLTable)tables.get((String)t.elementAt(i)); jtbl.close(); } /* * return a result set */ jrs.setLevel(0); }
static internal java.util.Map DeriveStyle(java.util.Map attribs, FontStyle style, bool createNew) { java.util.Map newAttribs; if (createNew) { newAttribs = new java.util.Hashtable(attribs.size()); java.util.Iterator it = attribs.keySet().iterator(); while (it.hasNext()) { object key = it.next(); object value = attribs.get(key); if (value != null) { newAttribs.put(key, value); } } } else { newAttribs = attribs; } //Bold if ((style & FontStyle.Bold) == FontStyle.Bold) { newAttribs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); } else { newAttribs.remove(TextAttribute.WEIGHT); } //Italic if ((style & FontStyle.Italic) == FontStyle.Italic) { newAttribs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); } else { newAttribs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR); } //Underline if ((style & FontStyle.Underline) == FontStyle.Underline) { newAttribs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); } else { newAttribs.remove(TextAttribute.UNDERLINE); } //Strikeout if ((style & FontStyle.Strikeout) == FontStyle.Strikeout) { newAttribs.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); } else { newAttribs.remove(TextAttribute.STRIKETHROUGH); } return(newAttribs); }
static internal java.util.Map DeriveStyle(java.util.Map attribs, FontStyle style, bool createNew) { java.util.Map newAttribs; if (createNew) { newAttribs = new java.util.Hashtable( attribs.size() ); java.util.Iterator it = attribs.keySet().iterator(); while (it.hasNext ()) { object key = it.next (); object value = attribs.get (key); if (value != null) newAttribs.put (key, value); } } else newAttribs = attribs; //Bold if((style & FontStyle.Bold) == FontStyle.Bold) newAttribs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); else newAttribs.remove(TextAttribute.WEIGHT); //Italic if((style & FontStyle.Italic) == FontStyle.Italic) newAttribs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); else newAttribs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR); //Underline if((style & FontStyle.Underline) == FontStyle.Underline) newAttribs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); else newAttribs.remove(TextAttribute.UNDERLINE); //Strikeout if((style & FontStyle.Strikeout) == FontStyle.Strikeout) newAttribs.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); else newAttribs.remove(TextAttribute.STRIKETHROUGH); return newAttribs; }
/* * opens a DBF file. This is based on Pratap Pereira's * Xbase.pm perl module * @return column definition list (java.util.Hashtable<Object,Object>) * * @author Thomas Morgner <*****@*****.**> added check for * file exists, before the file is opened. Opening a non existing * file will create a new file, and we get errors while trying * to read the non-existend headers */ java.util.Hashtable <Object, Object> open_dbf() //throws TinySQLException { try { java.io.File f = new java.io.File(fullPath); if (TinySQLGlobals.DEBUG) { java.lang.SystemJ.outJ.println("Try to open " + f.getAbsolutePath()); } if (!f.exists()) { throw new TinySQLException("Unable to open " + f.getAbsolutePath() + " - does not exist. or can't be read."); } else if (!f.canRead()) { throw new TinySQLException("Unable to open " + f.getAbsolutePath() + " - file can't be read (permissions?)."); } if (f.canWrite()) { ftbl = new java.io.RandomAccessFile(f, "rw"); } else { /* * Open readonly if the file is not writeable. Needed for * databases on CD-Rom */ ftbl = new java.io.RandomAccessFile(f, "r"); } /* * Read the first 32 bytes ... */ dbfHeader = new DBFHeader(ftbl); /* * read the column info (each is a 32 byte bulk) ... */ java.util.Hashtable <Object, Object> coldef_list = new java.util.Hashtable <Object, Object>(); columnNameKeys = new java.util.Vector <Object>(); int locn = 0; // offset of the current column for (int i = 1; i <= dbfHeader.numFields; i++) { TsColumn coldef = DBFFile.readColdef(ftbl, table, i, locn); locn += coldef.size; // increment locn by the length of this field. coldef_list.put(coldef.name, coldef); columnNameKeys.addElement(coldef.name); } fileOpen = true; return(coldef_list); } catch (Exception e) { if (TinySQLGlobals.DEBUG) { java.lang.SystemJ.err.println(e.ToString()); // e.printStackTrace(); } throw new TinySQLException(e.getMessage()); } }
// end methods implemented from tinySQLTable.java // the rest of this stuff is internal methods // for textFileTable // /* * * Reads in a table definition and populates the column_info * Hashtable * */ void readColumnInfo() {//throws tinySQLException { try { column_info = new java.util.Hashtable <Object, Object>(); // Open an FileInputStream to the .def (table // definition) file // java.io.FileInputStream fdef = new java.io.FileInputStream(dataDir + "/" + table + ".def"); // use a StreamTokenizer to break up the stream. // java.io.Reader r = new java.io.BufferedReader( new java.io.InputStreamReader(fdef)); java.io.StreamTokenizer def = new java.io.StreamTokenizer(r); // set the | as a delimiter, and set everything between // 0 and z as word characters. Let it know that eol is // *not* significant, and that it should parse numbers. // def.whitespaceChars('|', '|'); def.wordChars('0', 'z'); def.eolIsSignificant(false); def.parseNumbers(); // read each token from the tokenizer // while (def.nextToken() != java.io.StreamTokenizer.TT_EOF) { // first token is the datatype // // Q&D: Default is char value, numeric is special String datatype = java.lang.StringJ.valueOf(java.sql.Types.CHAR); if (def.sval.equals("NUMERIC")) { datatype = java.lang.StringJ.valueOf(java.sql.Types.NUMERIC); } // get the next token; it's the column name // def.nextToken(); String column = def.sval; // get the third token; it's the size of the column // def.nextToken(); long size = (new java.lang.Double(def.nval)).longValue(); // create an info array // String[] info = new String[3]; // store the datatype, the size, and the position // within the record (the record length *before* // we increment it with the size of this column // info[COLUMN_TYPE] = datatype; info[COLUMN_SIZE] = java.lang.Long.toString(size); info[COLUMN_POS] = java.lang.Long.toString(record_length); // this is the start position of the next column // record_length += size; // store this info in the column_info hash, // keyed by column name. // column_info.put(column, info); } fdef.close(); // close the file } catch (Exception e) { throw new TinySQLException(e.getMessage()); } }
/* * Sets the receiver's stream handler to one which is appropriate for its * protocol. Throws a MalformedURLException if no reasonable handler is * available. * <p/> * Note that this will overwrite any existing stream handler with the new * one. Senders must check if the strmHandler is null before calling the * method if they do not want this behavior (a speed optimization). */ void setupStreamHandler() { String className = null; // Check for a cached (previously looked up) handler for // the requested protocol. strmHandler = streamHandlers.get(protocol); if (strmHandler != null) { return; } // If there is a stream handler factory, then attempt to // use it to create the handler. if (streamHandlerFactory != null) { strmHandler = streamHandlerFactory.createURLStreamHandler(protocol); if (strmHandler != null) { streamHandlers.put(protocol, strmHandler); return; } } // Check if there is a list of packages which can provide handlers. // If so, then walk this list looking for an applicable one. String packageList = java.security.AccessController .doPrivileged(new PriviAction <String>( "java.protocol.handler.pkgs")); //$NON-NLS-1$ if (packageList != null) { java.util.StringTokenizer st = new java.util.StringTokenizer(packageList, "|"); //$NON-NLS-1$ while (st.hasMoreTokens()) { className = st.nextToken() + "." + protocol + ".Handler"; //$NON-NLS-1$ //$NON-NLS-2$ try { strmHandler = (URLStreamHandler)java.lang.Class.forName(className, true, java.lang.ClassLoader.getSystemClassLoader()) .newInstance(); if (strmHandler != null) { streamHandlers.put(protocol, strmHandler); } return; } catch (java.lang.IllegalAccessException e) { } catch (java.lang.InstantiationException e) { } catch (java.lang.ClassNotFoundException e) { } } } // No one else has provided a handler, so try our internal one. className = "org.apache.harmony.luni.internal.net.www.protocol." + protocol //$NON-NLS-1$ + ".Handler"; //$NON-NLS-1$ try { strmHandler = (URLStreamHandler)java.lang.Class.forName(className) .newInstance(); } catch (java.lang.IllegalAccessException e) { } catch (java.lang.InstantiationException e) { } catch (java.lang.ClassNotFoundException e) { } if (strmHandler != null) { streamHandlers.put(protocol, strmHandler); } }
/* * Adds the argument to the collection. * * @param permission * the permission to add to the collection. */ public override void add(Permission permission) { perms.put(permission, permission); }
private void initOutputFiles()//throws FileNotFoundException, IOException { { while (true) { // try to find a unique file which is not locked by other process uniqueID++; // FIXME: improve performance here for (int generation = 0; generation < count; generation++) { // cache all file names for rotation use files[generation] = new java.io.File(parseFileName(generation)); } fileName = files[0].getAbsolutePath(); lock (allLocks) { /* * if current process has held lock for this fileName continue * to find next file */ if (null != allLocks.get(fileName)) { continue; } if (files[0].exists() && (!append || files[0].length() >= limit)) { for (int i = count - 1; i > 0; i--) { if (files[i].exists()) { files[i].delete(); } files[i - 1].renameTo(files[i]); } } java.io.FileOutputStream fileStream = new java.io.FileOutputStream(fileName + LCK_EXT); java.nio.channels.FileChannel channel = fileStream.getChannel(); /* * if lock is unsupported and IOException thrown, just let the * IOException throws out and exit otherwise it will go into an * undead cycle */ lockJ = channel.tryLock(); if (null == lockJ) { try { fileStream.close(); } catch (Exception e) { // ignore } continue; } allLocks.put(fileName, lockJ); break; } } output = new MeasureOutputStream(new java.io.BufferedOutputStream( new java.io.FileOutputStream(fileName, append)), files[0].length()); setOutputStream(output); }
public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte charSet, bool isVertical) { if (family == null) throw new ArgumentNullException("family"); _gUnit = unit; _fontFamily = family; _charset = charSet; java.util.Hashtable attribs = new java.util.Hashtable(); attribs.put(TextAttribute.FAMILY, family.Name/*TODO: family doungrade possibility*/); //init defaults attribs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR); float newSize = emSize * Graphics.UnitConversion[ (int)_gUnit ]; attribs.put(TextAttribute.SIZE, new java.lang.Float(newSize)); DeriveStyle(attribs, style, false); _jFont = family.FamilyFont.deriveFont(attribs); }