Package de.danet.an.workflow.tools.xmlrpc

Source Code of de.danet.an.workflow.tools.xmlrpc.XMLParser

/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2006 Danet GmbH (www.danet.de), BU BTS.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* $Id: XMLParser.java 2364 2007-04-22 16:15:13Z mlipp $
*
* $Log$
*/
package de.danet.an.workflow.tools.xmlrpc;

import javax.xml.transform.Templates;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.parser.TypeParser;
import org.apache.xmlrpc.serializer.TypeSerializer;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.XMLFilterImpl;

import de.danet.an.util.sax.BodyFilter;
import de.danet.an.workflow.api.SAXEventBuffer;
import de.danet.an.workflow.util.SAXEventBufferImpl;

/**
* This class provides a serializer for XML passes in a SAX event buffer.
*
* @author mnl
*
*/
public class XMLParser extends XMLFilterImpl implements TypeParser {

    private static final org.apache.commons.logging.Log logger
        = org.apache.commons.logging.LogFactory.getLog(XmlRpcTool.class);

    private SAXTransformerFactory transformerFactory = null;
    private Templates templates = null;
    private ContentHandler handler = null;
    private SAXEventBufferImpl result = null;
   
    /**
     * Create a new instance with all attributes initialized
     * to defaults or the given values.
     *
     * @param transformerFactory the transformer factory to use
     * @param templates the templates to use
     */
    public XMLParser
        (SAXTransformerFactory transformerFactory, Templates templates) {
        this.transformerFactory = transformerFactory;
        this.templates = templates;
       
        // Prepare result chain
        result = new SAXEventBufferImpl ();
        if (templates == null) {
            setContentHandler(result);
        } else {
            try {
                TransformerHandler th
                    = transformerFactory.newTransformerHandler(templates);
                // XML header is output despite xsl:output settings
                th.setResult(new SAXResult(new BodyFilter(result)));
                setContentHandler(th);
            } catch (TransformerConfigurationException e) {
                logger.error ("Cannot create transformer: " + e.getMessage(), e);
                throw (IllegalStateException)
                    new IllegalStateException(e.getMessage()).initCause(e);
            }
        }
    }

    /* (non-Javadoc)
     * Comment copied from interface or superclass.
     */
    public Object getResult() throws XmlRpcException {
        return result;
    }

}
TOP

Related Classes of de.danet.an.workflow.tools.xmlrpc.XMLParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.