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

me.saro.sap.jco.SapManagerBuilder Maven / Gradle / Ivy

There is a newer version: 3.0.14.7
Show newest version
package me.saro.sap.jco;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;

/**
 * Sap Manager Builder 
 * @author      PARK Yong Seo
 * @since       0.1
 */
public class SapManagerBuilder {

    /** properties */
    private final Properties properties = new Properties();

    /**
     * use SapManager
     */
    SapManagerBuilder() {
    }

    /**
     * build SapManager
     * @return
     * @throws JCoException
     * @throws IOException
     */
    public synchronized SapManager build() throws JCoException, IOException {
        return build("SAP");
    }

    /**
     * build
     * @param createDestinationFileName
     * ex) SAP = make file SAP.jcoDestination
     * @return
     * @throws JCoException
     * @throws IOException
     */
    public synchronized SapManager build(String createDestinationFileName) throws JCoException, IOException {

        File file = new File(createDestinationFileName+".jcoDestination");

        if (file.exists()) {
            file.delete();
        }

        try (FileOutputStream fos = new FileOutputStream(file, false)) {
            properties.store(fos, "make connection file");
        }

        return new SapManager(JCoDestinationManager.getDestination(createDestinationFileName));
    }

    /**
     * set options
     * @param key
     * @param value
     * @return
     */
    public SapManagerBuilder set(String key, String value) {
        properties.setProperty(key, value);
        return this;
    }

    /**
     * set options
     * @param option
     * @param value
     * @return
     */
    public SapManagerBuilder set(SapManagerBuilderOption option, String value) {
        return set(option.value(), value);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy