Actividad 1.10 - Excepciones y Teoria
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>add_fic10</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
module add_fic10 {
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package org.palomafp.aadd.mag.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.palomafp.aadd.mag.model.Continente;
|
||||||
|
import org.palomafp.aadd.mag.excepciones.AccesoDatosException;
|
||||||
|
|
||||||
|
public interface IContinenteDAO {
|
||||||
|
List<Continente> obtenerListaContinentes() throws AccesoDatosException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package org.palomafp.aadd.mag.dao.impl;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.mag.dao.IContinenteDAO;
|
||||||
|
import org.palomafp.aadd.mag.model.Continente;
|
||||||
|
import org.palomafp.aadd.mag.excepciones.AccesoDatosException;
|
||||||
|
|
||||||
|
public class ContinenteDaoFichero implements IContinenteDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Continente> obtenerListaContinentes() throws AccesoDatosException {
|
||||||
|
List<Continente> lista = new ArrayList<>();
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader("continentes.txt"))) {
|
||||||
|
String linea;
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
// Lógica simple para leer tus líneas del fichero
|
||||||
|
String[] partes = linea.split(",");
|
||||||
|
if (partes.length >= 2) {
|
||||||
|
lista.add(new Continente(partes[0].trim(), partes[1].trim()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// AQUÍ ESTÁ LA CLAVE DE LA ACTIVIDAD: Si falla el fichero, lanzamos nuestra excepción
|
||||||
|
throw new AccesoDatosException("Error al leer el archivo de continentes", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lista;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.palomafp.aadd.mag.excepciones;
|
||||||
|
|
||||||
|
public class AccesoDatosException extends TecnicoException {
|
||||||
|
|
||||||
|
public AccesoDatosException(String mensaje) {
|
||||||
|
super(mensaje);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AccesoDatosException(String mensaje, Throwable causa) {
|
||||||
|
super(mensaje, causa);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.palomafp.aadd.mag.excepciones;
|
||||||
|
|
||||||
|
public abstract class MapaMundiException extends Exception {
|
||||||
|
|
||||||
|
public MapaMundiException(String mensaje) {
|
||||||
|
super(mensaje);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapaMundiException(String mensaje, Throwable causa) {
|
||||||
|
super(mensaje, causa);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package org.palomafp.aadd.mag.excepciones;
|
||||||
|
|
||||||
|
public class NegocioException extends MapaMundiException {
|
||||||
|
|
||||||
|
public NegocioException(String mensaje) {
|
||||||
|
super(mensaje);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.palomafp.aadd.mag.excepciones;
|
||||||
|
|
||||||
|
public class TecnicoException extends MapaMundiException {
|
||||||
|
|
||||||
|
public TecnicoException(String mensaje) {
|
||||||
|
super(mensaje);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TecnicoException(String mensaje, Throwable causa) {
|
||||||
|
super(mensaje, causa);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package org.palomafp.aadd.mag.model;
|
||||||
|
|
||||||
|
public class Continente {
|
||||||
|
private String codigo;
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
// Constructor vacío
|
||||||
|
public Continente() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructor con parámetros
|
||||||
|
public Continente(String codigo, String nombre) {
|
||||||
|
this.codigo = codigo;
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters y Setters
|
||||||
|
public String getCodigo() {
|
||||||
|
return codigo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCodigo(String codigo) {
|
||||||
|
this.codigo = codigo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToString para ver los datos por consola
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Continente [codigo=" + codigo + ", nombre=" + nombre + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user