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

io.katharsis.repository.RepositoryInstanceBuilder Maven / Gradle / Ivy

There is a newer version: 2.6.3
Show newest version
package io.katharsis.repository;

import io.katharsis.locator.JsonServiceLocator;
import io.katharsis.repository.exception.RepositoryInstanceNotFoundException;

/**
 * This builder is responsible for creating a new instance of a repository
 */
public class RepositoryInstanceBuilder {

    private final JsonServiceLocator jsonServiceLocator;
    private final Class repositoryClass;

    public RepositoryInstanceBuilder(JsonServiceLocator jsonServiceLocator, Class repositoryClass) {
        this.jsonServiceLocator = jsonServiceLocator;
        this.repositoryClass = repositoryClass;
    }

    public T buildRepository() {
        T repoInstance = jsonServiceLocator.getInstance(repositoryClass);
        if (repoInstance == null) {
            throw new RepositoryInstanceNotFoundException(repositoryClass.getCanonicalName());
        }
        return repoInstance;
    }

    public Class getRepositoryClass() {
        return repositoryClass;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy