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

org.milyn.ejc.templates.factoryClass.ftl.xml Maven / Gradle / Ivy

There is a newer version: 1.7.1
Show newest version
/**
 * Generated by Smooks EJC (Edifact Java Compiler).
 */
package ${package};

import org.milyn.Smooks;
import org.milyn.payload.JavaResult;
import org.milyn.edisax.model.internal.Edimap;
import org.milyn.edisax.model.internal.Delimiters;
import org.milyn.edisax.model.EDIConfigDigester;
import org.milyn.edisax.EDIConfigurationException;
import org.xml.sax.SAXException;

import javax.xml.transform.stream.StreamSource;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.IOException;
import javax.xml.transform.Result;

public class ${className}Factory {

    private Smooks smooks;
    private Delimiters delimiters;

    public static ${className}Factory getInstance() throws IOException, SAXException {
        return new ${className}Factory();
    }

    public void addConfigurations(InputStream resourceConfigStream) throws SAXException, IOException {
        smooks.addConfigurations(resourceConfigStream);
    }

    public ${className} fromEDI(InputStream ediStream, Result... additionalResults) {
        return fromEDI(new InputStreamReader(ediStream), additionalResults);
    }

    public ${className} fromEDI(Reader ediStream, Result... additionalResults) {
        JavaResult javaResult = new JavaResult();
        int numAdditionalRes = (additionalResults != null? additionalResults.length : 0);
        Result[] results = new Result[numAdditionalRes + 1];

        results[0] = javaResult;
        if(additionalResults != null) {
            System.arraycopy(additionalResults, 0, results, 1, numAdditionalRes);
        }

        smooks.filterSource(new StreamSource(ediStream), results);
        return (${className}) javaResult.getBean(${className}.class);
    }

    <#if generateFromEDINR == true>
    public ${className} fromEDINR(Reader ediStream) {
        return fromEDI(ediStream);
    }
    

    public void toEDI(${className} instance, Writer writer) throws IOException {
        instance.write(writer, delimiters);
    }

    private ${className}Factory() throws IOException, SAXException {
        smooks = new Smooks(${className}Factory.class.getResourceAsStream("${bindingFile}"));

        try {
            Edimap edimap = EDIConfigDigester.digestConfig(${className}Factory.class.getResourceAsStream("edimappingconfig.xml"));
            delimiters = edimap.getDelimiters();
        } catch(EDIConfigurationException e) {
            IOException ioException = new IOException("Exception reading EDI Mapping model.");
            ioException.initCause(e);
            throw ioException;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy