![JAR search and dependency download from the Maven repository](/logo.png)
net.sf.xolite.transform.XMLEventParserResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xo-lite Show documentation
Show all versions of xo-lite Show documentation
This project provides a lightweight framework to
serialize/deserialize (or marshall/unmarshall) java objects into
XML. The implementation is based on standard SAX (Simple Api for
Xml) but it follows a original approach based on the strong data
encapsulation paradigm of Object Oriented (OO)
programming.
The newest version!
/*-------------------------------------------------------------------------
Copyright 2012 Olivier Berlanger
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 net.sf.xolite.transform;
import javax.xml.transform.sax.SAXResult;
import net.sf.xolite.XMLObjectFactory;
import net.sf.xolite.XMLParseException;
import net.sf.xolite.XMLSerializable;
import net.sf.xolite.sax.SaxXMLEventParser;
import net.sf.xolite.utils.RootHolder;
import org.xml.sax.XMLReader;
/**
* Implementation of a XML transformation result that will internally consume the event sent to it to build a XMLSerializable
* object. This object uses internally a SaxXMLEventParser to interpret the events coming out the XSL transformation.
*
* @author Olivier Berlanger
*/
public class XMLEventParserResult extends SAXResult {
private SaxXMLEventParser parser;
private XMLSerializable root;
private boolean useRootHolder;
public XMLEventParserResult() {
this(new RootHolder());
useRootHolder = true;
}
public XMLEventParserResult(XMLSerializable rootObject) {
if (rootObject == null) throw new IllegalArgumentException("Root XMLSerializable object cannot be null");
root = rootObject;
parser = new SaxXMLEventParser((XMLReader) null);
setHandler(parser.initForExternalRead(root));
}
public void setXmlObjectFactory(XMLObjectFactory factory) {
parser.setFactory(factory);
}
public XMLObjectFactory getXmlObjectFactory() throws XMLParseException {
return parser.getFactory();
}
public XMLSerializable getParsedObject() {
if (useRootHolder) return ((RootHolder) root).getRoot();
return root;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy