jdk/src/share/classes/com/sun/rowset/internal/WebRowSetXmlWriter.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * An implementation of the <code>XmlWriter</code> interface, which writes a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <code>WebRowSet</code> object to an output stream as an XML document.
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * The <code>java.io.Writer</code> object to which this <code>WebRowSetXmlWriter</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * object will write when its <code>writeXML</code> method is called. The value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * for this field is set with the <code>java.io.Writer</code> object given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * as the second argument to the <code>writeXML</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private java.io.Writer writer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * The <code>java.util.Stack</code> object that this <code>WebRowSetXmlWriter</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * object will use for storing the tags to be used for writing the calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * <code>WebRowSet</code> object as an XML document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private java.util.Stack stack;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Writes the given <code>WebRowSet</code> object as an XML document
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * using the given <code>java.io.Writer</code> object. The XML document
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * will include the <code>WebRowSet</code> object's data, metadata, and
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>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * This method is called by the <code>XmlWriter</code> object that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * referenced in the calling <code>WebRowSet</code> object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * <code>xmlWriter</code> field.  The <code>XmlWriter.writeXML</code>
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
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param caller the <code>WebRowSet</code> object to be written; must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *        be a rowset for which this <code>WebRowSetXmlWriter</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *        is the writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param wrt the <code>java.io.Writer</code> object to which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *        <code>caller</code> will be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @exception SQLException if a database access error occurs or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *            this <code>WebRowSetXmlWriter</code> object is not the writer
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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        stack = new java.util.Stack();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Writes the given <code>WebRowSet</code> object as an XML document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * using the given <code>java.io.OutputStream</code> object. The XML document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * will include the <code>WebRowSet</code> object's data, metadata, and
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>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Using stream is a faster way than using <code>java.io.Writer<code/>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * This method is called by the <code>XmlWriter</code> object that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * referenced in the calling <code>WebRowSet</code> object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * <code>xmlWriter</code> field.  The <code>XmlWriter.writeXML</code>
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
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param caller the <code>WebRowSet</code> object to be written; must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *        be a rowset for which this <code>WebRowSetXmlWriter</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *        is the writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @param oStream the <code>java.io.OutputStream</code> object to which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *        <code>caller</code> will be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @throws SQLException if a database access error occurs or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *            this <code>WebRowSetXmlWriter</code> object is not the writer
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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        stack = new java.util.Stack();
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");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            java.util.Map typeMap = caller.getTypeMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            if (typeMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                Iterator i = typeMap.keySet().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                Class c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                while (i.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    type = (String)i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    c = (Class)typeMap.get(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    propString("type", type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    propString("class", c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            endSection("map");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            propInteger("max-field-size", caller.getMaxFieldSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            propInteger("max-rows", caller.getMaxRows());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            propInteger("query-timeout", caller.getQueryTimeout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            propBoolean("read-only", caller.isReadOnly());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            int itype = caller.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            String strType = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            if(itype == 1003) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                strType = "ResultSet.TYPE_FORWARD_ONLY";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            } else if(itype == 1004) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                strType = "ResultSet.TYPE_SCROLL_INSENSITIVE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            } else if(itype == 1005) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                strType = "ResultSet.TYPE_SCROLL_SENSITIVE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            propString("rowset-type", strType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            propBoolean("show-deleted", caller.getShowDeleted());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            propString("table-name", caller.getTableName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            propString("url", caller.getUrl());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            beginSection("sync-provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            // Remove the string after "@xxxx"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            // before writing it to the xml file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            String strProviderInstance = (caller.getSyncProvider()).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            String strProvider = strProviderInstance.substring(0, (caller.getSyncProvider()).toString().indexOf("@"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            propString("sync-provider-name", strProvider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            propString("sync-provider-vendor", "Sun Microsystems Inc.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            propString("sync-provider-version", "1.0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            propInteger("sync-provider-grade", caller.getSyncProvider().getProviderGrade());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            propInteger("data-source-lock", caller.getSyncProvider().getDataSourceLock());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            endSection("sync-provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        } catch (SQLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        endSection("properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @exception SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    private void writeMetaData(WebRowSet caller) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        int columnCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        beginSection("metadata");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            ResultSetMetaData rsmd = caller.getMetaData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            columnCount = rsmd.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            propInteger("column-count", columnCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            for (int colIndex = 1; colIndex <= columnCount; colIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                beginSection("column-definition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                propInteger("column-index", colIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                propBoolean("auto-increment", rsmd.isAutoIncrement(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                propBoolean("case-sensitive", rsmd.isCaseSensitive(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                propBoolean("currency", rsmd.isCurrency(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                propInteger("nullable", rsmd.isNullable(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                propBoolean("signed", rsmd.isSigned(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                propBoolean("searchable", rsmd.isSearchable(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                propInteger("column-display-size",rsmd.getColumnDisplaySize(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                propString("column-label", rsmd.getColumnLabel(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                propString("column-name", rsmd.getColumnName(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                propString("schema-name", rsmd.getSchemaName(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                propInteger("column-precision", rsmd.getPrecision(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                propInteger("column-scale", rsmd.getScale(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                propString("table-name", rsmd.getTableName(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                propString("catalog-name", rsmd.getCatalogName(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                propInteger("column-type", rsmd.getColumnType(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                propString("column-type-name", rsmd.getColumnTypeName(colIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                endSection("column-definition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        } catch (SQLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        endSection("metadata");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @exception SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    private void writeData(WebRowSet caller) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        ResultSet rs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            ResultSetMetaData rsmd = caller.getMetaData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            int columnCount = rsmd.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            beginSection("data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            caller.beforeFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            caller.setShowDeleted(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            while (caller.next()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                if (caller.rowDeleted() && caller.rowInserted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    beginSection("modifyRow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                } else if (caller.rowDeleted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    beginSection("deleteRow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                } else if (caller.rowInserted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    beginSection("insertRow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    beginSection("currentRow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                for (i = 1; i <= columnCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    if (caller.columnUpdated(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                        rs = caller.getOriginalRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                        rs.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                        beginTag("columnValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                        writeValue(i, (RowSet)rs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                        endTag("columnValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                        beginTag("updateRow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                        writeValue(i, caller);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                        endTag("updateRow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                        beginTag("columnValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                        writeValue(i, caller);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                        endTag("columnValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                endSection(); // this is unchecked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            endSection("data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        } catch (SQLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    private void writeValue(int idx, RowSet caller) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            int type = caller.getMetaData().getColumnType(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                case java.sql.Types.BIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                case java.sql.Types.BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    boolean b = caller.getBoolean(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                        writeBoolean(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                case java.sql.Types.TINYINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                case java.sql.Types.SMALLINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    short s = caller.getShort(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                        writeShort(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                case java.sql.Types.INTEGER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    int i = caller.getInt(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                        writeInteger(caller.getInt(idx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                case java.sql.Types.BIGINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    long l = caller.getLong(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                        writeLong(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                case java.sql.Types.REAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                case java.sql.Types.FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    float f = caller.getFloat(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                        writeFloat(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                case java.sql.Types.DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    double d = caller.getDouble(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                        writeDouble(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                case java.sql.Types.NUMERIC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                case java.sql.Types.DECIMAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    writeBigDecimal(caller.getBigDecimal(idx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                case java.sql.Types.BINARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                case java.sql.Types.VARBINARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                case java.sql.Types.LONGVARBINARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                case java.sql.Types.DATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    java.sql.Date date = caller.getDate(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                        writeLong(date.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                case java.sql.Types.TIME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    java.sql.Time time = caller.getTime(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                        writeLong(time.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                case java.sql.Types.TIMESTAMP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    java.sql.Timestamp ts = caller.getTimestamp(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    if (caller.wasNull())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                        writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                        writeLong(ts.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                case java.sql.Types.CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                case java.sql.Types.VARCHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                case java.sql.Types.LONGVARCHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    writeStringData(caller.getString(idx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    System.out.println(resBundle.handleGetObject("wsrxmlwriter.notproper").toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    //Need to take care of BLOB, CLOB, Array, Ref here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        } catch (SQLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            throw new java.io.IOException(resBundle.handleGetObject("wrsxmlwriter.failedwrite").toString()+ ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * This begins a new tag with a indent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    private void beginSection(String tag) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        // store the current tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        setTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        writeIndent(stack.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        // write it out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        writer.write("<" + tag + ">\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * This closes a tag started by beginTag with a indent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    private void endSection(String tag) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        writeIndent(stack.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        String beginTag = getTag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if(beginTag.indexOf("webRowSet") != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            beginTag ="webRowSet";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (tag.equals(beginTag) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            // get the current tag and write it out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            writer.write("</" + beginTag + ">\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        writer.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    private void endSection() throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        writeIndent(stack.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        // get the current tag and write it out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        String beginTag = getTag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        writer.write("</" + beginTag + ">\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        writer.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    private void beginTag(String tag) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        // store the current tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        setTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        writeIndent(stack.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        // write tag out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        writer.write("<" + tag + ">");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    private void endTag(String tag) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        String beginTag = getTag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        if (tag.equals(beginTag)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            // get the current tag and write it out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            writer.write("</" + beginTag + ">\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        writer.flush();
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 emptyTag(String tag) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        // write an emptyTag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        writer.write("<" + 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 void setTag(String tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        // add the tag to stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        stack.push(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    private String getTag() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        return (String)stack.pop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    private void writeNull() throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        emptyTag("null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    private void writeStringData(String s) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        } else if (s.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            writeEmptyString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            s = processSpecialCharacters(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            writer.write(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    private void writeString(String s) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            writer.write(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        } else  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            writeNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    private void writeShort(short s) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        writer.write(Short.toString(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    private void writeLong(long l) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        writer.write(Long.toString(l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    private void writeInteger(int i) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        writer.write(Integer.toString(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    private void writeBoolean(boolean b) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        writer.write(new Boolean(b).toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    private void writeFloat(float f) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        writer.write(Float.toString(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    private void writeDouble(double d) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        writer.write(Double.toString(d));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    private void writeBigDecimal(java.math.BigDecimal bd) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        if (bd != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            writer.write(bd.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            emptyTag("null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    private void writeIndent(int tabs) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        // indent...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        for (int i = 1; i < tabs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            writer.write("  ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    private void propString(String tag, String s) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        beginTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        writeString(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        endTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    private void propInteger(String tag, int i) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        beginTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        writeInteger(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        endTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    private void propBoolean(String tag, boolean b) throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        beginTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        writeBoolean(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        endTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    private void writeEmptyString() throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        emptyTag("emptyString");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * Purely for code coverage purposes..
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    public boolean writeData(RowSetInternal caller) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * This function has been added for the processing of special characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * lik <,>,'," and & in the data to be serialized. These have to be taken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * of specifically or else there will be parsing error while trying to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * the contents of the XML file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    private String processSpecialCharacters(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        if(s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        char []charStr = s.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        String specialStr = new String();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        for(int i = 0; i < charStr.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            if(charStr[i] == '&') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                specialStr = specialStr.concat("&amp;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            } else if(charStr[i] == '<') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                specialStr = specialStr.concat("&lt;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            } else if(charStr[i] == '>') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                specialStr = specialStr.concat("&gt;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            } else if(charStr[i] == '\'') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                specialStr = specialStr.concat("&apos;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            } else if(charStr[i] == '\"') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                specialStr = specialStr.concat("&quot;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                specialStr = specialStr.concat(String.valueOf(charStr[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        s = specialStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
}