0N/A/*
2802N/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.providers;
0N/A
0N/Aimport com.sun.rowset.JdbcRowSetResourceBundle;
0N/Aimport java.io.IOException;
0N/Aimport java.sql.*;
0N/Aimport javax.sql.*;
0N/A
0N/Aimport javax.sql.rowset.spi.*;
0N/A
0N/A/**
0N/A * A reference implementation of a JDBC RowSet synchronization provider
0N/A * with the ability to read and write rowsets in well formed XML using the
0N/A * standard WebRowSet schema.
0N/A *
0N/A * <h3>1.0 Background</h3>
0N/A * This synchronization provider is registered with the
0N/A * <code>SyncFactory</code> by default as the
0N/A * <code>com.sun.rowset.providers.RIXMLProvider</code>.
0N/A * <P>
0N/A * A <code>WebRowSet</code> object uses an <code>RIXMLProvider</code> implementation
0N/A * to read an XML data source or to write itself in XML format using the
0N/A * <code>WebRowSet</code> XML schema definition available at
0N/A * <pre>
0N/A * <a href="http://java.sun.com/xml/ns/jdbc/webrowset.xsd">http://java.sun.com/xml/ns/jdbc/webrowset.xsd</a>
0N/A * </pre>
0N/A * The <code>RIXMLProvider</code> implementation has a synchronization level of
0N/A * GRADE_NONE, which means that it does no checking at all for conflicts. It
0N/A * simply writes a <code>WebRowSet</code> object to a file.
0N/A * <h3>2.0 Usage</h3>
0N/A * A <code>WebRowSet</code> implementation is created with an <code>RIXMLProvider</code>
0N/A * by default.
0N/A * <pre>
0N/A * WebRowSet wrs = new FooWebRowSetImpl();
0N/A * </pre>
0N/A * The <code>SyncFactory</code> always provides an instance of
0N/A * <code>RIOptimisticProvider</code> when no provider is specified,
0N/A * but the implementation of the default constructor for <code>WebRowSet</code> sets the
0N/A * provider to be the <code>RIXMLProvider</code> implementation. Therefore,
0N/A * the following line of code is executed behind the scenes as part of the
0N/A * implementation of the default constructor.
0N/A * <pre>
0N/A * wrs.setSyncProvider("com.sun.rowset.providers.RIXMLProvider");
0N/A * </pre>
0N/A * See the standard <code>RowSet</code> reference implementations in the
0N/A * <code>com.sun.rowset</code> package for more details.
0N/A *
0N/A * @author Jonathan Bruce
0N/A * @see javax.sql.rowset.spi.SyncProvider
0N/A * @see javax.sql.rowset.spi.SyncProviderException
0N/A * @see javax.sql.rowset.spi.SyncFactory
0N/A * @see javax.sql.rowset.spi.SyncFactoryException
0N/A */
0N/Apublic final class RIXMLProvider extends SyncProvider {
0N/A
0N/A /**
0N/A * The unique provider identifier.
0N/A */
0N/A private String providerID = "com.sun.rowset.providers.RIXMLProvider";
0N/A
0N/A /**
0N/A * The vendor name of this SyncProvider implementation.
0N/A */
2802N/A private String vendorName = "Oracle Corporation";
0N/A
0N/A /**
0N/A * The version number of this SyncProvider implementation.
0N/A */
0N/A private String versionNumber = "1.0";
0N/A
0N/A private JdbcRowSetResourceBundle resBundle;
0N/A
0N/A private XmlReader xmlReader;
0N/A private XmlWriter xmlWriter;
0N/A
0N/A /**
0N/A * This provider is available to all JDBC <code>RowSet</code> implementations as the
0N/A * default persistence provider.
0N/A */
0N/A public RIXMLProvider() {
0N/A providerID = this.getClass().getName();
0N/A try {
0N/A resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
0N/A } catch(IOException ioe) {
0N/A throw new RuntimeException(ioe);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>"javax.sql.rowset.providers.RIXMLProvider"</code>, which is
0N/A * the fully qualified class name of this provider implementation.
0N/A *
0N/A * @return a <code>String</code> object with the fully specified class name of
0N/A * this <code>RIOptimisticProvider</code> implementation
0N/A */
0N/A public String getProviderID() {
0N/A return providerID;
0N/A }
0N/A
0N/A // additional methods that sit on top of reader/writer methods back to
0N/A // original datasource. Allow XML state to be written out and in
0N/A
0N/A /**
0N/A * Sets this <code>WebRowSet</code> object's reader to the given
0N/A * <code>XmlReader</code> object.
0N/A *
0N/A * @throws SQLException if a database access error occurs
0N/A */
0N/A public void setXmlReader(XmlReader reader) throws SQLException {
0N/A xmlReader = reader;
0N/A }
0N/A
0N/A /**
0N/A * Sets this <code>WebRowSet</code> object's writer to the given
0N/A * <code>XmlWriter</code> object.
0N/A *
0N/A * @throws SQLException if a database access error occurs
0N/A */
0N/A public void setXmlWriter(XmlWriter writer) throws SQLException {
0N/A xmlWriter = writer;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the reader that this <code>WebRowSet</code> object
0N/A * will call when its <code>readXml</code> method is called.
0N/A *
0N/A * @return the <code>XmlReader</code> object for this SyncProvider
0N/A * @throws SQLException if a database access error occurs
0N/A */
0N/A public XmlReader getXmlReader() throws SQLException {
0N/A return xmlReader;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the writer that this <code>WebRowSet</code> object
0N/A * will call when its <code>writeXml</code> method is called.
0N/A *
0N/A * @return the <code>XmlWriter</code> for this SyncProvider
0N/A * @throws SQLException if a database access error occurs
0N/A */
0N/A public XmlWriter getXmlWriter() throws SQLException {
0N/A return xmlWriter;
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>SyncProvider</code> grade of syncrhonization that
0N/A * <code>RowSet</code> object instances can expect when using this
0N/A * implementation. As this implementation provides no synchonization
0N/A * facilities to the XML data source, the lowest grade is returned.
0N/A *
0N/A * @return the <code>SyncProvider</code> syncronization grade of this
0N/A * provider; must be one of the following constants:
0N/A * <PRE>
0N/A * SyncProvider.GRADE_NONE,
0N/A * SyncProvider.GRADE_MODIFIED_AT_COMMIT,
0N/A * SyncProvider.GRADE_CHECK_ALL_AT_COMMIT,
0N/A * SyncProvider.GRADE_LOCK_WHEN_MODIFIED,
0N/A * SyncProvider.GRADE_LOCK_WHEN_LOADED
0N/A * </PRE>
0N/A *
0N/A */
0N/A public int getProviderGrade() {
0N/A return SyncProvider.GRADE_NONE;
0N/A }
0N/A
0N/A /**
0N/A * Returns the default UPDATABLE_VIEW behavior of this reader
0N/A *
0N/A */
0N/A public int supportsUpdatableView() {
0N/A return SyncProvider.NONUPDATABLE_VIEW_SYNC;
0N/A }
0N/A
0N/A /**
0N/A * Returns the default DATASOURCE_LOCK behavior of this reader
0N/A */
0N/A public int getDataSourceLock() throws SyncProviderException {
0N/A return SyncProvider.DATASOURCE_NO_LOCK;
0N/A }
0N/A
0N/A /**
0N/A * Throws an unsupported operation exception as this method does
0N/A * function with non-locking XML data sources.
0N/A */
0N/A public void setDataSourceLock(int lock) throws SyncProviderException {
0N/A throw new UnsupportedOperationException(resBundle.handleGetObject("rixml.unsupp").toString());
0N/A }
0N/A
0N/A /**
0N/A * Returns a null object as RowSetWriters are not returned by this SyncProvider
0N/A */
0N/A public RowSetWriter getRowSetWriter() {
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns a null object as RowSetWriter objects are not returned by this
0N/A * SyncProvider
0N/A */
0N/A public RowSetReader getRowSetReader() {
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns the release version ID of the Reference Implementation Optimistic
0N/A * Synchronization Provider.
0N/A *
0N/A * @return the <code>String</code> detailing the version number of this SyncProvider
0N/A */
0N/A public String getVersion() {
0N/A return this.versionNumber;
0N/A }
0N/A
0N/A /**
0N/A * Returns the vendor name of the Reference Implemntation Optimistic
0N/A * Syncchronication Provider
0N/A *
0N/A * @return the <code>String</code> detailing the vendor name of this
0N/A * SyncProvider
0N/A */
0N/A public String getVendor() {
0N/A return this.vendorName;
0N/A }
0N/A}