src/java.sql.rowset/share/classes/com/sun/rowset/internal/WebRowSetXmlWriter.java
author rriggs
Fri, 07 Dec 2018 11:51:17 -0500
changeset 52902 e3398b2e1ab0
parent 47216 71c04702a3d5
permissions -rw-r--r--
8214971: Replace use of string.equals("") with isEmpty() Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
11680
8be4a665d07e 7132879: address Findbugs issue in WebRowSetXmlWriter
lancea
parents: 11129
diff changeset
     2
 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.rowset.internal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.rowset.JdbcRowSetResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.text.MessageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.sql.rowset.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.sql.rowset.spi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    39
 * An implementation of the {@code XmlWriter}  interface, which writes a
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    40
 * {@code WebRowSet}  object to an output stream as an XML document.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class WebRowSetXmlWriter implements XmlWriter, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    46
     * The {@code java.io.Writer}  object to which this {@code WebRowSetXmlWriter}
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    47
     * object will write when its {@code writeXML}  method is called. The value
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    48
     * for this field is set with the {@code java.io.Writer}  object given
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    49
     * as the second argument to the {@code writeXML}  method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
11680
8be4a665d07e 7132879: address Findbugs issue in WebRowSetXmlWriter
lancea
parents: 11129
diff changeset
    51
    private transient java.io.Writer writer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    54
     * The {@code java.util.Stack}  object that this {@code WebRowSetXmlWriter}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * object will use for storing the tags to be used for writing the calling
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    56
     * {@code WebRowSet}  object as an XML document.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 6697
