webrowsetdataprovider.java
来自「java实现浏览器等本地桌面的功能」· Java 代码 · 共 724 行 · 第 1/3 页
JAVA
724 行
col.setType(Timestamp.class); break; case Types.ARRAY: case Types.BLOB: case Types.CLOB: case Types.DATALINK: case Types.DISTINCT: case Types.JAVA_OBJECT: case Types.OTHER: case Types.REF: case Types.STRUCT: //what to do with this? break; default : //do nothing } } } catch (Exception e) { e.printStackTrace(); } // TODO: new API // table.fireDataTableChanged(new TableChangeEvent(table)); } }); if (metadataCompleteRunnable != null) { SwingUtilities.invokeLater(metadataCompleteRunnable); } } } catch (Exception e) { e.printStackTrace();// LOG.error("Failed to parse something", e); } data = null; if (dataToLoad.size() >= 100) { doLoad(table, dataToLoad); dataToLoad = new LinkedList<RowLoadItem>(); } } /** * @inheritDoc */ public void startDocument() throws SAXException {// LOG.debug("Start of Document"); } public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { //reset the wasNull flag wasNull = false; //push the element name onto the stack. In this way, when // the characters method is called, I know what kind of data //I'm dealing with. String tag = qName.toLowerCase(); tagStack.push(tag); try { if (tag.equals("properties")) { inProperties = true; inMetaData = false; inData = false; } else if (tag.equals("metadata")) { inProperties = false; inMetaData = true; inData = false; metaData = new RowSetMetaDataImpl(); } else if (tag.equals("data")) { inProperties = false; inMetaData = false; inData = true; //construct the rowValues array rowValues = new Object[metaData.getColumnCount()]; } else if (tag.equals("currentrow")) { columnIndex = 1; reinitRowValues(); currentRow++; } else if (tag.equals("insertrow")) { columnIndex = 1; reinitRowValues(); currentRow++; } else if (tag.equals("deleterow")) { columnIndex = 1; reinitRowValues(); currentRow++; } else if (tag.equals("modifyrow")) { columnIndex = 1; reinitRowValues(); currentRow++; } } catch (Exception e) { e.printStackTrace(); } } /** * Utility method that clears out the rowValues array */ private void reinitRowValues() { for (int i=0; i<rowValues.length; i++) { rowValues[i] = null; } } } protected void loadData(LoadTask.LoadItem[] items) { for (LoadItem item : items) { DataTable table = item.table; List<RowLoadItem> loadItems = (List<RowLoadItem>)item.data; for (RowLoadItem loadItem : loadItems) { DataRow row = table.appendRowNoEvent(); List<DataColumn> cols = table.getColumns(); for (int i=0; i<loadItem.values.length; i++) { try { row.setValue(cols.get(i).getName(), loadItem.values[i]); } catch (Exception e) { System.out.println(loadItem.values.length); } } row.setStatus(loadItem.status); item.table.fireDataTableChanged(TableChangeEvent.newRowAddedEvent(item.table, row)); } item.table.fireDataTableChanged(TableChangeEvent.newLoadCompleteEvent(item.table)); } } protected void readData(DataTable[] tables) throws Exception { //get the XML from the url try { for (int i=0; i<tables.length; i++) { InputStream is = url.openStream(); readXml(new InputStreamReader(is), tables[i]); } } catch (Exception e) { e.printStackTrace(); } } public void doLoad(DataTable table, List items) { super.scheduleLoad(new LoadTask.LoadItem(table, items)); } /** * Originally this method was implemented with a PullParser. However, the * PullParser did not have very good error messages, so debugging the XML * was murder. A normal SAX parser is being used at this time. * * @inheritDoc */ public void readXml(Reader reader, final DataTable table) throws SQLException { try { /* * Parsing is done via SAX. The basic methodology is to keep a stack of tags seen. * Also, a flag is kept to keep track of whether or not a <null/> tag has been seen. * This flag is reset to false whenever a new tag is started, but is set to true when * the end of the <null> tag is found. * Also, A single variable contains the results of the character data for the current tag. * This variable is read after the end tag is found. You will find that all work is * done after the entire element has been read (after the end tag). */ WebRowSetXMLHandler handler = new WebRowSetXMLHandler(table); SAXParser parser = FACTORY.newSAXParser(); XMLReader xmlReader = parser.getXMLReader(); xmlReader.setProperty( "http://xml.org/sax/properties/lexical-handler", handler ); parser.parse(new InputSource(reader), handler ); } catch (Exception e) { e.printStackTrace(); throw new SQLException("Error while parsing a the xml document for a WebRowSetDataProvider"); } } }; }/* public static void main(String... args) { DataSet ds = new DataSet(); DataTable dt = ds.createTable(); dt.setName("Rowset"); DataProvider dp = new WebRowSetDataProvider(); dt.setDataProvider(dp); JFrame frame = new JFrame(); // JTable table = new JTable(); // //Binding b = BindingFactory.bind(table, dt); TabularDataModelAdapter adapter = new TabularDataModelAdapter(dt); // JNTable table = new JNTable(); // new DirectTableBinding(table.getTable(),adapter); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(800,600); frame.setVisible(true); dt.load();// dt.loadAndWait();// System.out.println(dt.getRows().size());// List<DataColumn> cols = dt.getColumns();// for (DataColumn col : cols) {// System.out.println(col.getName());// } } */ public URL getUrl() { return url; } public void setUrl(URL url) { this.url = url; } public Runnable getCompletionRunnable() { return completionRunnable; } public void setCompletionRunnable(Runnable completionRunnable) { this.completionRunnable = completionRunnable; } public Runnable getMetadataCompleteRunnable() { return metadataCompleteRunnable; } public void setMetadataCompleteRunnable(Runnable metadataCompleteRunnable) { this.metadataCompleteRunnable = metadataCompleteRunnable; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?