Files
aadd_fic10/src/org/palomafp/aadd/jaec/config/Configuracion.java
T

44 lines
1.2 KiB
Java

package org.palomafp.aadd.jaec.config;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.palomafp.aadd.jaec.excepciones.TecnicoException;
public class Configuracion {
private static final String RUTA_FICHERO_CONFIGURACION = "application.properties";
private static final Properties PROPIEDADES = new Properties();
// Constructor privado: de esta manera conseguimos que esta clase no se pueda
// instanciar
private Configuracion() {
}
// Cargamos el fichero de configuracion
static {
try (InputStream input = Configuracion.class.getClassLoader().getResourceAsStream(RUTA_FICHERO_CONFIGURACION)) {
if (input == null) {
throw new TecnicoException("No se encuentra " + RUTA_FICHERO_CONFIGURACION + " en el classpath");
}
PROPIEDADES.load(input);
} catch (IOException | TecnicoException e) {
throw new RuntimeException(new TecnicoException("No se pudo cargar el fichero de configuración", e));
}
}
// Metodo para obtener el valor de una propiedad
public static String get(String clave) {
String valor = PROPIEDADES.getProperty(clave);
if (valor == null || valor.trim().isEmpty()) {
throw new IllegalArgumentException("No existe la propiedad: " + clave);
}
return valor.trim();
}
}