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

file.producer.FileManagerProducer Maven / Gradle / Ivy

package file.producer;

import java.util.Properties;

import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;

import file.contract.FileManager;
import file.implementation.LocalRepositoryFileManager;
import file.implementation.RemoteRepositoryFileManager;
import file.producer.FileManagerType.ManagerType;
import file.util.properties.PropertiesLoader;

public class FileManagerProducer {
	
	@Inject
	private PropertiesLoader loader;

	@Produces
	@FileManagerType(ManagerType.LOCAL)
	@RequestScoped
	public FileManager getLocalRepositoryFileManager() {
		return new LocalRepositoryFileManager(getRepositoryPath(FileProperties.localKey));
	}

	@Produces
	@FileManagerType(ManagerType.REMOTE)
	@RequestScoped
	public FileManager getRemoteRepositoryFileManager() {
		return new RemoteRepositoryFileManager(getRepositoryPath(FileProperties.remoteKey));
	}

	/**
	 * Gets the repository path in the property file.
	 * 
	 * @param propertieKey
	 *            the related key in the property file.
	 * 
	 * @return the repository path.
	 */
	private String getRepositoryPath(String propertieKey) {

		Properties properties = loader.getPropertiesFile(FileProperties.FILE_PROPERTIES);
		loader.verifyIfValueExists(properties, propertieKey);
		return loader.getProperty(properties, propertieKey);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy