Se creo la clase DaoFactory en org.palomafp.aadd.jaec.dao
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package org.palomafp.aadd.jaec.dao;
|
||||
|
||||
import org.palomafp.aadd.jaec.config.Configuracion;
|
||||
|
||||
public class DaoFactory {
|
||||
|
||||
// Método para instanciar IContinenteDAO por reflexión
|
||||
public static IContinenteDAO getContinenteDAO() {
|
||||
try {
|
||||
String nombreClase = Configuracion.get("continente.implementacion.clase");
|
||||
Class<?> clase = Class.forName(nombreClase);
|
||||
return (IContinenteDAO) clase.getDeclaredConstructor().newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error al instanciar IContinenteDAO por reflexión: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// Método para instanciar IPaisDAO por reflexión (recibiendo el continenteDAO)
|
||||
public static IPaisDAO getPaisDAO(IContinenteDAO continenteDAO) {
|
||||
try {
|
||||
String nombreClase = Configuracion.get("pais.implementacion.clase");
|
||||
Class<?> clase = Class.forName(nombreClase);
|
||||
// Como PaisDaoText tiene un constructor que recibe IContinenteDAO:
|
||||
return (IPaisDAO) clase.getDeclaredConstructor(IContinenteDAO.class).newInstance(continenteDAO);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error al instanciar IPaisDAO por reflexión: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user