[Major] Removed redundant XmlPersistenceStreamWriter

- Now SaxParser simply writes to XMLStreamWriter
This commit is contained in:
Robert von Burg 2015-07-08 08:00:14 +02:00
parent f72ff76b40
commit 6659b90b83
5 changed files with 9 additions and 96 deletions

View File

@ -77,10 +77,9 @@ public class FileIo {
writer.writeStartDocument(DEFAULT_ENCODING, DEFAULT_XML_VERSION);
// then delegate object writing to caller
XmlPersistenceStreamWriter xmlWriter = new XmlPersistenceStreamWriter(writer);
SaxParser<T> saxParser = ctx.getParserFactor().getSaxParser();
saxParser.setObject(ctx.getObject());
saxParser.write(xmlWriter);
saxParser.write(writer);
// and now end
writer.writeEndDocument();

View File

@ -16,6 +16,7 @@
package ch.eitchnet.xmlpers.api;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.xml.sax.helpers.DefaultHandler;
@ -27,5 +28,5 @@ public interface SaxParser<T> {
public DefaultHandler getDefaultHandler();
public void write(XmlPersistenceStreamWriter xmlWriter) throws XMLStreamException;
public void write(XMLStreamWriter xmlWriter) throws XMLStreamException;
}

View File

@ -1,88 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.eitchnet.xmlpers.api;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class XmlPersistenceStreamWriter {
private XMLStreamWriter writer;
public XmlPersistenceStreamWriter(XMLStreamWriter writer) {
this.writer = writer;
}
/**
* @param localName
* @throws XMLStreamException
* @see javax.xml.stream.XMLStreamWriter#writeEmptyElement(java.lang.String)
*/
public void writeEmptyElement(String localName) throws XMLStreamException {
this.writer.writeEmptyElement(localName);
}
/**
* @param localName
* @throws XMLStreamException
* @see javax.xml.stream.XMLStreamWriter#writeStartElement(java.lang.String)
*/
public void writeElement(String localName) throws XMLStreamException {
this.writer.writeStartElement(localName);
}
/**
* <b>Note:</b> Don't call this method to close an element written by {@link #writeEmptyElement(String)}
*
* @throws XMLStreamException
* @see javax.xml.stream.XMLStreamWriter#writeEndElement()
*/
public void endElement() throws XMLStreamException {
this.writer.writeEndElement();
}
/**
* @param localName
* @param value
* @throws XMLStreamException
* @see javax.xml.stream.XMLStreamWriter#writeAttribute(java.lang.String, java.lang.String)
*/
public void writeAttribute(String localName, String value) throws XMLStreamException {
this.writer.writeAttribute(localName, value);
}
/**
* @param data
* @throws XMLStreamException
* @see javax.xml.stream.XMLStreamWriter#writeCData(java.lang.String)
*/
public void writeCData(String data) throws XMLStreamException {
this.writer.writeCData(data);
}
/**
* @param text
* @throws XMLStreamException
* @see javax.xml.stream.XMLStreamWriter#writeCharacters(java.lang.String)
*/
public void writeCharacters(String text) throws XMLStreamException {
this.writer.writeCharacters(text);
}
}

View File

@ -16,13 +16,13 @@
package ch.eitchnet.xmlpers.test.impl;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import ch.eitchnet.xmlpers.api.SaxParser;
import ch.eitchnet.xmlpers.api.XmlPersistenceStreamWriter;
import ch.eitchnet.xmlpers.test.model.Book;
/**
@ -51,7 +51,7 @@ public class BookSaxParser extends DefaultHandler implements SaxParser<Book> {
@SuppressWarnings("nls")
@Override
public void write(XmlPersistenceStreamWriter writer) throws XMLStreamException {
public void write(XMLStreamWriter writer) throws XMLStreamException {
writer.writeEmptyElement("Book");
writer.writeAttribute("id", Long.toString(this.book.getId()));

View File

@ -16,13 +16,13 @@
package ch.eitchnet.xmlpers.test.impl;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import ch.eitchnet.xmlpers.api.SaxParser;
import ch.eitchnet.xmlpers.api.XmlPersistenceStreamWriter;
import ch.eitchnet.xmlpers.test.model.MyModel;
import ch.eitchnet.xmlpers.test.model.MyParameter;
@ -47,9 +47,9 @@ class MyModelSaxParser extends DefaultHandler implements SaxParser<MyModel> {
@SuppressWarnings("nls")
@Override
public void write(XmlPersistenceStreamWriter writer) throws XMLStreamException {
public void write(XMLStreamWriter writer) throws XMLStreamException {
writer.writeElement("Resource");
writer.writeStartElement("Resource");
writer.writeAttribute("id", this.resource.getId());
writer.writeAttribute("name", this.resource.getName());
writer.writeAttribute("type", this.resource.getType());
@ -61,6 +61,7 @@ class MyModelSaxParser extends DefaultHandler implements SaxParser<MyModel> {
writer.writeAttribute("type", param.getType());
writer.writeAttribute("value", param.getValue());
}
writer.writeEndElement();
}
@SuppressWarnings("nls")