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

io.bootique.linkmove.LinkMoveFactory Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
package io.bootique.linkmove;

import com.google.inject.Injector;
import com.nhl.link.move.connect.Connector;
import com.nhl.link.move.runtime.LmRuntime;
import com.nhl.link.move.runtime.LmRuntimeBuilder;
import io.bootique.linkmove.connector.IConnectorFactoryFactory;
import io.bootique.linkmove.connector.JdbcConnectorFactoryFactory;
import io.bootique.linkmove.connector.URIConnectorFactoryFactory;
import org.apache.cayenne.configuration.server.ServerRuntime;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

public class LinkMoveFactory {

    private String extractorsDir;

    private List> connectorFactories;


    public LinkMoveFactory() {
        this.extractorsDir = ".";
        this.connectorFactories = new ArrayList<>();

        // add default factories
        connectorFactories.add(new JdbcConnectorFactoryFactory());
        connectorFactories.add(new URIConnectorFactoryFactory());
    }

    public LmRuntime createLinkMove(Injector injector, ServerRuntime targetRuntime,
                                    Set builderCallbacks) {

        Objects.requireNonNull(extractorsDir);

        LmRuntimeBuilder builder = new LmRuntimeBuilder().withTargetRuntime(targetRuntime).extractorModelsRoot(extractorsDir);

        connectorFactories.forEach(factory -> addToBuilder(builder, factory, injector));

        builderCallbacks.forEach(c -> c.build(builder));
        return builder.build();
    }

    protected  void addToBuilder(LmRuntimeBuilder builder, IConnectorFactoryFactory factoryFactory, Injector injector) {
        builder.withConnectorFactory(factoryFactory.getConnectorType(), factoryFactory.getConnectorFactory(injector));
    }

    public List> getConnectorFactories() {
        return connectorFactories;
    }

    public void setConnectorFactories(List> connectorFactories) {
        this.connectorFactories = connectorFactories;
    }

    public String getExtractorsDir() {
        return extractorsDir;
    }

    public void setExtractorsDir(String extractorsDir) {
        this.extractorsDir = extractorsDir;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy