Extract some functionality of loader to abstract template

This commit is contained in:
2015-06-11 22:41:02 +01:00
parent 25ec09eb1f
commit 1c85ae6e70

View File

@@ -0,0 +1,38 @@
package base.loader;
import java.io.IOException;
import java.util.Properties;
import org.picocontainer.DefaultPicoContainer;
import org.picocontainer.MutablePicoContainer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AbstractLoader {
protected static final String PROPERTIES_FILE = "loader.properties";
protected Logger logger = LoggerFactory.getLogger(AbstractLoader.class);
protected MutablePicoContainer pico;
public AbstractLoader() {
/* Initialise container */
pico = new DefaultPicoContainer();
}
public AbstractLoader(Properties properties) {
this();
}
public static AbstractLoader getLoader() throws IOException {
return getLoader(PROPERTIES_FILE);
}
public static AbstractLoader getLoader(String propertiesFile) throws IOException {
/* Read properties file */
Properties properties = new Properties();
properties.load(AbstractLoader.class.getClassLoader().getResourceAsStream(propertiesFile));
/* Initialise loader */
return new AbstractLoader(properties);
}
}