1452 lines · 48.7 KB · Java
RawDownload
/* * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.  Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.rowset.internal; import java.util.*; import org.xml.sax.*;import org.xml.sax.helpers.*; import java.sql.*;import javax.sql.*; import javax.sql.rowset.*;import com.sun.rowset.*;import java.io.IOException;import java.text.MessageFormat; /** * The document handler that receives parse events that an XML parser sends while it * is parsing an XML document representing a <code>WebRowSet</code> object. The * parser sends strings to this <code>XmlReaderContentHandler</code> and then uses * these strings as arguments for the <code>XmlReaderContentHandler</code> methods * it invokes. The final goal of the SAX parser working with an * <code>XmlReaderContentHandler</code> object is to read an XML document that represents * a <code>RowSet</code> object. * <P> * A rowset consists of its properties, metadata, and data values. An XML document * representating a rowset includes the values in these three categories along with * appropriate XML tags to identify them.  It also includes a top-level XML tag for * the rowset and three section tags identifying the three categories of values. * <P> * The tags in an XML document are hierarchical. * This means that the top-level tag, <code>RowSet</code>, is * followed by the three sections with appropriate tags, which are in turn each * followed by their constituent elements. For example, the <code>properties</code> * element will be followed by an element for each of the properties listed in * in this <code>XmlReaderContentHandler</code> object's <code>properties</code> * field.  The content of the other two fields, <code>colDef</code>, which lists * the rowset's metadata elements, and <code>data</code>, which lists the rowset's data * elements, are handled similarly . * <P> * This implementation of <code>XmlReaderContentHandler</code> provides the means for the * parser to determine which elements need to have a value set and then to set * those values. The methods in this class are all called by the parser; an * application programmer never calls them directly. * */ public class XmlReaderContentHandler extends DefaultHandler {     private HashMap propMap;    private HashMap colDefMap;    private HashMap dataMap;     private HashMap typeMap;     private Vector updates;    private Vector keyCols;     private String columnValue;    private String propertyValue;    private String metaDataValue;     private int tag;    private int state;     private WebRowSetImpl rs;    private boolean nullVal;    private boolean emptyStringVal;    private RowSetMetaData md;    private int idx;    private String lastval;    private String Key_map;    private String Value_map;    private String tempStr;    private String tempUpdate;    private String tempCommand;    private Object [] upd;     /**     * A list of the properties for a rowset. There is a constant defined to     * correspond to each of these properties so that a <code>HashMap</code>     * object can be created to map the properties, which are strings, to     * the constants, which are integers.     */    private String [] properties = {"command", "concurrency", "datasource",                            "escape-processing", "fetch-direction", "fetch-size",                            "isolation-level", "key-columns", "map",                            "max-field-size", "max-rows", "query-timeout",                            "read-only", "rowset-type", "show-deleted",                            "table-name", "url", "null", "column", "type",                            "class", "sync-provider", "sync-provider-name",                             "sync-provider-vendor", "sync-provider-version",                             "sync-provider-grade","data-source-lock"};     /**     * A constant representing the tag for the command property.     */    private final static int CommandTag = 0;     /**     * A constant representing the tag for the concurrency property.     */    private final static int ConcurrencyTag = 1;     /**     * A constant representing the tag for the datasource property.     */    private final static int DatasourceTag = 2;     /**     * A constant representing the tag for the escape-processing property.     */    private final static int EscapeProcessingTag = 3;     /**     * A constant representing the tag for the fetch-direction property.     */    private final static int FetchDirectionTag = 4;     /**     * A constant representing the tag for the fetch-size property.     */    private final static int FetchSizeTag = 5;     /**     * A constant representing the tag for the isolation-level property     */    private final static int IsolationLevelTag = 6;     /**     * A constant representing the tag for the key-columns property.     */    private final static int KeycolsTag = 7;     /**     * A constant representing the tag for the map property.     * This map is the type map that specifies the custom mapping     * for an SQL user-defined type.     */    private final static int MapTag = 8;     /**     * A constant representing the tag for the max-field-size property.     */    private final static int MaxFieldSizeTag = 9;     /**     * A constant representing the tag for the max-rows property.     */    private final static int MaxRowsTag = 10;     /**     * A constant representing the tag for the query-timeout property.     */    private final static int QueryTimeoutTag = 11;     /**     * A constant representing the tag for the read-only property.     */    private final static int ReadOnlyTag = 12;     /**     * A constant representing the tag for the rowset-type property.     */    private final static int RowsetTypeTag = 13;     /**     * A constant representing the tag for the show-deleted property.     */    private final static int ShowDeletedTag = 14;     /**     * A constant representing the tag for the table-name property.     */    private final static int TableNameTag = 15;     /**     * A constant representing the tag for the URL property.     */    private final static int UrlTag = 16;     /**     * A constant representing the tag for the null property.     */    private final static int PropNullTag = 17;     /**     * A constant representing the tag for the column property.     */    private final static int PropColumnTag = 18;     /**     * A constant representing the tag for the type property.     */    private final static int PropTypeTag = 19;     /**     * A constant representing the tag for the class property.     */    private final static int PropClassTag = 20;     /**     * A constant representing the tag for the sync-provider.     */    private final static int SyncProviderTag = 21;     /**     * A constant representing the tag for the sync-provider     * name     */    private final static int SyncProviderNameTag = 22;     /**     * A constant representing the tag for the sync-provider     * vendor tag.     */    private final static int SyncProviderVendorTag = 23;     /**     * A constant representing the tag for the sync-provider     * version tag.     */    private final static int SyncProviderVersionTag = 24;     /**     * A constant representing the tag for the sync-provider     * grade tag.     */    private final static int SyncProviderGradeTag = 25;     /**     * A constant representing the tag for the data source lock.     */    private final static int DataSourceLock = 26;     /**     * A listing of the kinds of metadata information available about     * the columns in a <code>WebRowSet</code> object.     */    private String [] colDef = {"column-count", "column-definition", "column-index",                        "auto-increment", "case-sensitive", "currency",                        "nullable", "signed", "searchable",                        "column-display-size", "column-label", "column-name",                        "schema-name", "column-precision", "column-scale",                        "table-name", "catalog-name", "column-type",                        "column-type-name", "null"};      /**     * A constant representing the tag for column-count.     */    private final static int ColumnCountTag = 0;     /**     * A constant representing the tag for column-definition.     */    private final static int ColumnDefinitionTag = 1;     /**     * A constant representing the tag for column-index.     */    private final static int ColumnIndexTag = 2;     /**     * A constant representing the tag for auto-increment.     */    private final static int AutoIncrementTag = 3;     /**     * A constant representing the tag for case-sensitive.     */    private final static int CaseSensitiveTag = 4;     /**     * A constant representing the tag for currency.     */    private final static int CurrencyTag = 5;     /**     * A constant representing the tag for nullable.     */    private final static int NullableTag = 6;     /**     * A constant representing the tag for signed.     */    private final static int SignedTag = 7;     /**     * A constant representing the tag for searchable.     */    private final static int SearchableTag = 8;     /**     * A constant representing the tag for column-display-size.     */    private final static int ColumnDisplaySizeTag = 9;     /**     * A constant representing the tag for column-label.     */    private final static int ColumnLabelTag = 10;     /**     * A constant representing the tag for column-name.     */    private final static int ColumnNameTag = 11;     /**     * A constant representing the tag for schema-name.     */    private final static int SchemaNameTag = 12;     /**     * A constant representing the tag for column-precision.     */    private final static int ColumnPrecisionTag = 13;     /**     * A constant representing the tag for column-scale.     */    private final static int ColumnScaleTag = 14;     /**     * A constant representing the tag for table-name.     */    private final static int MetaTableNameTag = 15;     /**     * A constant representing the tag for catalog-name.     */    private final static int CatalogNameTag = 16;     /**     * A constant representing the tag for column-type.     */    private final static int ColumnTypeTag = 17;     /**     * A constant representing the tag for column-type-name.     */    private final static int ColumnTypeNameTag = 18;     /**     * A constant representing the tag for null.     */    private final static int MetaNullTag = 19;     private String [] data = {"currentRow", "columnValue", "insertRow", "deleteRow", "insdel", "updateRow", "null" , "emptyString"};     private final static int RowTag = 0;    private final static int ColTag = 1;    private final static int InsTag = 2;    private final static int DelTag = 3;    private final static int InsDelTag = 4;    private final static int UpdTag = 5;    private final static int NullTag = 6;    private final static int EmptyStringTag = 7;     /**     * A constant indicating the state of this <code>XmlReaderContentHandler</code>     * object in which it has not yet been called by the SAX parser and therefore     * has no indication of what type of input to expect from the parser next.     * <P>     * The state is set to <code>INITIAL</code> at the end of each     * section, which allows the sections to appear in any order and     * still be parsed correctly (except that metadata must be     * set before data values can be set).     */    private final static int INITIAL = 0;     /**     * A constant indicating the state in which this <code>XmlReaderContentHandler</code>     * object expects the next input received from the     * SAX parser to be a string corresponding to one of the elements in     * <code>properties</code>.     */    private final static int PROPERTIES = 1;     /**     * A constant indicating the state in which this <code>XmlReaderContentHandler</code>     * object expects the next input received from the     * SAX parser to be a string corresponding to one of the elements in     * <code>colDef</code>.     */    private final static int METADATA = 2;     /**     * A constant indicating the state in which this <code>XmlReaderContentHandler</code>     * object expects the next input received from the     * SAX parser to be a string corresponding to one of the elements in     * <code>data</code>.     */    private final static int DATA = 3;     private  JdbcRowSetResourceBundle resBundle;     /**     * Constructs a new <code>XmlReaderContentHandler</code> object that will     * assist the SAX parser in reading a <code>WebRowSet</code> object in the     * format of an XML document. In addition to setting some default values,     * this constructor creates three <code>HashMap</code> objects, one for     * properties, one for metadata, and one for data.  These hash maps map the     * strings sent by the SAX parser to integer constants so that they can be     * compared more efficiently in <code>switch</code> statements.     *     * @param r the <code>RowSet</code> object in XML format that will be read     */    public XmlReaderContentHandler(RowSet r) {        // keep the rowset we've been given        rs = (WebRowSetImpl)r;         // set-up the token maps        initMaps();         // allocate the collection for the updates        updates = new Vector();         // start out with the empty string        columnValue = "";        propertyValue = "";        metaDataValue = "";         nullVal = false;        idx = 0;        tempStr = "";        tempUpdate = "";        tempCommand = "";         try {           resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();        } catch(IOException ioe) {            throw new RuntimeException(ioe);        }    }     /**     * Creates and initializes three new <code>HashMap</code> objects that map     * the strings returned by the SAX parser to <code>Integer</code>     * objects.  The strings returned by the parser will match the strings that     * are array elements in this <code>XmlReaderContentHandler</code> object's     * <code>properties</code>, <code>colDef</code>, or <code>data</code>     * fields. For each array element in these fields, there is a corresponding     * constant defined. It is to these constants that the strings are mapped.     * In the <code>HashMap</code> objects, the string is the key, and the     * integer is the value.     * <P>     * The purpose of the mapping is to make comparisons faster.  Because comparing     * numbers is more efficient than comparing strings, the strings returned     * by the parser are mapped to integers, which can then be used in a     * <code>switch</code> statement.     */    private void initMaps() {        int items, i;         propMap = new HashMap();        items = properties.length;         for (i=0;i<items;i++) {            propMap.put(properties[i], Integer.valueOf(i));        }         colDefMap = new HashMap();        items = colDef.length;         for (i=0;i<items;i++) {            colDefMap.put(colDef[i], Integer.valueOf(i));        }         dataMap = new HashMap();        items = data.length;         for (i=0;i<items;i++) {            dataMap.put(data[i], Integer.valueOf(i));        } 

Lines 1–500 of 1452.