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

com.tngtech.propertyloader.impl.DefaultPropertyLocationContainer Maven / Gradle / Ivy

There is a newer version: 1.5.1
Show newest version
package com.tngtech.propertyloader.impl;

import com.tngtech.propertyloader.impl.interfaces.PropertyLoaderOpener;
import com.tngtech.propertyloader.impl.interfaces.PropertyLocationsContainer;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class DefaultPropertyLocationContainer implements PropertyLocationsContainer {

    private final PropertyLoaderFactory propertyLoaderFactory;

    private final List openers = new ArrayList<>();

    public DefaultPropertyLocationContainer(PropertyLoaderFactory propertyLoaderFactory) {
        this.propertyLoaderFactory = propertyLoaderFactory;
    }

    public List getOpeners() {
        return openers;
    }

    public DefaultPropertyLocationContainer atDefaultLocations() {
        atCurrentDirectory();
        atContextClassPath();
        atHomeDirectory();
        return this;
    }

    public DefaultPropertyLocationContainer atCurrentDirectory() {
        openers.add(propertyLoaderFactory.getURLFileOpener());
        return this;
    }

    public DefaultPropertyLocationContainer atHomeDirectory() {
        openers.add(propertyLoaderFactory.getURLFileOpener(System.getProperty("user.home")));
        return this;
    }

    public DefaultPropertyLocationContainer atDirectory(String directory) {
        openers.add(propertyLoaderFactory.getURLFileOpener(directory));
        return this;
    }

    public DefaultPropertyLocationContainer atContextClassPath() {
        openers.add(propertyLoaderFactory.getContextClassLoaderOpener());
        return this;
    }

    public DefaultPropertyLocationContainer atRelativeToClass(Class reference) {
        openers.add(propertyLoaderFactory.getRelativeToClass(reference));
        return this;
    }

    public DefaultPropertyLocationContainer atClassLoader(ClassLoader classLoader) {
        openers.add(propertyLoaderFactory.getClassLoaderOpener(classLoader));
        return this;
    }

    public DefaultPropertyLocationContainer atBaseURL(URL url) {
        openers.add(propertyLoaderFactory.getURLFileOpener(url));
        return this;
    }

    public DefaultPropertyLocationContainer clear() {
        openers.clear();
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy