Académique Documents
Professionnel Documents
Culture Documents
POJOs / Anotaciones
DEPARTAMENTO DE SISTEMAS
Agenda
• Anotaciones
• POJOS
• Inyección de Dependencias
DEPARTAMENTO DE SISTEMAS
Anotaciones
Ejemplo:
public @interface BugReport {
String assignedTo() default "[none]";
int severity() = 0;
}
DEPARTAMENTO DE SISTEMAS
Anotaciones
@AnnotationName(elementName1=value1, elementName2=value2, . . .)
• Ejemplo
o Paquetes
o Clases
o Enum
o Métodos
o Constructores
o Variables locales
o Parámetros
DEPARTAMENTO DE SISTEMAS
Anotaciones
• Meta-Anotaciones
o @Target
Aplica a una anotación
Especifica a que elementos puede aplicar la
anotación
o @Retention
Especifica por cuanto tiempo es retenida una
anotación
DEPARTAMENTO DE SISTEMAS
Anotaciones
@Target({ElementType.METHOD,ElementType.CONSTRUCTOR})
public @interface TestCase
DEPARTAMENTO DE SISTEMAS
Anotaciones
• @Retention
@Retention(RetentionPolicy.RUNTIME)
public @interface ActionListenerFor
DEPARTAMENTO DE SISTEMAS
Anotaciones
• La herramienta APT
o Herramienta de procesamiento de anotaciones
• Algoritmo de procesamiento
public void process()
{
for (TypeDeclaration t : env.getSpecifiedTypeDeclarations())
{
if (t.getModifiers().contains(Modifier.PUBLIC))
{
for (MethodDeclaration m : t.getMethods())
{
Property p = m.getAnnotation(Property.class);
if (p != null)
{
process property
}
}
}
write bean info source file
}
}
DEPARTAMENTO DE SISTEMAS
Anotaciones
• Procesamiento de ByteCode
o Normalmente requiere librerias de apoyo como
BCEL (ByteCode Engineering Library)
• Anotaciones
• POJOs
• Inyección de Dependencias
DEPARTAMENTO DE SISTEMAS
POJOs
o Mantenimiento
KISS
o Testing
Junit
o Reusabilidad
DEPARTAMENTO DE SISTEMAS
POJOs
• Anotaciones
• POJOS
• Inyección de Dependencias
DEPARTAMENTO DE SISTEMAS
Inyección de Dependencias