All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.drools.xml.XmlPackageReader Maven / Gradle / Ivy

There is a newer version: 10.0.0
Show newest version
package org.drools.xml;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;

import javax.xml.parsers.SAXParser;

import org.drools.lang.descr.PackageDescr;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;


public class XmlPackageReader {
    private ExtensibleXmlParser parser;

    private PackageDescr        packageDescr;

    public XmlPackageReader(final SemanticModules modules) {
        this( modules, null );
    }

    public XmlPackageReader(final SemanticModules modules, final SAXParser parser) {
        if ( parser == null ) {
            this.parser = new ExtensibleXmlParser();
        } else {
            this.parser = new ExtensibleXmlParser( parser );
        }      
        this.parser.setSemanticModules( modules );
    }
    
    public ExtensibleXmlParser getParser() {
        return this.parser;
    }

    /**
     * Read a RuleSet from a Reader.
     *
     * @param reader
     *            The reader containing the rule-set.
     *
     * @return The rule-set.
     */
    public PackageDescr read(final Reader reader) throws SAXException,
                                                 IOException {
        this.packageDescr = (PackageDescr) this.parser.read( reader );
        return this.packageDescr;
    }

    /**
     * Read a RuleSet from an InputStream.
     *
     * @param inputStream
     *            The input-stream containing the rule-set.
     *
     * @return The rule-set.
     */
    public PackageDescr read(final InputStream inputStream) throws SAXException,
                                                           IOException {
        this.packageDescr = (PackageDescr) this.parser.read( inputStream );
        return this.packageDescr;
    }

    /**
     * Read a RuleSet from an InputSource.
     *
     * @param in
     *            The rule-set input-source.
     *
     * @return The rule-set.
     */
    public PackageDescr read(final InputSource in) throws SAXException,
                                                  IOException {
        this.packageDescr = (PackageDescr) this.parser.read( in );
        return this.packageDescr;
    }

    void setPackageDescr(final PackageDescr packageDescr) {
        this.packageDescr = packageDescr;
    }

    public PackageDescr getPackageDescr() {
        return this.packageDescr;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy