public Row(String timeStamp, String id, String schemaName, String tableName, String sqlOperation){
this.timeStamp = timeStamp;
this.id = id;
if(schemaName != null){
this.schemaName = schemaName;
}
this.tableName = tableName;
this.sqlOperation = sqlOperation;
}
}
RowSet.java
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
import courseExample.Row;
import courseExample.ReplicatorHome;
import courseExample.Replicator;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.io.*;
import java.util.ArrayList;
import java.util.Hashtable;
public class RowSet extends DefaultHandler implements ContentHandler, DTDHandler, ErrorHandler {
protected String timeStamp = null;
protected boolean goodDTD = false;
protected boolean doKey = false;
protected String currentColumn = null;
protected PrintWriter fOut;
protected Locator locator = null;
protected Row currentRow = null;
protected String currentCharacters = null;
public ArrayList rows = new ArrayList();
public void setOutput(OutputStream stream, String encoding) throws UnsupportedEncodingException {
if (encoding == null) {
encoding = "UTF8";
}
fOut = new PrintWriter(new OutputStreamWriter(stream, encoding), true);
}
public void setOutput(Writer writer) {
fOut = writer instanceof PrintWriter ? (PrintWriter)writer : new PrintWriter(writer, true);
}
RowSet() throws UnsupportedEncodingException {
setOutput(System.out, System.getProperty("file.encoding"));
}
//SAX2 ContentHandler Methods
public void setDocumentLocator(Locator locator) {
this.locator = locator;
}
// public void skippedEntity(java.lang.String name) throws SAXException {
// fOut.println("Пропущено: "+name);
// }
public void startDocument() throws SAXException {
// fOut.println("document");
goodDTD = true;
}
public void startElement(String uri, String localName, String qname, Attributes attributes) throws SAXException {
// fOut.println(localName);
if(localName.equals("rowset")){
timeStamp = attributes.getValue(0);
} else if(localName.equals("row")){
// Новая строка
String id = null;
String schemaName = null;
String tableName = null;
String sqlOperation = null;
for(int i = 0; i < attributes.getLength(); i++ ){
String temp = attributes.getLocalName(i);
if( temp.equals("id")){
id = attributes.getValue(i);
} else if( temp.equals("schemaName")){
schemaName = attributes.getValue(i);
} else if( temp.equals("tableName")){
tableName = attributes.getValue(i);
} else if( temp.equals("sqlOperation")){
sqlOperation = attributes.getValue(i);
}
}
currentRow = new Row(timeStamp, id, schemaName, tableName, sqlOperation);
} else if(localName.equals("key")){
// Новый ключ для операций update или delete
doKey = true;
} else if(localName.equals("column-value")){
// Новое значение ключа поиска или столбца данных
for(int i = 0; i < attributes.getLength(); i++ ){
String temp = attributes.getLocalName(i);
String name = null;
if(temp.equals("columnName")){
currentColumn = attributes.getValue(i);
} else if(temp.equals("sqlType")){
if(doKey){
currentRow.keyTypes.put(currentColumn, attributes.getValue(i));
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.