0N/A/*
2741N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.rowset;
0N/A
0N/Aimport java.sql.*;
0N/Aimport javax.sql.*;
0N/Aimport java.io.*;
0N/Aimport java.math.*;
0N/Aimport java.util.*;
0N/Aimport java.text.*;
0N/A
0N/Aimport org.xml.sax.*;
0N/A
0N/Aimport javax.sql.rowset.*;
0N/Aimport javax.sql.rowset.spi.*;
0N/A
0N/Aimport com.sun.rowset.providers.*;
0N/Aimport com.sun.rowset.internal.*;
0N/A
0N/A/**
0N/A * The standard implementation of the <code>WebRowSet</code> interface. See the interface
0N/A * defintion for full behaviour and implementation requirements.
0N/A *
0N/A * @author Jonathan Bruce, Amit Handa
0N/A */
0N/Apublic class WebRowSetImpl extends CachedRowSetImpl implements WebRowSet {
0N/A
0N/A /**
0N/A * The <code>WebRowSetXmlReader</code> object that this
0N/A * <code>WebRowSet</code> object will call when the method
0N/A * <code>WebRowSet.readXml</code> is invoked.
0N/A */
0N/A private WebRowSetXmlReader xmlReader;
0N/A
0N/A /**
0N/A * The <code>WebRowSetXmlWriter</code> object that this
0N/A * <code>WebRowSet</code> object will call when the method
0N/A * <code>WebRowSet.writeXml</code> is invoked.
0N/A */
0N/A private WebRowSetXmlWriter xmlWriter;
0N/A
0N/A /* This stores the cursor position prior to calling the writeXML.
0N/A * This variable is used after the write to restore the position
0N/A * to the point where the writeXml was called.
0N/A */
0N/A private int curPosBfrWrite;
0N/A
0N/A private SyncProvider provider;
0N/A
0N/A /**
0N/A * Constructs a new <code>WebRowSet</code> object initialized with the
0N/A * default values for a <code>CachedRowSet</code> object instance. This
0N/A * provides the <code>RIOptimistic</code> provider to deliver
0N/A * synchronization capabilities to relational datastores and a default
0N/A * <code>WebRowSetXmlReader</code> object and a default
0N/A * <code>WebRowSetXmlWriter</code> object to enable XML output
0N/A * capabilities.
0N/A *
0N/A * @throws SQLException if an error occurs in configuring the default
0N/A * synchronization providers for relational and XML providers.
0N/A */
0N/A public WebRowSetImpl() throws SQLException {
0N/A super();
0N/A
0N/A // %%%
0N/A // Needs to use to SPI XmlReader,XmlWriters
0N/A //
0N/A xmlReader = new WebRowSetXmlReader();
0N/A xmlWriter = new WebRowSetXmlWriter();
0N/A }
0N/A
0N/A /**
0N/A * Constructs a new <code>WebRowSet</code> object initialized with the the
0N/A * synchronization SPI provider properties as specified in the <code>Hashtable</code>. If
0N/A * this hashtable is empty or is <code>null</code> the default constructor is invoked.
0N/A *
0N/A * @throws SQLException if an error occurs in configuring the specified
0N/A * synchronization providers for the relational and XML providers; or
0N/A * if the Hashtanle is null
0N/A */
0N/A public WebRowSetImpl(Hashtable env) throws SQLException {
0N/A
2741N/A try {
2741N/A resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
2741N/A } catch(IOException ioe) {
2741N/A throw new RuntimeException(ioe);
2741N/A }
2741N/A
0N/A if ( env == null) {
0N/A throw new SQLException(resBundle.handleGetObject("webrowsetimpl.nullhash").toString());
0N/A }
0N/A
0N/A String providerName =
0N/A (String)env.get(javax.sql.rowset.spi.SyncFactory.ROWSET_SYNC_PROVIDER);
0N/A
0N/A // set the Reader, this maybe overridden latter
0N/A provider = (SyncProvider)SyncFactory.getInstance(providerName);
0N/A
0N/A // xmlReader = provider.getRowSetReader();
0N/A // xmlWriter = provider.getRowSetWriter();
0N/A }
0N/A
0N/A /**
0N/A * Populates this <code>WebRowSet</code> object with the
0N/A * data in the given <code>ResultSet</code> object and writes itself
0N/A * to the given <code>java.io.Writer</code> object in XML format.
0N/A * This includes the rowset's data, properties, and metadata.
0N/A *
0N/A * @throws SQLException if an error occurs writing out the rowset
0N/A * contents to XML
0N/A */
0N/A public void writeXml(ResultSet rs, java.io.Writer writer)
0N/A throws SQLException {
0N/A // WebRowSetImpl wrs = new WebRowSetImpl();
0N/A this.populate(rs);
0N/A
0N/A // Store the cursor position before writing
0N/A curPosBfrWrite = this.getRow();
0N/A
0N/A this.writeXml(writer);
0N/A }
0N/A
0N/A /**
0N/A * Writes this <code>WebRowSet</code> object to the given
0N/A * <code>java.io.Writer</code> object in XML format. This
0N/A * includes the rowset's data, properties, and metadata.
0N/A *
0N/A * @throws SQLException if an error occurs writing out the rowset
0N/A * contents to XML
0N/A */
0N/A public void writeXml(java.io.Writer writer) throws SQLException {
0N/A // %%%
0N/A // This will change to a XmlReader, which over-rides the default
0N/A // Xml that is used when a WRS is instantiated.
0N/A // WebRowSetXmlWriter xmlWriter = getXmlWriter();
0N/A if (xmlWriter != null) {
0N/A
0N/A // Store the cursor position before writing
0N/A curPosBfrWrite = this.getRow();
0N/A
0N/A xmlWriter.writeXML(this, writer);
0N/A } else {
0N/A throw new SQLException(resBundle.handleGetObject("webrowsetimpl.invalidwr").toString());
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Reads this <code>WebRowSet</code> object in its XML format.
0N/A *
0N/A * @throws SQLException if a database access error occurs
0N/A */
0N/A public void readXml(java.io.Reader reader) throws SQLException {
0N/A // %%%
0N/A // This will change to a XmlReader, which over-rides the default
0N/A // Xml that is used when a WRS is instantiated.
0N/A //WebRowSetXmlReader xmlReader = getXmlReader();
0N/A try {
0N/A if (reader != null) {
0N/A xmlReader.readXML(this, reader);
0N/A
0N/A // Position is before the first row
0N/A // The cursor position is to be stored while serializng
0N/A // and deserializing the WebRowSet Object.
0N/A if(curPosBfrWrite == 0) {
0N/A this.beforeFirst();
0N/A }
0N/A
0N/A // Return the position back to place prior to callin writeXml
0N/A else {
0N/A this.absolute(curPosBfrWrite);
0N/A }
0N/A
0N/A } else {
0N/A throw new SQLException(resBundle.handleGetObject("webrowsetimpl.invalidrd").toString());
0N/A }
0N/A } catch (Exception e) {
0N/A throw new SQLException(e.getMessage());
0N/A }
0N/A }
0N/A
0N/A // Stream based methods
0N/A /**
0N/A * Reads a stream based XML input to populate this <code>WebRowSet</code>
0N/A * object.
0N/A *
0N/A * @throws SQLException if a data source access error occurs
0N/A * @throws IOException if a IO exception occurs
0N/A */
0N/A public void readXml(java.io.InputStream iStream) throws SQLException, IOException {
0N/A if (iStream != null) {
0N/A xmlReader.readXML(this, iStream);
0N/A
0N/A // Position is before the first row
0N/A // The cursor position is to be stored while serializng
0N/A // and deserializing the WebRowSet Object.
0N/A if(curPosBfrWrite == 0) {
0N/A this.beforeFirst();
0N/A }
0N/A
0N/A // Return the position back to place prior to callin writeXml
0N/A else {
0N/A this.absolute(curPosBfrWrite);
0N/A }
0N/A
0N/A } else {
0N/A throw new SQLException(resBundle.handleGetObject("webrowsetimpl.invalidrd").toString());
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Writes this <code>WebRowSet</code> object to the given <code> OutputStream</code>
0N/A * object in XML format.
0N/A * Creates an an output stream of the internal state and contents of a
0N/A * <code>WebRowSet</code> for XML proceessing
0N/A *
0N/A * @throws SQLException if a datasource access error occurs
0N/A * @throws IOException if an IO exception occurs
0N/A */
0N/A public void writeXml(java.io.OutputStream oStream) throws SQLException, IOException {
0N/A if (xmlWriter != null) {
0N/A
0N/A // Store the cursor position before writing
0N/A curPosBfrWrite = this.getRow();
0N/A
0N/A xmlWriter.writeXML(this, oStream);
0N/A } else {
0N/A throw new SQLException(resBundle.handleGetObject("webrowsetimpl.invalidwr").toString());
0N/A }
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Populates this <code>WebRowSet</code> object with the
0N/A * data in the given <code>ResultSet</code> object and writes itself
0N/A * to the given <code>java.io.OutputStream</code> object in XML format.
0N/A * This includes the rowset's data, properties, and metadata.
0N/A *
0N/A * @throws SQLException if a datasource access error occurs
0N/A * @throws IOException if an IO exception occurs
0N/A */
0N/A public void writeXml(ResultSet rs, java.io.OutputStream oStream) throws SQLException, IOException {
0N/A this.populate(rs);
0N/A
0N/A // Store the cursor position before writing
0N/A curPosBfrWrite = this.getRow();
0N/A
0N/A this.writeXml(oStream);
0N/A }
2741N/A
2741N/A /**
2741N/A * This method re populates the resBundle
2741N/A * during the deserialization process
2741N/A *
2741N/A */
2741N/A private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
2741N/A // Default state initialization happens here
2741N/A ois.defaultReadObject();
2741N/A // Initialization of transient Res Bundle happens here .
2741N/A try {
2741N/A resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
2741N/A } catch(IOException ioe) {
2741N/A throw new RuntimeException(ioe);
2741N/A }
2741N/A
2741N/A }
2741N/A
2741N/A static final long serialVersionUID = -8771775154092422943L;
0N/A}