/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* An implementation of the <code>XmlWriter</code> interface, which writes a
* <code>WebRowSet</code> object to an output stream as an XML document.
*/
/**
* The <code>java.io.Writer</code> object to which this <code>WebRowSetXmlWriter</code>
* object will write when its <code>writeXML</code> method is called. The value
* for this field is set with the <code>java.io.Writer</code> object given
* as the second argument to the <code>writeXML</code> method.
*/
/**
* The <code>java.util.Stack</code> object that this <code>WebRowSetXmlWriter</code>
* object will use for storing the tags to be used for writing the calling
* <code>WebRowSet</code> object as an XML document.
*/
public WebRowSetXmlWriter() {
try {
} catch(IOException ioe) {
throw new RuntimeException(ioe);
}
}
/**
* Writes the given <code>WebRowSet</code> object as an XML document
* using the given <code>java.io.Writer</code> object. The XML document
* will include the <code>WebRowSet</code> object's data, metadata, and
* properties. If a data value has been updated, that information is also
* included.
* <P>
* This method is called by the <code>XmlWriter</code> object that is
* referenced in the calling <code>WebRowSet</code> object's
* <code>xmlWriter</code> field. The <code>XmlWriter.writeXML</code>
* method passes to this method the arguments that were supplied to it.
*
* @param caller the <code>WebRowSet</code> object to be written; must
* be a rowset for which this <code>WebRowSetXmlWriter</code> object
* is the writer
* @param wrt the <code>java.io.Writer</code> object to which
* <code>caller</code> will be written
* @exception SQLException if a database access error occurs or
* this <code>WebRowSetXmlWriter</code> object is not the writer
* for the given rowset
* @see XmlWriter#writeXML
*/
throws SQLException {
// create a new stack for tag checking.
}
/**
* Writes the given <code>WebRowSet</code> object as an XML document
* using the given <code>java.io.OutputStream</code> object. The XML document
* will include the <code>WebRowSet</code> object's data, metadata, and
* properties. If a data value has been updated, that information is also
* included.
* <P>
* Using stream is a faster way than using <code>java.io.Writer<code/>
*
* This method is called by the <code>XmlWriter</code> object that is
* referenced in the calling <code>WebRowSet</code> object's
* <code>xmlWriter</code> field. The <code>XmlWriter.writeXML</code>
* method passes to this method the arguments that were supplied to it.
*
* @param caller the <code>WebRowSet</code> object to be written; must
* be a rowset for which this <code>WebRowSetXmlWriter</code> object
* is the writer
* @param oStream the <code>java.io.OutputStream</code> object to which
* <code>caller</code> will be written
* @throws SQLException if a database access error occurs or
* this <code>WebRowSetXmlWriter</code> object is not the writer
* for the given rowset
* @see XmlWriter#writeXML
*/
throws SQLException {
// create a new stack for tag checking.
}
/**
*
*
* @exception SQLException if a database access error occurs
*/
try {
startHeader();
endHeader();
throw new SQLException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.ioex").toString(), ex.getMessage()));
}
}
setTag("webRowSet");
writer.write("<webRowSet xmlns=\"http://java.sun.com/xml/ns/jdbc\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
writer.write("xsi:schemaLocation=\"http://java.sun.com/xml/ns/jdbc http://java.sun.com/xml/ns/jdbc/webrowset.xsd\">\n");
}
endTag("webRowSet");
}
/**
*
*
* @exception SQLException if a database access error occurs
*/
beginSection("properties");
try {
propBoolean("escape-processing",
try {
} catch(SQLException sqle) {
// it may be the case that fetch direction has not been set
// fetchDir == 0
// in that case it will throw a SQLException.
// To avoid that catch it here
}
propInteger("isolation-level",
beginSection("key-columns");
endSection("key-columns");
//Changed to beginSection and endSection for maps for proper indentation
beginSection("map");
Class c;
while (i.hasNext()) {
}
}
endSection("map");
if(itype == 1003) {
strType = "ResultSet.TYPE_FORWARD_ONLY";
} else if(itype == 1004) {
strType = "ResultSet.TYPE_SCROLL_INSENSITIVE";
} else if(itype == 1005) {
strType = "ResultSet.TYPE_SCROLL_SENSITIVE";
}
beginSection("sync-provider");
// Remove the string after "@xxxx"
// before writing it to the xml file.
String strProvider = strProviderInstance.substring(0, (caller.getSyncProvider()).toString().indexOf("@"));
endSection("sync-provider");
} catch (SQLException ex) {
throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
}
endSection("properties");
}
/**
*
*
* @exception SQLException if a database access error occurs
*/
int columnCount;
beginSection("metadata");
try {
beginSection("column-definition");
endSection("column-definition");
}
} catch (SQLException ex) {
throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
}
endSection("metadata");
}
/**
*
*
* @exception SQLException if a database access error occurs
*/
try {
int i;
beginSection("data");
caller.setShowDeleted(true);
beginSection("modifyRow");
} else if (caller.rowDeleted()) {
beginSection("deleteRow");
} else if (caller.rowInserted()) {
beginSection("insertRow");
} else {
beginSection("currentRow");
}
for (i = 1; i <= columnCount; i++) {
if (caller.columnUpdated(i)) {
beginTag("columnValue");
endTag("columnValue");
beginTag("updateRow");
writeValue(i, caller);
endTag("updateRow");
} else {
beginTag("columnValue");
writeValue(i, caller);
endTag("columnValue");
}
}
endSection(); // this is unchecked
}
endSection("data");
} catch (SQLException ex) {
throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
}
}
try {
switch (type) {
writeNull();
else
writeBoolean(b);
break;
writeNull();
else
writeShort(s);
break;
writeNull();
else
writeInteger(i);
break;
writeNull();
else
writeLong(l);
break;
writeNull();
else
writeFloat(f);
break;
writeNull();
else
writeDouble(d);
break;
break;
break;
writeNull();
else
break;
writeNull();
else
break;
writeNull();
else
break;
break;
default:
//Need to take care of BLOB, CLOB, Array, Ref here
}
} catch (SQLException ex) {
throw new java.io.IOException(resBundle.handleGetObject("wrsxmlwriter.failedwrite").toString()+ ex.getMessage());
}
}
/*
* This begins a new tag with a indent
*
*/
// store the current tag
// write it out
}
/*
* This closes a tag started by beginTag with a indent
*
*/
beginTag ="webRowSet";
}
// get the current tag and write it out
} else {
;
}
}
// get the current tag and write it out
}
// store the current tag
// write tag out
}
// get the current tag and write it out
} else {
;
}
}
// write an emptyTag
}
// add the tag to stack
}
}
emptyTag("null");
}
if (s == null) {
writeNull();
} else if (s.equals("")) {
} else {
s = processSpecialCharacters(s);
}
}
if (s != null) {
} else {
writeNull();
}
}
}
}
}
}
}
}
else
emptyTag("null");
}
// indent...
for (int i = 1; i < tabs; i++) {
}
}
writeString(s);
}
writeInteger(i);
}
writeBoolean(b);
}
emptyTag("emptyString");
}
/**
* Purely for code coverage purposes..
*/
return false;
}
/**
* This function has been added for the processing of special characters
* lik <,>,'," and & in the data to be serialized. These have to be taken
* of specifically or else there will be parsing error while trying to read
* the contents of the XML file.
**/
if(s == null) {
return null;
}
char []charStr = s.toCharArray();
if(charStr[i] == '&') {
} else if(charStr[i] == '<') {
} else if(charStr[i] == '>') {
} else if(charStr[i] == '\'') {
} else if(charStr[i] == '\"') {
} else {
}
}
s = specialStr;
return s;
}
/**
* This method re populates the resBundle
* during the deserialization process
*
*/
// Default state initialization happens here
// Initialization of transient Res Bundle happens here .
try {
} catch(IOException ioe) {
throw new RuntimeException(ioe);
}
}
}