diff changeset
    58
    private java.util.Stack<String> stack;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private  JdbcRowSetResourceBundle resBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public WebRowSetXmlWriter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
           resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        } catch(IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            throw new RuntimeException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    72
     * Writes the given {@code WebRowSet}  object as an XML document
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    73
     * using the given {@code java.io.Writer}  object. The XML document
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    74
     * will include the {@code WebRowSet}  object's data, metadata, and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * properties.  If a data value has been updated, that information is also
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * included.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * <P>
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    78
     * This method is called by the {@code XmlWriter}  object that is
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    79
     * referenced in the calling {@code WebRowSet}  object's
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    80
     * {@code xmlWriter}  field.  The {@code XmlWriter.writeXML}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * method passes to this method the arguments that were supplied to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    83
     * @param caller the {@code WebRowSet}  object to be written; must
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    84
     *        be a rowset for which this {@code WebRowSetXmlWriter}  object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *        is the writer
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    86
     * @param wrt the {@code java.io.Writer}  object to which
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    87
     *        {@code caller}  will be written
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @exception SQLException if a database access error occurs or
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    89
     *            this {@code WebRowSetXmlWriter}  object is not the writer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *            for the given rowset
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @see XmlWriter#writeXML
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public void writeXML(WebRowSet caller, java.io.Writer wrt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        // create a new stack for tag checking.
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 6697
diff changeset
    97
        stack = new java.util.Stack<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        writer = wrt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        writeRowSet(caller);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   103
     * Writes the given {@code WebRowSet}  object as an XML document
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   104
     * using the given {@code java.io.OutputStream}  object. The XML document
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   105
     * will include the {@code WebRowSet}  object's data, metadata, and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * properties.  If a data value has been updated, that information is also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * included.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * <P>
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   109
     * Using stream is a faster way than using {@code java.io.Writer}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   111
     * This method is called by the {@code XmlWriter}  object that is
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   112
     * referenced in the calling {@code WebRowSet}  object's
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   113
     * {@code xmlWriter}  field.  The {@code XmlWriter.writeXML}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * method passes to this method the arguments that were supplied to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   116
     * @param caller the {@code WebRowSet}  object to be written; must
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   117
     *        be a rowset for which this {@code WebRowSetXmlWriter}  object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *        is the writer
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   119
     * @param oStream the {@code java.io.OutputStream}  object to which
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   120
     *        {@code caller}  will be written
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @throws SQLException if a database access error occurs or
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   122
     *            this {@code WebRowSetXmlWriter}  object is not the writer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *            for the given rowset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @see XmlWriter#writeXML
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public void writeXML(WebRowSet caller, java.io.OutputStream oStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // create a new stack for tag checking.
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 6697
diff changeset
   130
        stack = new java.util.Stack<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        writer = new OutputStreamWriter(oStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        writeRowSet(caller);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @exception SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private void writeRowSet(WebRowSet caller) throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            startHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            writeProperties(caller);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            writeMetaData(caller);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            writeData(caller);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            endHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        } catch (java.io.IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            throw new SQLException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.ioex").toString(), ex.getMessage()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    private void startHeader() throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        setTag("webRowSet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        writer.write("<?xml version=\"1.0\"?>\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        writer.write("<webRowSet xmlns=\"http://java.sun.com/xml/ns/jdbc\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        writer.write("xsi:schemaLocation=\"http://java.sun.com/xml/ns/jdbc http://java.sun.com/xml/ns/jdbc/webrowset.xsd\">\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    private void endHeader() throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        endTag("webRowSet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @exception SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    private void writeProperties(WebRowSet caller) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        beginSection("properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            propString("command", processSpecialCharacters(caller.getCommand()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            propInteger("concurrency", caller.getConcurrency());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            propString("datasource", caller.getDataSourceName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            propBoolean("escape-processing",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    caller.getEscapeProcessing());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                propInteger("fetch-direction", caller.getFetchDirection());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            } catch(SQLException sqle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                // it may be the case that fetch direction has not been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                // fetchDir  == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                // in that case it will throw a SQLException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                // To avoid that catch it here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            propInteger("fetch-size", caller.getFetchSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            propInteger("isolation-level",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    caller.getTransactionIsolation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            beginSection("key-columns");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            int[] kc = caller.getKeyColumns();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            for (int i = 0; kc != null && i < kc.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                propInteger("column", kc[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            endSection("key-columns");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            //Changed to beginSection and endSection for maps for proper indentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            beginSection("map");
11680
8be4a665d07e 7132879: address Findbugs issue in WebRowSetXmlWriter
lancea
parents: 11129
diff changeset
   208
            Map<String, Class<?>> typeMap = caller.getTypeMap();
8be4a665d07e 7132879: address Findbugs issue in WebRowSetXmlWriter
lancea
parents: 11129
diff changeset
   209
            if(typeMap != null) {
8be4a665d07e 7132879: address Findbugs issue in WebRowSetXmlWriter
lancea
parents: 11129
diff changeset
   210
                for(Map.Entry<String, Class<?>> mm : typeMap.entrySet()) {
8be4a665d07e 7132879: address Findbugs issue in WebRowSetXmlWriter
lancea
parents: 11129
diff changeset
   211
                    propString("type", mm.getKey());
8be4a665d07e 7132879: address Findbugs issue in WebRowSetXmlWriter
lancea
parents: 11129
diff changeset
   212
                    propString("class", mm.getValue().getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            endSection("map");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            propInteger("max-field-size", caller.getMaxFieldSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            propInteger("max-rows", caller.getMaxRows());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            propInteger("query-timeout", caller.getQueryTimeout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            propBoolean("read-only", caller.isReadOnly());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            int itype = caller.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            String strType = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            if(itype == 1003) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                strType = "ResultSet.TYPE_FORWARD_ONLY";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            } else if(itype == 1004) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                strType = "ResultSet.TYPE_SCROLL_INSENSITIVE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            } else if(itype == 1005) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                strType = "ResultSet.TYPE_SCROLL_SENSITIVE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            propString("rowset-type", strType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            propBoolean("show-deleted", caller.getShowDeleted());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            propString("table-name", caller.getTableName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            propString("url", caller.getUrl());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            beginSection("sync-provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            // Remove the string after "@xxxx"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            // before writing it to the xml file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            String strProviderInstance = (caller.getSyncProvider()).toString();
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 11680
diff changeset
   243
            String strProvider = strProviderInstance.substring(0, (caller.getSyncProvider()).toString().indexOf('@'));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            propString("sync-provider-name", strProvider);
6671
c5fbc05d7347 6984044: RowSet source needs to rebrand vendor references
lancea
parents: 6530
diff changeset
   246
            propString("sync-provider-vendor", "Oracle Corporation");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            propString("sync-provider-version", "1.0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            propInteger("sync-provider-grade", caller.getSyncProvider().getProviderGrade());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            propInteger("data-source-lock", caller.getSyncProvider().getDataSourceLock());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            endSection("sync-provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        } catch (SQLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        endSection("properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @exception SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    private void writeMetaData(WebRowSet caller) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        int columnCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        beginSection("metadata");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            ResultSetMetaData rsmd = caller.getMetaData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            columnCount = rsmd.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            propInteger("column-count", columnCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            for (int colIndex = 1; colIndex <= columnCount; colIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                beginSection("column-definition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                propInteger("column-index", colIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                propBoolean("auto-increment", rsmd.isAutoIncrement(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                propBoolean("case-sensitive", rsmd.isCaseSensitive(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                propBoolean("currency", rsmd.isCurrency(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                propInteger("nullable", rsmd.isNullable(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                propBoolean("signed", rsmd.isSigned(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                propBoolean("searchable", rsmd.isSearchable(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                propInteger("column-display-size",rsmd.getColumnDisplaySize(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                propString("column-label", rsmd.getColumnLabel(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                propString("column-name", rsmd.getColumnName(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                propString("schema-name", rsmd.getSchemaName(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                propInteger("column-precision", rsmd.getPrecision(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                propInteger("column-scale", rsmd.getScale(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                propString("table-name", rsmd.getTableName(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                propString("catalog-name", rsmd.getCatalogName(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                propInteger("column-type", rsmd.getColumnType(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                propString("column-type-name", rsmd.getColumnTypeName(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                endSection("column-definition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        } catch (SQLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        endSection("metadata");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @exception SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    private void writeData(WebRowSet caller) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        ResultSet rs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            ResultSetMetaData rsmd = caller.getMetaData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            int columnCount = rsmd.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            beginSection("data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            caller.beforeFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            caller.setShowDeleted(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            while (caller.next()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                if (caller.rowDeleted() && caller.rowInserted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    beginSection("modifyRow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                } else if (caller.rowDeleted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    beginSection("deleteRow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                } else if (caller.rowInserted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    beginSection("insertRow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    beginSection("currentRow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                for (i = 1; i <= columnCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    if (caller.columnUpdated(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                        rs = caller.getOriginalRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                        rs.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                        beginTag("columnValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                        writeValue(i, (RowSet)rs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                        endTag("columnValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                        beginTag("updateRow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                        writeValue(i, caller);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                        endTag("updateRow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                        beginTag("columnValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                        writeValue(i, caller);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                        endTag("columnValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                endSection(); // this is unchecked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            endSection("data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        } catch (SQLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    private void writeValue(int idx, RowSet caller) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            int type = caller.getMetaData().getColumnType(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                case java.sql.Types.BIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                case java.sql.Types.BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    boolean b = caller.getBoolean(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                        writeBoolean(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                case java.sql.Types.TINYINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                case java.sql.Types.SMALLINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    short s = caller.getShort(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                        writeShort(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                case java.sql.Types.INTEGER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    int i = caller.getInt(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    else
6697
39929804f9d4 6989139: Address JDBC Findbugs where Number type Constructor are used
lancea
parents: 6692
diff changeset
   385
                        writeInteger(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                case java.sql.Types.BIGINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    long l = caller.getLong(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                        writeLong(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                case java.sql.Types.REAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                case java.sql.Types.FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    float f = caller.getFloat(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                        writeFloat(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                case java.sql.Types.DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    double d = caller.getDouble(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                        writeDouble(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                case java.sql.Types.NUMERIC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                case java.sql.Types.DECIMAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                    writeBigDecimal(caller.getBigDecimal(idx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                case java.sql.Types.BINARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                case java.sql.Types.VARBINARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                case java.sql.Types.LONGVARBINARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                case java.sql.Types.DATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    java.sql.Date date = caller.getDate(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                        writeLong(date.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                case java.sql.Types.TIME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    java.sql.Time time = caller.getTime(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                        writeLong(time.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                case java.sql.Types.TIMESTAMP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    java.sql.Timestamp ts = caller.getTimestamp(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                        writeLong(ts.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                case java.sql.Types.CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                case java.sql.Types.VARCHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                case java.sql.Types.LONGVARCHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    writeStringData(caller.getString(idx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    System.out.println(resBundle.handleGetObject("wsrxmlwriter.notproper").toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    //Need to take care of BLOB, CLOB, Array, Ref here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        } catch (SQLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            throw new java.io.IOException(resBundle.handleGetObject("wrsxmlwriter.failedwrite").toString()+ ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * This begins a new tag with a indent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    private void beginSection(String tag) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        // store the current tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        setTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        writeIndent(stack.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        // write it out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        writer.write("<" + tag + ">\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * This closes a tag started by beginTag with a indent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    private void endSection(String tag) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        writeIndent(stack.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        String beginTag = getTag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        if(beginTag.indexOf("webRowSet") != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            beginTag ="webRowSet";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (tag.equals(beginTag) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            // get the current tag and write it out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            writer.write("</" + beginTag + ">\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        writer.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    private void endSection() throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        writeIndent(stack.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        // get the current tag and write it out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        String beginTag = getTag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        writer.write("</" + beginTag + ">\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        writer.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    private void beginTag(String tag) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        // store the current tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        setTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        writeIndent(stack.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        // write tag out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        writer.write("<" + tag + ">");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    private void endTag(String tag) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        String beginTag = getTag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (tag.equals(beginTag)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            // get the current tag and write it out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            writer.write("</" + beginTag + ">\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        writer.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    private void emptyTag(String tag) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        // write an emptyTag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        writer.write("<" + tag + "/>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    private void setTag(String tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        // add the tag to stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        stack.push(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    private String getTag() {
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 6697
diff changeset
   530
        return stack.pop();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    private void writeNull() throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        emptyTag("null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    private void writeStringData(String s) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            writeNull();
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   540
        } else if (s.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            writeEmptyString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            s = processSpecialCharacters(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            writer.write(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    private void writeString(String s) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            writer.write(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        } else  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    private void writeShort(short s) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        writer.write(Short.toString(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    private void writeLong(long l) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        writer.write(Long.toString(l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    private void writeInteger(int i) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        writer.write(Integer.toString(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    private void writeBoolean(boolean b) throws java.io.IOException {
6697
39929804f9d4 6989139: Address JDBC Findbugs where Number type Constructor are used
lancea
parents: 6692
diff changeset
   572
        writer.write(Boolean.valueOf(b).toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    private void writeFloat(float f) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        writer.write(Float.toString(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    private void writeDouble(double d) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        writer.write(Double.toString(d));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    private void writeBigDecimal(java.math.BigDecimal bd) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        if (bd != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            writer.write(bd.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            emptyTag("null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    private void writeIndent(int tabs) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        // indent...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        for (int i = 1; i < tabs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            writer.write("  ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    private void propString(String tag, String s) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        beginTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        writeString(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        endTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    private void propInteger(String tag, int i) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        beginTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        writeInteger(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        endTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    private void propBoolean(String tag, boolean b) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        beginTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        writeBoolean(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        endTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    private void writeEmptyString() throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        emptyTag("emptyString");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * Purely for code coverage purposes..
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    public boolean writeData(RowSetInternal caller) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * This function has been added for the processing of special characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * lik <,>,'," and & in the data to be serialized. These have to be taken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * of specifically or else there will be parsing error while trying to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * the contents of the XML file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    private String processSpecialCharacters(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        if(s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        char []charStr = s.toCharArray();
6692
aef4e294026f 6988993: Address Findbugs warnings for the use of String Constructor
lancea
parents: 6671
diff changeset
   639
        String specialStr = "";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        for(int i = 0; i < charStr.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            if(charStr[i] == '&') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                specialStr = specialStr.concat("&amp;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            } else if(charStr[i] == '<') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                specialStr = specialStr.concat("&lt;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            } else if(charStr[i] == '>') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                specialStr = specialStr.concat("&gt;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            } else if(charStr[i] == '\'') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                specialStr = specialStr.concat("&apos;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            } else if(charStr[i] == '\"') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                specialStr = specialStr.concat("&quot;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                specialStr = specialStr.concat(String.valueOf(charStr[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        s = specialStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
6530
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   661
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   662
    /**
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   663
     * This method re populates the resBundle
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   664
     * during the deserialization process
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   665
     *
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   666
     */
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   667
    private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   668
        // Default state initialization happens here
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   669
        ois.defaultReadObject();
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   670
        // Initialization of transient Res Bundle happens here .
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   671
        try {
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   672
           resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   673
        } catch(IOException ioe) {
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   674
            throw new RuntimeException(ioe);
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   675
        }
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   676
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   677
    }
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   678
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   679
    static final long serialVersionUID = 7163134986189677641L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
}